Skip to content

Handle explicit sharding in array truncation - #79

Open
sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:mainfrom
sylvesterkaczmarek:fix-explicit-sharded-array-truncation
Open

Handle explicit sharding in array truncation#79
sylvesterkaczmarek wants to merge 1 commit into
google-deepmind:mainfrom
sylvesterkaczmarek:fix-explicit-sharded-array-truncation

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Fixes #70.

Explicitly-sharded JAX arrays can reject ordinary slicing when the truncated dimension is not divisible by the mesh axis. Treescope currently hits that failure in _truncate_part_with_slices before the JIT out_shardings constraint can make the final result replicated.

For explicit NamedSharding, convert the first shrinking slice to a gather with an explicitly replicated output on the same mesh. Remaining slices then operate on a replicated intermediate, while non-explicit and older JAX paths keep the existing behavior.

The regression test forces four CPU devices in a subprocess and exercises JAXArrayAdapter.get_array_data_with_truncation with an explicit P("tp", None) sharding, verifying the 7x7 edge data and validity mask.

Local validation:

  • reproduced the original ShardingTypeError with four explicit CPU shards
  • patched truncation returned the expected 7x7 data and mask
  • ordinary non-explicit truncation returned the expected data and mask
  • Python syntax compilation passed

The full repository CI toolchain could not be run locally because the isolated environment cannot fetch the repository's development dependencies, so this remains Draft pending upstream CI.

@sylvesterkaczmarek
sylvesterkaczmarek marked this pull request as ready for review August 15, 2026 18:33
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.

Array visualization fails for large, sharded arrays

1 participant