Support PackedSeqParams in TE CUDA graphs#5672
Open
SakshamKapoor2911 wants to merge 2 commits into
Open
Conversation
Signed-off-by: SakshamKapoor2911 <sakshamkapoor2911@gmail.com>
da9ddde to
e24c92d
Compare
Signed-off-by: SakshamKapoor2911 <sakshamkapoor2911@gmail.com>
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.
What does this PR do?
Adds a TE CUDA graph adapter for THD
PackedSeqParamsby flattening graph-dynamic tensor fields into keyword graph inputs, storing non-tensor metadata on the capturedTransformerLayer, and rebuildingPackedSeqParamsinside the layer capture callable.Issue tracking
Linked issue: Related to #5619
Contribution process
Pre-checks
Details
This PR implements the dynamic/static contract requested in #5619:
cu_seqlens_q,cu_seqlens_kv,cu_seqlens_q_padded, andcu_seqlens_kv_padded.qkv_format,max_seqlen_q,max_seqlen_kv,local_cp_size, andcp_group.total_tokensandseq_idxstay outside the TE attention CUDA graph boundary, matchingTEDotProductAttention's existing filtering.TECudaGraphHelperaccepts an optionalsample_packed_seq_paramsand injects its flattened tensor fields into sample kwargs.PackedSeqParamssample used for CUDA graph signature consistency.Validation
python3 -m py_compile megatron/core/packed_seq_params.py megatron/core/transformer/transformer_layer.py megatron/core/transformer/cuda_graphs.py megatron/rl/rl_utils.py megatron/rl/sequence_packing_utils.py megatron/training/training.py train_rl.py tests/unit_tests/transformer/test_packed_seq_params_cuda_graph.py tests/unit_tests/rl/test_rl_utils.pygit diff --checkover all touched files plus the new unit test filetools/autoformat.shandCHECK_ONLY=true tools/autoformat.shwith repo-pinned formatter versions in a disposable CPU-only venv18 passed, 19 warnings/tmp/te5619-venvon RTX 3090: MegatronTECudaGraphHelpercreated TE graphs, replayed a GPT layer with THDPackedSeqParams, and completed backward with fused RoPE (MEGATRON_TE_PACKED_SEQ_CUDAGRAPH_OK_FUSED_ROPE).tests/unit_tests/transformer/test_packed_seq_params_cuda_graph.pyTestRLUtils::test_get_rl_packed_seq_params_for_cuda_graph_*testsAdditional local evidence from a disposable TE environment:
/tmp/te5619-venv.DotProductAttentionpassed for bf16 and fp16.torch.cuda.CUDAGraphTHD attention wrapper replayed successfully after changingcu_seqlens, withmax_abs_diff_vs_eager = 0.0.make_weak_refshim and dropping the newer unsupportedretain_graph_in_backwardkwarg. These should not be needed in NVIDIA's pinned/current TE runtime.Remaining draft caveat: this is still draft until NVIDIA external-contributor validation/CI runs. In this disposable lambda stack, unfused THD RoPE is not graph-safe because it calls
.tolist()/.item()on CUDAcu_seqlensduring capture; the Megatron helper smoke therefore validates the graph path with fused RoPE enabled. Maintainers should still validate the full path in the supported pinned TE runtime before review-ready state.