mlx icon indicating copy to clipboard operation
mlx copied to clipboard

[BUG] conv weight gradient fails on an empty batch

Open goyaladitya05 opened this issue 3 weeks ago • 0 comments

☑️ I understand it is strictly prohibited to use AI to write issues.

Describe the bug The gradient of conv2d (and conv1d) with respect to the weights raises on an empty batch. The forward pass and the gradient with respect to the input both work.

To Reproduce

import mlx.core as mx

w, x = mx.ones((4, 2, 2, 3)), mx.zeros((0, 8, 8, 3))
mx.grad(lambda w: mx.conv2d(x, w).sum())(w)
# ValueError: [reshape] Cannot infer the shape of an empty array

Expected behavior A zero gradient of shape (4, 2, 2, 3).

Desktop (please complete the following information):

  • OS Version: macOS 26.6 (Apple M5), and Linux with mlx[cpu]
  • Version: 0.32.4 (also on main, fc344c9)

Additional context We hit this in KerasHub when training a vision-language model on text-only batches.

goyaladitya05 avatar Nov 11 '26 19:11 goyaladitya05