Skip to content

fuse_convs_horizontally crashes (or silently can't) handle bias-less Conv nodes #39

Open

Description

@SID-6921

Description

scripts/prepare_models/common.py''s fuse_convs_horizontally has a no-bias fallback that is both unreachable and broken if it were reached:

first_bias = first_conv.inputs[2] if len(first_conv.inputs) > 1 else np.zeros(
    first_weights.shape[0], dtype=first_weights.dtype)
  1. Unreachable fallback. Per the ONNX spec, a Conv node always has at least 2 inputs (X, W); the optional bias is a 3rd input. So len(conv.inputs) > 1 is true for every valid Conv node, bias or not — the else branch (meant for bias-less convs) can never execute. The correct check is > 2.
  2. Broken if reached. Even after fixing the condition, the fallback produces a raw np.zeros(...) array, but the following line treats it as an object with a .values attribute (matching onnx_graphsurgeon.Constant):
    first_bias.values = np.concatenate([first_bias.values, bias.values], axis=0)
    A plain numpy.ndarray has no .values attribute, so this raises AttributeError: 'numpy.ndarray' object has no attribute 'values'.

Net effect: fuse_convs_horizontally can only ever work when every fused Conv already has a bias input; it cannot actually synthesize a zero bias for a bias-less conv as the code clearly intends.

This doesn't currently crash ssd_mobilenetv1.py/ssd_resnet34.py (the only two current callers) because their convs happen to already carry a bias by the time this function runs, but the helper itself is broken for the general bias-less case it was written to handle.

Fix

Fix the off-by-one (> 2) and wrap the synthesized zero bias in a gs.Constant (appending it to the conv's inputs when it was missing) so it has the .values attribute the rest of the function relies on.

I have a fix ready to submit as a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions