-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[None][fix] Make tile_tokens_dim calculation just in time before kernel launching. #7529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bff4b4b to
bc1970e
Compare
a26e7c0 to
b9f001b
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #17744 [ run ] triggered by Bot |
|
PR_Github #17744 [ run ] completed with state |
b9f001b to
0e3641a
Compare
0e3641a to
6d4cc6e
Compare
|
/bot run --disable-fail-fast |
|
Caution Review failedFailed to post review comments. Configuration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
💤 Files with no reviewable changes (1)
🧰 Additional context used📓 Path-based instructions (3)**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Files:
**/*.py📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Files:
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Files:
🧠 Learnings (4)📚 Learning: 2025-08-09T20:57:04.084ZApplied to files:
📚 Learning: 2025-08-21T02:39:12.009ZApplied to files:
📚 Learning: 2025-08-14T23:23:27.449ZApplied to files:
📚 Learning: 2025-08-19T12:45:11.997ZApplied to files:
🧬 Code graph analysis (2)tensorrt_llm/_torch/modules/fused_moe/fused_moe_trtllm_gen.py (1)
tensorrt_llm/_torch/custom_ops/trtllm_gen_custom_ops.py (3)
📝 WalkthroughWalkthroughThe PR updates MoE custom ops to dynamically compute tile size with an optional imbalance factor and to cache TorchScript runners per tile dimension via new get_runner methods. Public constructors drop tile_tokens_dim; call sites now compute tile size at runtime. Fused MoE module removes its local tile computation. PyTorch ModelEngine removes an autotuner warmup branch. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller as CustomOp Entry
participant RunnerMgr as MoE Runner (Python)
participant Calc as calculate_tile_tokens_dim()
participant TSRunner as TorchScript Runner (per tile_dim)
participant Kernel as MoE Kernel
Caller->>RunnerMgr: forward(...inputs...)
RunnerMgr->>Calc: compute tile_tokens_dim(num_tokens, num_experts, top_k, imbalance_factor?)
note right of Calc: tokens_per_expert *= imbalance_factor<br/>tile_dim = clamp(pow2(...), 8..64)
Calc-->>RunnerMgr: tile_tokens_dim
RunnerMgr->>RunnerMgr: get_runner(tile_tokens_dim)
alt runner cached
RunnerMgr-->>Caller: reuse cached TSRunner
else miss
RunnerMgr->>TSRunner: create/compile TS runner for tile_dim
RunnerMgr-->>Caller: cache TSRunner
end
RunnerMgr->>TSRunner: run_moe(..., tile_tokens_dim)
TSRunner->>Kernel: dispatch kernel
Kernel-->>TSRunner: outputs
TSRunner-->>RunnerMgr: outputs
RunnerMgr-->>Caller: outputs
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
PR_Github #18007 [ run ] triggered by Bot |
|
PR_Github #18007 [ run ] completed with state |
ed59848 to
8ecf44c
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #18156 [ run ] triggered by Bot |
|
PR_Github #18156 [ run ] completed with state |
6f8720e to
2a54d04
Compare
…rnel launching. `tile_tokens_dim` directly depends on the num_token, which is a dynamic shape during tuning and inference. When AutoTuner prepares dummy tensors with different num_tokens, it does not update the value of `tile_tokens_dim` automatically. Therefore, the value stored in the AutoTuner cache is misaligned, which will introduce a lot of cache misses during inference, which hurts perf a lot. To avoid this issue, we move the calculation of `tile_tokens_dim` right before kernel launching, so that the value of `tile_tokens_dim` is always up to date with the num_tokens of the current input tensor used for the kernel runner. To avoid extra warmup time costs, the extra autotuning warmup steps for all the CUDA graph batch sizes can be removed. Signed-off-by: Yukun He <[email protected]>
2a54d04 to
3ff3040
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #18557 [ run ] triggered by Bot |
|
PR_Github #18557 [ run ] completed with state |
…el launching. (NVIDIA#7529) tile_tokens_dim directly depends on the num_token, which is a dynamic shape during tuning and inference. When AutoTuner prepares dummy tensors with different num_tokens, it does not update the value of tile_tokens_dim automatically. Therefore, the value stored in the AutoTuner cache is misaligned, which will introduce a lot of cache misses during inference, which hurts perf a lot. To avoid this issue, we move the calculation of tile_tokens_dim right before kernel launching, so that the value of tile_tokens_dim is always up to date with the num_tokens of the current input tensor used for the kernel runner. Also, the tile_tokens_dim is calculated based on the number of tokens of a tuned bucket, instead of the original token number. Because we only tune the value for the buckets, not for the raw input token number, to avoid unexpected misalignment between tile_tokens_dim and the token number. This PR also removes the warmup requests with the extra input shapes, which are triggered in the CUDA graph warmup phase. Signed-off-by: Yukun He <[email protected]>
…el launching. (NVIDIA#7529) tile_tokens_dim directly depends on the num_token, which is a dynamic shape during tuning and inference. When AutoTuner prepares dummy tensors with different num_tokens, it does not update the value of tile_tokens_dim automatically. Therefore, the value stored in the AutoTuner cache is misaligned, which will introduce a lot of cache misses during inference, which hurts perf a lot. To avoid this issue, we move the calculation of tile_tokens_dim right before kernel launching, so that the value of tile_tokens_dim is always up to date with the num_tokens of the current input tensor used for the kernel runner. Also, the tile_tokens_dim is calculated based on the number of tokens of a tuned bucket, instead of the original token number. Because we only tune the value for the buckets, not for the raw input token number, to avoid unexpected misalignment between tile_tokens_dim and the token number. This PR also removes the warmup requests with the extra input shapes, which are triggered in the CUDA graph warmup phase. Signed-off-by: Yukun He <[email protected]>
Summary by CodeRabbit
New Features
Refactor
Chores
Description
tile_tokens_dimdirectly depends on the num_token, which is a dynamic shape during tuning and inference. When AutoTuner prepares dummy tensors with different num_tokens, it does not update the value oftile_tokens_dimautomatically. Therefore, the value stored in the AutoTuner cache is misaligned, which will introduce a lot of cache misses during inference, which hurts perf a lot.To avoid this issue, we move the calculation of
tile_tokens_dimright before kernel launching, so that the value oftile_tokens_dimis always up to date with the num_tokens of the current input tensor used for the kernel runner.Also, the tile_tokens_dim is calculated based on the number of tokens of a tuned bucket, instead of the original token number. Because we only tune the value for the buckets, not for the raw input token number, to avoid unexpected misalignment between
tile_tokens_dimand the token number.This PR also removes the warmup requests with the extra input shapes, which are triggered in the CUDA graph warmup phase.
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]to print this help message.See details below for each supported subcommand.
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-listparameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.mdand the
scripts/test_to_stage_mapping.pyhelper.kill
killKill all running builds associated with pull request.
skip
skip --comment COMMENTSkip testing for latest commit on pull request.
--comment "Reason for skipping build/test"is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipelineReuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.