Skip to content

[JAX] Migrate EP collective-stream annotation to region-based compute_on - #3304

Merged
phu0ngng merged 4 commits into
NVIDIA:mainfrom
phu0ngng:jax_compute_on_version
Aug 6, 2026
Merged

[JAX] Migrate EP collective-stream annotation to region-based compute_on#3304
phu0ngng merged 4 commits into
NVIDIA:mainfrom
phu0ngng:jax_compute_on_version

Conversation

@phu0ngng

@phu0ngng phu0ngng commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Description

JAX rewrote jax.experimental.compute_on.compute_on into a region-based transform. This migrates _on_collective_stream, which uses compute_on to the new signature.

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refactoring

Changes

  • _on_collective_stream calls compute_on(compute_type="gpu_stream:collective", out_memory_spaces=Device) on a nullary thunk that closes over the static EpLayerConfig/PartitionSpec args, since region-based compute_on abstract-evals every argument, then invokes the annotated call.
  • Region-based compute_on moves _xla_stream_annotation onto the async wrapper XLA generates, so test_z_dispatch_combine_on_collective_stream checks each EP call is reachable from a collective-annotated wrapper.
  • Region-based compute_on and jax.memory.Space exist since JAX 0.10.1, the current collective-stream floor, so no min-version bump is needed.

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
@phu0ngng

phu0ngng commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

Pipeline #60891724 with the nightly JAX image.

@greptile-apps

greptile-apps Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR migrates JAX expert-parallel operations to the region-based compute_on API and aligns MoE output sharding with the activation input.

  • Wraps EP operations in a nullary collective-stream region while retaining static configuration in the closure.
  • Updates the multiprocess HLO test to validate collective-stream reachability through generated wrapper computations.
  • Applies the input logical-axis constraint to MoE forward output and updates test sharding configuration.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains within the eligible follow-up review scope.

Important Files Changed

Filename Overview
transformer_engine/jax/cpp_extensions/ep.py Migrates EP collective-stream decoration to a region-based nullary compute_on wrapper gated by JAX collective-stream support.
transformer_engine/jax/moe.py Constrains the MoE forward output using the same logical axes as the activation input.
tests/jax/test_multi_process_ep.py Reworks collective-stream verification to follow annotated wrapper computations through the compiled HLO call graph.
tests/jax/test_te_ep_moe.py Aligns logical batch-axis ordering with the EP layout and supplies explicit input axes to the MoE test helper.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[MoE input] --> B[EP dispatch compute_on region]
  B --> C[Collective-stream async wrapper]
  C --> D[Per-expert MLP]
  D --> E[EP combine compute_on region]
  E --> F[Output constrained to input logical axes]
Loading

Reviews (3): Last reviewed commit: "Merge branch 'main' into jax_compute_on_..." | Re-trigger Greptile

@jberchtold-nvidia jberchtold-nvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
Signed-off-by: Phuong Nguyen <phuonguyen@nvidia.com>
@phu0ngng

phu0ngng commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

pipeline #61310617 with the nightly JAX image.

@phu0ngng phu0ngng changed the title [JAX] Migrate EP collective-stream annotation to compute_on2 [JAX] Migrate EP collective-stream annotation to region-based compute_on Aug 6, 2026
def _on_collective_stream(func):
"""Pin ``func``'s ops to XLA's collective stream so the scheduler serializes
them with native collectives. No-op on JAX that lacks the annotation."""
if not is_collective_stream_supported():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update is_collective_stream_supported's definition to attempt to import compute_on in a try/catch, and return False if an import error occurs? Since this compute_on is experimental, it seems JAX may freely rename this function without warning, so any future JAX versions could cause TE to break until we update TE

If we instead tried to import compute_on as part of the is_collective_stream_supported check, we'd just skip the compute_on logic but TE would still work and import correctly. We could log a warning in this case

We could even go a step further and wrap the body of _on_collective_stream in a try/catch, so if something subtler happens like JAX keeps compute_on as the same function name but changes the params, we would try/catch then log a warning and fallback to the original function without the compute_on annotation.

Since this can fail at import-time, it affects all of TE usage even for modules unrelated to TE EP, so I think try/catch'ing at least the first import case would be helpful

What do you think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be in follow-up

out_partition_spec=out_partition_spec,
)
# output of MLP should be sharded the same way as the activation input
output = with_sharding_constraint_by_logical_axes(output, input_axes)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

input_axes and out_partition_spec should be equivalent here, right? If so, can we simplify this be replacing out_partition_spec above with input_axes

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be in follow-up

@phu0ngng
phu0ngng merged commit 66b6d25 into NVIDIA:main Aug 6, 2026
2 of 14 checks passed
@phu0ngng
phu0ngng deleted the jax_compute_on_version branch August 6, 2026 15:51
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.

2 participants