Skip to content

[Pallas] Fix ZeroDivisionError in block spec for int64 1D tensors#1950

Draft
norx1991 wants to merge 1 commit intomainfrom
yifeixu/fix-int64-tiling-zerodiv
Draft

[Pallas] Fix ZeroDivisionError in block spec for int64 1D tensors#1950
norx1991 wants to merge 1 commit intomainfrom
yifeixu/fix-int64-tiling-zerodiv

Conversation

@norx1991
Copy link
Copy Markdown
Contributor

@norx1991 norx1991 commented Apr 4, 2026

Summary

  • Fix ZeroDivisionError: integer modulo by zero in _compute_block_spec_info when processing 1D tensors with dtypes wider than 32 bits (e.g. int64)
  • Root cause: tiling_1d = 128 * (32 // bitwidth) evaluates to 0 for bitwidth=64 because 32 // 64 = 0 in Python integer division. The modulo check bs % tiling_1d then divides by zero.
  • Fix: change parenthesization to 128 * 32 // bitwidth so the product 4096 is divided as a whole (4096 // 64 = 64)
  • Affected examples: cross_entropy, jagged_dense_add, jagged_mean, jagged_softmax, jagged_sum (all use int64 index/offset tensors)

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 4, 2026
The tiling factor formula `128 * (32 // bitwidth)` evaluates to 0
for dtypes wider than 32 bits (e.g. int64 where bitwidth=64) because
`32 // 64 = 0` in integer division.  This causes `bs % tiling_1d` to
divide by zero in `_compute_block_spec_info`.

Fix by changing the parenthesization to `128 * 32 // bitwidth` so the
product is divided as a whole: 4096 // 64 = 64.

Affected examples: cross_entropy, jagged_dense_add, jagged_mean,
jagged_softmax, jagged_sum (all use int64 index/offset tensors).
@norx1991 norx1991 force-pushed the yifeixu/fix-int64-tiling-zerodiv branch from 1d68b6a to a33f104 Compare April 4, 2026 22:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant