Fix cudagraphs, add rms norm pattern matcher - #87
Conversation
Signed-off-by: Suyog Gupta <suyogg@nvidia.com>
Signed-off-by: Suyog Gupta <suyogg@nvidia.com>
Signed-off-by: Suyog Gupta <suyogg@nvidia.com>
Signed-off-by: Suyog Gupta <suyogg@nvidia.com>
Signed-off-by: Suyog Gupta <suyogg@nvidia.com>
There was a problem hiding this comment.
Pull Request Overview
This PR adds a graph transformation to match and replace RMSNorm patterns, integrates the new matcher into the transformation pipeline, provides custom operators and unit tests for both FlashInfer and Triton backends, and also fixes cuDAGraph batch size ordering and extends the executor to handle new tokens.
- Introduce
match_rms_normpattern matcher, custom ops, and corresponding unit tests. - Update the main transform pipeline and initialization (
transform.py) to invoke RMSNorm matching. - Fix cuDAGraph batch size sorting, add
max_beam_widthandnew_tokenshandling inad_executor.py, and adjust the default overlap scheduler flag.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unittest/_torch/auto_deploy/unit/singlegpu/transformations/library/test_rms_norm.py | Add unit tests for RMSNorm pattern matching across both backends. |
| tensorrt_llm/_torch/auto_deploy/transformations/transform.py | Import and invoke match_rms_norm in the transformation pipeline. |
| tensorrt_llm/_torch/auto_deploy/transformations/library/rms_norm.py | Implement search and replacement functions for RMSNorm optimization. |
| tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py | Add max_beam_width, extend _prepare_inputs to accept new_tokens. |
| tensorrt_llm/_torch/auto_deploy/llm_args.py | Change default for disable_overlap_scheduler to False. |
| tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py | Define FlashInfer and Triton custom ops for RMSNorm. |
| tensorrt_llm/_torch/auto_deploy/custom_ops/init.py | Export rms_norm operators. |
| tensorrt_llm/_torch/auto_deploy/compile/backends/torch_cudagraph.py | Sort cuda_graph_batch_sizes in descending order. |
Comments suppressed due to low confidence (4)
tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py:9
- The function name
flashinfer_rmsnorm(no underscore) differs from the op nameflashinfer_rms_norm. Consider renaming the Python function toflashinfer_rms_normfor consistency.
@torch.library.custom_op("auto_deploy::flashinfer_rms_norm", mutates_args=())
tensorrt_llm/_torch/auto_deploy/custom_ops/rms_norm.py:42
- The function name
triton_rmsnorm(no underscore) does not match the op nametriton_rms_norm. Renaming it totriton_rms_normwould improve readability and maintain consistency.
@torch.library.custom_op("auto_deploy::triton_rms_norm", mutates_args=())
tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py:157
- The docstring for
_prepare_inputswas not updated to mention the newnew_tokensparameter. Please extend the docstring to describe its purpose and expected behavior.
) -> bool:
tensorrt_llm/_torch/auto_deploy/transformations/transform.py:196
- [nitpick] The call to
match_rms_normuses the default backend. It may be clearer to surface the backend option here or pass it via configuration rather than relying on the default in the function signature.
match_rms_norm(egm)
Signed-off-by: Suyog Gupta <suyogg@nvidia.com>
|
@Fridah-nv : ptal. |
Fridah-nv
left a comment
There was a problem hiding this comment.
LGTM for the pattern matcher part!
|
Here is a rough summary of my investigation of hitting torch.compile's recompile limit during cuda graph capture and a suggestion on how to fix it It's not a blocker though - we can probably fix it a follow-up PR. @suyoggupta maybe you can just a comment to the torch-opt backend for this @nzmora-nvidia, maybe you can take this on as a small task to get more familiar with our cudagraph capture? |
|
I created NVIDIA#6142 |
Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
* fix overlap scheduler in AD Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * cleanups Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * fix nest sequences Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * nits * avoid hardcoding max beam width Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * avoid hardcoding max beam width Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * cudagraph fixes + rms norm Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * fix test Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * revert ad_executor changes Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * Review comments + make sure num_pages >= max batch size * wrapping reviewer feedback and open items Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com> --------- Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com> Co-authored-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
* fix overlap scheduler in AD Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * cleanups Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * fix nest sequences Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * nits * avoid hardcoding max beam width Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * avoid hardcoding max beam width Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * cudagraph fixes + rms norm Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * fix test Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * revert ad_executor changes Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> * Review comments + make sure num_pages >= max batch size * wrapping reviewer feedback and open items Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com> --------- Signed-off-by: Suyog Gupta <41447211+suyoggupta@users.noreply.github.com> Signed-off-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com> Co-authored-by: Lucas Liebenwein <11156568+lucaslie@users.noreply.github.com>
AutoDeploy:
Pytorch: