ACT icon indicating copy to clipboard operation
ACT copied to clipboard

vit_2023: fuzzing fails with more than one instance (converted model only accepts batch size 1)

Open Cui8609 opened this issue 3 weeks ago • 4 comments

On main (65952d7), fuzzing vit_2023 fails on the first iteration as soon as the batch has more than one seed.

To reproduce (with vit_2023 downloaded):

python -m act.pipeline --fuzz --category vit_2023 --max-instances 4 --timeout 5 --device cpu
Traceback (most recent call last):
  ...
  File "act/pipeline/fuzzing/actfuzzer.py", line 528, in _fuzz_iteration
    output = self.model(inputs)
  ...
  File "act/front_end/verifiable_model.py", line 157, in forward
  ...
  File "site-packages/onnx2torch/node_converters/binary_math_operations.py", line 50, in forward
    return self.math_op_function(first, second)
  ...
RuntimeError: The size of tensor a (17) must match the size of tensor b (5) at non-singleton dimension 1
Full traceback (paths shortened)
Traceback (most recent call last):
  File "act/config/pipeline_cli.py", line 476, in cmd_fuzz
    report = fuzzer.fuzz()
             ^^^^^^^^^^^^^
  File "act/pipeline/fuzzing/actfuzzer.py", line 451, in fuzz
    self._fuzz_iteration(iteration, batch_size)
  File "act/pipeline/fuzzing/actfuzzer.py", line 528, in _fuzz_iteration
    output = self.model(inputs)
             ^^^^^^^^^^^^^^^^^^
  File "site-packages/torch/nn/modules/module.py", line 1783, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/torch/nn/modules/module.py", line 1889, in _call_impl
    return inner()
           ^^^^^^^
  File "site-packages/torch/nn/modules/module.py", line 1837, in inner
    result = forward_call(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "act/front_end/verifiable_model.py", line 157, in forward
    x = self.model(x)
        ^^^^^^^^^^^^^
  File "site-packages/torch/fx/graph_module.py", line 1007, in call_wrapped
    return self._wrapped_call(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/torch/fx/graph_module.py", line 514, in __call__
    raise e
  File "site-packages/torch/fx/graph_module.py", line 500, in __call__
    return super(self.cls, obj).__call__(*args, **kwargs)  # type: ignore[misc]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/torch/nn/modules/module.py", line 1783, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/torch/nn/modules/module.py", line 1794, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<eval_with_key>.0", line 12, in forward
    _0_add_1 = getattr(self, "0/Add_1")(_0_concat_2, initializers_onnx_initializer_2);  _0_concat_2 = initializers_onnx_initializer_2 = None
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/torch/nn/modules/module.py", line 1783, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/torch/nn/modules/module.py", line 1794, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/onnx2torch/node_converters/binary_math_operations.py", line 50, in forward
    return self.math_op_function(first, second)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "site-packages/torch/utils/_device.py", line 122, in __torch_function__
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
RuntimeError: The size of tensor a (17) must match the size of tensor b (5) at non-singleton dimension 1

17 = 4 images × 4 patches + 1 class token, where 5 is expected per image: the four images end up in one sample.

Cause

The ONNX file declares a symbolic batch dimension, and onnxruntime runs it with batch 2. _preprocess_onnx_for_onnx2torch (act/front_end/vnnlib_loader/onnx_converter.py, lines 189-193) rewrites that dimension to 1; its docstring names vit_2023. The converted module then has the batch-1 shapes fixed and only accepts one input at a time.

Notes

  • The conversion fails with BatchNorm operation with spatial rank == -2 is not implemented. I'm investigating whether its the issue of symbolic dimension's nature or the implementation we have.
  • Writing N instead of 1 gives a module that accepts exactly N inputs and nothing else (N=2 runs a batch of 2 but not 1 or 4). It is not a workaround either: with N=4 the command above fails earlier, in spec creation, which runs the model on a single input.

Scripts for the statements above (branch repro/vit-batch-dim of my fork, directory repro/vit_batch_dim/; run from the repo root, nothing in act/ is changed):

Statement Script
The ONNX file runs a batch of 2; the converted module only a batch of 1 vit_original_vs_converted.py
Symbolic dimension fails to convert; N instead of 1 accepts exactly N vit_pin_batch.py
With N=4 the fuzz command fails in spec creation vit_fuzz_with_pin.py 4

Cui8609 avatar Nov 14 '26 02:11 Cui8609

@guanqin-123 could you help take a look at this issue?

yuleisui avatar Nov 14 '26 10:11 yuleisui

Update: the BatchNorm failure comes from shape inference, not from the symbolic dimension itself. onnx.shape_inference.infer_shapes leaves the BatchNorm input without a shape; with onnxruntime's SymbolicShapeInference instead, and the dimension left symbolic, the conversion succeeds and the fuzz command above runs with 4 instances. These two changes together are not a fix, though: --verify vnnlib --category vit_2023 then fails with OnnxGather: missing predecessor for _0_gather, while it passes on unmodified main.

Cui8609 avatar Nov 15 '26 04:11 Cui8609

Update: the BatchNorm failure comes from shape inference, not from the symbolic dimension itself. onnx.shape_inference.infer_shapes leaves the BatchNorm input without a shape; with onnxruntime's SymbolicShapeInference instead, and the dimension left symbolic, the conversion succeeds and the fuzz command above runs with 4 instances. These two changes together are not a fix, though: --verify vnnlib --category vit_2023 then fails with OnnxGather: missing predecessor for _0_gather, while it passes on unmodified main.

@Cui8609 would you please use my upcoming fix pr to load in your local device and check, then let me go if the issue is resolved?

guanqin-123 avatar Nov 15 '26 23:11 guanqin-123

Update: the BatchNorm failure comes from shape inference, not from the symbolic dimension itself. onnx.shape_inference.infer_shapes leaves the BatchNorm input without a shape; with onnxruntime's SymbolicShapeInference instead, and the dimension left symbolic, the conversion succeeds and the fuzz command above runs with 4 instances. These two changes together are not a fix, though: --verify vnnlib --category vit_2023 then fails with OnnxGather: missing predecessor for _0_gather, while it passes on unmodified main.

@Cui8609 would you please use my upcoming fix pr to load in your local device and check, then let me go if the issue is resolved?

Checked PR #142 (64d4a7c) locally against main (b0afdc1), CPU only. The issue is resolved for me:

  • --fuzz --category vit_2023 with 1, 4 and 20 instances runs (both fail on main).
  • --verify vnnlib --category vit_2023 with 1, 4, and 20 instances still passes, same status as main.
  • Both vit models match onnxruntime at batch 1/2/3/4/100.
  • Other dynamic-batch models I have locally convert to the same modules as on main, except smart_turn_multimodal_2026, which also has Shape nodes. On main it fails to fuzz 3 instances (shape '[1, 400, 6, 64]' is invalid for input of size 460800); with the PR it runs.

Not checked: --verify on smart_turn (runs out of memory on my 16 GB machine on main as well), GPU.

Cui8609 avatar Nov 16 '26 09:11 Cui8609