Skip to content

Fix conv weight gradient with empty batch - #4873

Merged
zcbenz merged 1 commit into
ml-explore:mainfrom
OgShadoww:fix/conv-empty-batch-grad
Nov 21, 2026
Merged

zcbenz merged 1 commit into
ml-explore:mainfrom
OgShadoww:fix/conv-empty-batch-grad

Conversation

@OgShadoww

Copy link
Copy Markdown
Contributor

When the input batch size is zero, computing the convolution weight gradient fails because the backward path attempts to infer a dimension when reshaping an empty array. The weight gradient should be a zero valued array with the same shape and dtype as the weights. Convolution::vjp now returns zeros_like(wt, stream()) when in.shape(0) == 0, avoiding the reshape error.

Added regression tests. Test fail without the fix and passes with it.

  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure: AI assisted with writing regression tests, investigating the issue and reviewing implementation. I wrote implementation, ran tests localy, checked tests with fix and without.

Fixes #4870

@zcbenz
zcbenz force-pushed the fix/conv-empty-batch-grad branch from 733194e to e126793 Compare November 21, 2026 07:29
@zcbenz
zcbenz marked this pull request as ready for review November 21, 2026 07:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] conv weight gradient fails on an empty batch

2 participants