Skip to content

AffineTransform: handle empty MLX input in block-diagonal path - #183

Merged
cboulay merged 1 commit into
devfrom
affine-mlx-empty
Jul 22, 2026
Merged

AffineTransform: handle empty MLX input in block-diagonal path#183
cboulay merged 1 commit into
devfrom
affine-mlx-empty

Conversation

@cboulay

@cboulay cboulay commented Jul 22, 2026

Copy link
Copy Markdown
Member

Summary

Fix AffineTransformTransformer when an empty message is processed through the block-diagonal MLX path.

MLX rejects indexed scatter assignments with zero-size updates. The block-diagonal implementation previously attempted one such assignment per cluster even though the preallocated zero-size output was already complete, causing empty chunks to raise.

Changes

  • Skip block-diagonal cluster multiplication and indexed assignments whenever any input dimension is empty.
  • Preserve the expected output shape, dtype, dimensions, and coordinate axis for empty messages.
  • Keep normal non-empty block-diagonal processing unchanged.
  • Add an MLX regression test covering empty input at startup, normal input through the same processor, and another empty chunk afterward.
  • Clean up an adjacent split string literal in the cluster validation error.

Testing

  • tests/unit/test_affine_transform.py: 47 passed.
  • Ruff lint and formatting checks pass.

MLX's scatter (indexed assignment) rejects zero-size updates, so
result[..., out_idx] = matmul(...) raised e.g. 'ValueError: [scatter]
Updates with shape (0,32,1,1) are too large for array with shape (0,128)'
when an empty startup message reached a block-diagonal transform.

The pre-allocated zeros output is already the correct result for any
zero-length input dimension (a zero-length inner dimension sums to
zero), so return it without entering the cluster-assignment loop. The
emptiness check reads only array metadata, so no backend conversion or
evaluation occurs.

Also includes a ruff-format cleanup of an adjacent f-string.
@cboulay
cboulay merged commit 9c48cb9 into dev Jul 22, 2026
14 checks passed
@cboulay
cboulay deleted the affine-mlx-empty branch July 22, 2026 14:15
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.

1 participant