[JAX] Fix FSDP when FSDP+EP is active#2649
Open
jberchtold-nvidia wants to merge 3 commits intoNVIDIA:mainfrom
Open
[JAX] Fix FSDP when FSDP+EP is active#2649jberchtold-nvidia wants to merge 3 commits intoNVIDIA:mainfrom
jberchtold-nvidia wants to merge 3 commits intoNVIDIA:mainfrom
Conversation
Contributor
Greptile OverviewGreptile SummaryFixed FSDP sharding check in JAX GEMM to handle tuple specs like
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant GemmPrimitive
participant infer_sharding_from_operands
participant MeshResource as gsr (MeshResource)
Caller->>GemmPrimitive: Execute GEMM with FSDP+EP
GemmPrimitive->>infer_sharding_from_operands: Get sharding specs
infer_sharding_from_operands->>MeshResource: Get fsdp_resource
MeshResource-->>infer_sharding_from_operands: Returns 'fsdp'
Note over infer_sharding_from_operands: Extract non-contracting specs<br/>from RHS (rhs_non_cspecs)
alt Spec is single string 'fsdp'
infer_sharding_from_operands->>infer_sharding_from_operands: spec == gsr.fsdp_resource → True
Note over infer_sharding_from_operands: Replace with None (gather)
else Spec is tuple ('fsdp', 'expert')
infer_sharding_from_operands->>infer_sharding_from_operands: isinstance(spec, tuple) → True
infer_sharding_from_operands->>infer_sharding_from_operands: gsr.fsdp_resource in spec → True
Note over infer_sharding_from_operands: Replace with None (gather)<br/>NEW: Fixes FSDP+EP case
else Spec is other
Note over infer_sharding_from_operands: Keep original spec
end
infer_sharding_from_operands-->>GemmPrimitive: Return modified specs
GemmPrimitive-->>Caller: Execute with correct sharding
|
Signed-off-by: Jeremy Berchtold <jberchtold@nvidia.com>
4ee4d73 to
08fda9c
Compare
Collaborator
Author
|
/te-ci L1 jax |
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
In some models when FSDP and EP are both active, the non-MoE blocks use
(('fsdp', 'expert'), None, None, None)with the EP GPU domain acting as FSDP. Our TE/JAX GEMM did not handle this correctly as it assumedfsdpwould be present in an axis alone, not as part of a tuple. This resulting in unnecessary AllGather's of the inputs blocking the critical path.This PR fixes the check and if the TE GEMM sees an inspect sharding with fsdp as part a tuple, it performs FSDP on the GPU domain of all axes specified in the tuple.
Type of change
Changes
('fsdp', 'expert')along the same axisChecklist: