Skip to content

fix: move shape definition before use in mean_dim function#20

Open
Jah-yee wants to merge 5 commits into
thinking-machines-lab:mainfrom
Jah-yee:fix/undefined-shape-variable
Open

fix: move shape definition before use in mean_dim function#20
Jah-yee wants to merge 5 commits into
thinking-machines-lab:mainfrom
Jah-yee:fix/undefined-shape-variable

Conversation

@Jah-yee
Copy link
Copy Markdown

@Jah-yee Jah-yee commented Apr 15, 2026

Good day,

I found a bug in the mean_dim function where the shape variable was referenced before it was defined. This causes a potential NameError when handling the empty dimension case.

Changes

  • Move shape = list(input.shape) definition before the empty dimension check
  • Also handle dtype properly in the empty dimension early return case

This fix ensures the code executes correctly when passing a tensor with an empty dimension (e.g., shape (1, 0, 8)).

Thank you for your work...

Warmly, RoomWithOutRoof

RoomWithOutRoof and others added 5 commits April 15, 2026 22:49
- Add comprehensive tests in tests/test_batch_invariant_ops.py
- Fix mean_dim to handle empty dimension (return zeros instead of NaN)

Good day,

Thank you for your work on this excellent library!

Warmly,
RoomWithOutRoof
Added softmax along with log_softmax, expanding batch-invariant operations.

Good day!

Warmly,
RoomWithoutRoof
Fixes Issue thinking-machines-lab#15: Fix NaN in mean_kernel for empty dimension

When the reduction dimension is empty (N==0), return 0 to avoid NaN.

Good day!

Warmly, RoomWithoutRoof
…ibility

The flatten parameter was removed in Triton 3.x public release.
This changes tl.range(..., flatten=True) to Python's built-in range(),
which works inside @triton.jit functions and is compatible with all versions.

Fixes: TypeError: range.__init__() got an unexpected keyword argument 'flatten'
The shape variable was referenced before it was defined, causing a potential
NameError when handling empty dimension case. This fix reorders the code
to define shape before the empty dimension check.
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