@@ -109,30 +109,24 @@ def linear_attention(
109109 uses_decay = update_rule in ("gated" , "gated_delta" )
110110 uses_beta = update_rule in ("delta" , "gated_delta" )
111111
112- # --- Define function inputs (conditional on update_rule) ---
113- # TODO: Investigate relaxing onnx-shape-inference's strict arity check
114- # to allow trailing optional inputs, enabling a single 6-input signature.
115- # The function is specialized per-model: only inputs actually used
116- # by this update_rule variant are declared. Call sites (e.g.
117- # Mamba2Block with "gated") pass exactly the declared number of args.
112+ # --- Define function inputs ---
113+ # Always declare the full 6-input signature:
114+ # (query, key, value, past_state, decay, beta).
115+ # Update-rule-specific paths inside the function body ignore unused
116+ # trailing inputs so every variant exposes the same ir.Function
117+ # interface. Call sites that don't need trailing inputs (decay, beta)
118+ # simply omit them — onnx-shape-inference >=0.1.9 accepts trailing
119+ # optional inputs (matching ONNX C++ behavior).
118120 inputs : list [ir .Value ] = [
119121 ir .Value (name = "query" ), # (B, T, q_num_heads * d_k)
120122 ir .Value (name = "key" ), # (B, T, q_num_heads * d_k)
121123 ir .Value (name = "value" ), # (B, T, kv_num_heads * d_v)
122124 ir .Value (name = "past_state" ),
125+ ir .Value (name = "decay" ),
126+ ir .Value (name = "beta" ),
123127 ]
124- if uses_decay :
125- inputs .append (ir .Value (name = "decay" ))
126- if uses_beta :
127- inputs .append (ir .Value (name = "beta" ))
128128
129- def body (op , * args ):
130- query_v , key_v , value_v , past_state_v = args [:4 ]
131- idx = 4
132- decay_v = args [idx ] if uses_decay else None
133- if uses_decay :
134- idx += 1
135- beta_v = args [idx ] if uses_beta else None
129+ def body (op , query_v , key_v , value_v , past_state_v , decay_v , beta_v ):
136130
137131 # --- Reshape 3D → 4D using head counts ---
138132 b_dim = op .Shape (query_v , start = 0 , end = 1 )
0 commit comments