You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add(MatMul(...), [1, N]) fails in tf.function with "bias must be 1-dimensional" while eager works #126661
tf-nightly 2.22.0-dev20260830 (v1.12.1-144425-gba73aa33d57), also reproduced on 2.21.0 (v2.21.0-rc1-5-ga481b10260d)
Custom code
Yes
OS platform and distribution
Linux Ubuntu 20.04.4 LTS (x86_64)
Python version
3.11
Current behavior?
Adding a [1, N] tensor to the result of a MatMul runs fine in eager, but raises InvalidArgumentError: bias must be 1-dimensional once the same function is wrapped in tf.function.
tf.add broadcasts [N, N] with [1, N] to [N, N], which is what eager does. In graph mode the remapper fuses Add(MatMul(...), y) into a fused MatMul-with-bias, and that fused form requires the bias operand to be 1-D. The fusion appears to fire whenever the addend is broadcast-compatible, without checking that it is actually rank 1, so the resulting graph contains an op whose contract the operand does not satisfy and the failure only surfaces at execution time.
The MatMul is required to trigger it: tf.add(a, b) on its own with the same shapes traces and runs correctly. A 1-D bias [N] and a column [N, 1] are both fine as well, so it is specifically the [1, N] case that is mis-fused.
Note that jit_compile=True also runs correctly, so this affects the default graph path rather than XLA.
Hi @laolvfan ,
Thank you for raising your concern here.
A fix for this issue has been proposed in this PR1, PR2. Once it is merged, this issue will be resolved.
Hi @adi-IL , @PranshulSoni,
Thank you for raising the PR to address this issue. We truly appreciate your initiative and the effort in contributing the fix.
Activity
Venkat6871 commentedon Sep 4, 2026
Hi @laolvfan ,
Thank you for raising your concern here.
A fix for this issue has been proposed in this PR1, PR2. Once it is merged, this issue will be resolved.
Hi @adi-IL , @PranshulSoni,
Thank you for raising the PR to address this issue. We truly appreciate your initiative and the effort in contributing the fix.
google-ml-butler commentedon Sep 25, 2026
Are you satisfied with the resolution of your issue?
Yes
No
fix: support broadcast-shaped bias with leading 1s in fused MatMul an…