-
Notifications
You must be signed in to change notification settings - Fork 2k
[TRTLLM-7967][feat] Adding Starcoder2 PyTorch Backend Support #8923
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
[TRTLLM-7967][feat] Adding Starcoder2 PyTorch Backend Support #8923
Conversation
adbefc2 to
c1646cb
Compare
|
/bot run |
📝 WalkthroughWalkthroughAdds a complete StarCoder2 model implementation for TensorRT-LLM, including custom LayerNorm, grouped-query attention with sliding window support, decoder layers, a transformer model, and a causal language model wrapper with weight loading logic for GPT-2 style MLP naming conventions. Includes comprehensive unit tests covering sanity checks, HuggingFace reference comparison, and token generation correctness. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Starcoder2ForCausalLM
participant Starcoder2Model
participant DecoderLayer as Starcoder2DecoderLayer
participant Attention as Starcoder2Attention
participant MLP
User->>Starcoder2ForCausalLM: forward(input_ids)
Starcoder2ForCausalLM->>Starcoder2Model: forward(input_ids)
Starcoder2Model->>Starcoder2Model: embed tokens & init position_ids
loop for each decoder layer
Starcoder2Model->>DecoderLayer: forward(hidden_states, position_ids)
DecoderLayer->>DecoderLayer: input normalization
DecoderLayer->>Attention: forward(hidden_states, position_ids)
rect rgba(200, 220, 255, 0.3)
Note over Attention: Grouped-query attention<br/>with sliding window
end
Attention-->>DecoderLayer: attn_output
DecoderLayer->>MLP: forward(attn_output)
MLP-->>DecoderLayer: mlp_output
DecoderLayer->>DecoderLayer: residual connections
DecoderLayer-->>Starcoder2Model: layer_output
end
Starcoder2Model->>Starcoder2Model: final layer normalization
Starcoder2Model-->>Starcoder2ForCausalLM: hidden_states
rect rgba(220, 240, 220, 0.3)
Note over Starcoder2ForCausalLM: Output projection<br/>(logits)
end
Starcoder2ForCausalLM-->>User: logits
sequenceDiagram
participant User
participant Starcoder2ForCausalLM
participant Loader as Weight Loader
participant HFWeights as HF Model Weights
participant InternalModules as Internal Modules
User->>Starcoder2ForCausalLM: load_weights(weights, weight_mapper)
alt with weight_mapper
Starcoder2ForCausalLM->>Loader: load_weights(weight_mapper path)
else without weight_mapper
Starcoder2ForCausalLM->>Loader: load_weights(default path)
end
Loader->>HFWeights: read c_fc, c_proj (GPT-2 MLP naming)
rect rgba(255, 220, 200, 0.3)
Note over Loader: Map GPT-2 names to<br/>internal up_proj/down_proj
end
HFWeights-->>Loader: weight tensors
Loader->>InternalModules: set_parameter(mapped_name)
InternalModules-->>Starcoder2ForCausalLM: weights loaded
Starcoder2ForCausalLM-->>User: ready for inference
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
tensorrt_llm/_torch/models/__init__.py(2 hunks)tensorrt_llm/_torch/models/modeling_starcoder2.py(1 hunks)tests/unittest/_torch/modeling/test_modeling_starcoder2.py(1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Use only spaces, no tabs; indent with 4 spaces.
Files:
tensorrt_llm/_torch/models/__init__.pytensorrt_llm/_torch/models/modeling_starcoder2.pytests/unittest/_torch/modeling/test_modeling_starcoder2.py
**/*.py
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.py: Python code must target Python 3.8+.
Indent Python code with 4 spaces; do not use tabs.
Maintain module namespace when importing; prefer 'from package.subpackage import foo' then 'foo.SomeClass()' instead of importing the class directly.
Python filenames should be snake_case (e.g., some_file.py).
Python classes use PascalCase names.
Functions and methods use snake_case names.
Local variables use snake_case; prefix 'k' for variables that start with a number (e.g., k_99th_percentile).
Global variables use upper SNAKE_CASE prefixed with 'G' (e.g., G_MY_GLOBAL).
Constants use upper SNAKE_CASE (e.g., MY_CONSTANT).
Avoid shadowing variables from an outer scope.
Initialize all externally visible members of a class in the constructor.
Prefer docstrings for interfaces that may be used outside a file; comments for in-function or file-local interfaces.
Use Google-style docstrings for classes and functions (Sphinx-parsable).
Document attributes and variables inline so they render under the class/function docstring.
Avoid reflection when a simpler, explicit approach suffices (e.g., avoid dict(**locals()) patterns).
In try/except, catch the most specific exceptions possible.
For duck-typing try/except, keep the try body minimal and use else for the main logic.
Files:
tensorrt_llm/_torch/models/__init__.pytensorrt_llm/_torch/models/modeling_starcoder2.pytests/unittest/_torch/modeling/test_modeling_starcoder2.py
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).
Files:
tensorrt_llm/_torch/models/__init__.pytensorrt_llm/_torch/models/modeling_starcoder2.pytests/unittest/_torch/modeling/test_modeling_starcoder2.py
🧠 Learnings (5)
📓 Common learnings
Learnt from: moraxu
Repo: NVIDIA/TensorRT-LLM PR: 6303
File: tests/integration/test_lists/qa/examples_test_list.txt:494-494
Timestamp: 2025-07-28T17:06:08.621Z
Learning: In TensorRT-LLM testing, it's common to have both CLI flow tests (test_cli_flow.py) and PyTorch API tests (test_llm_api_pytorch.py) for the same model. These serve different purposes: CLI flow tests validate the traditional command-line workflow, while PyTorch API tests validate the newer LLM API backend. Both are legitimate and should coexist.
Learnt from: galagam
Repo: NVIDIA/TensorRT-LLM PR: 6487
File: tests/unittest/_torch/auto_deploy/unit/singlegpu/test_ad_trtllm_bench.py:1-12
Timestamp: 2025-08-06T13:58:07.506Z
Learning: In TensorRT-LLM, test files (files under tests/ directories) do not require NVIDIA copyright headers, unlike production source code files. Test files typically start directly with imports, docstrings, or code.
Learnt from: fredricz-20070104
Repo: NVIDIA/TensorRT-LLM PR: 7645
File: tests/integration/test_lists/qa/llm_function_core.txt:648-648
Timestamp: 2025-09-09T09:40:45.658Z
Learning: In TensorRT-LLM test lists, it's common and intentional for the same test to appear in multiple test list files when they serve different purposes (e.g., llm_function_core.txt for comprehensive core functionality testing and llm_function_core_sanity.txt for quick sanity checks). This duplication allows tests to be run in different testing contexts.
📚 Learning: 2025-07-28T17:06:08.621Z
Learnt from: moraxu
Repo: NVIDIA/TensorRT-LLM PR: 6303
File: tests/integration/test_lists/qa/examples_test_list.txt:494-494
Timestamp: 2025-07-28T17:06:08.621Z
Learning: In TensorRT-LLM testing, it's common to have both CLI flow tests (test_cli_flow.py) and PyTorch API tests (test_llm_api_pytorch.py) for the same model. These serve different purposes: CLI flow tests validate the traditional command-line workflow, while PyTorch API tests validate the newer LLM API backend. Both are legitimate and should coexist.
Applied to files:
tests/unittest/_torch/modeling/test_modeling_starcoder2.py
📚 Learning: 2025-08-06T13:58:07.506Z
Learnt from: galagam
Repo: NVIDIA/TensorRT-LLM PR: 6487
File: tests/unittest/_torch/auto_deploy/unit/singlegpu/test_ad_trtllm_bench.py:1-12
Timestamp: 2025-08-06T13:58:07.506Z
Learning: In TensorRT-LLM, test files (files under tests/ directories) do not require NVIDIA copyright headers, unlike production source code files. Test files typically start directly with imports, docstrings, or code.
Applied to files:
tests/unittest/_torch/modeling/test_modeling_starcoder2.py
📚 Learning: 2025-09-09T09:40:45.658Z
Learnt from: fredricz-20070104
Repo: NVIDIA/TensorRT-LLM PR: 7645
File: tests/integration/test_lists/qa/llm_function_core.txt:648-648
Timestamp: 2025-09-09T09:40:45.658Z
Learning: In TensorRT-LLM test lists, it's common and intentional for the same test to appear in multiple test list files when they serve different purposes (e.g., llm_function_core.txt for comprehensive core functionality testing and llm_function_core_sanity.txt for quick sanity checks). This duplication allows tests to be run in different testing contexts.
Applied to files:
tests/unittest/_torch/modeling/test_modeling_starcoder2.py
📚 Learning: 2025-08-26T09:49:04.956Z
Learnt from: pengbowang-nv
Repo: NVIDIA/TensorRT-LLM PR: 7192
File: tests/integration/test_lists/test-db/l0_dgx_b200.yml:56-72
Timestamp: 2025-08-26T09:49:04.956Z
Learning: In TensorRT-LLM test configuration files, the test scheduling system handles wildcard matching with special rules that prevent duplicate test execution even when the same tests appear in multiple yaml files with overlapping GPU wildcards (e.g., "*b200*" and "*gb200*").
Applied to files:
tests/unittest/_torch/modeling/test_modeling_starcoder2.py
🧬 Code graph analysis (3)
tensorrt_llm/_torch/models/__init__.py (1)
tensorrt_llm/_torch/models/modeling_starcoder2.py (1)
Starcoder2ForCausalLM(249-304)
tensorrt_llm/_torch/models/modeling_starcoder2.py (6)
tensorrt_llm/_torch/attention_backend/interface.py (3)
AttentionMetadata(44-394)PositionalEmbeddingParams(564-582)RopeParams(408-560)tensorrt_llm/_torch/models/modeling_utils.py (3)
register_auto_model(617-623)_load_weights_impl(816-937)_load_weights_impl_v2(940-1016)tensorrt_llm/_torch/modules/embedding.py (1)
Embedding(180-264)tensorrt_llm/_torch/modules/linear.py (1)
TensorParallelMode(50-62)tensorrt_llm/_torch/speculative/interface.py (1)
SpecMetadata(152-240)tensorrt_llm/_torch/model_config.py (1)
torch_dtype(206-211)
tests/unittest/_torch/modeling/test_modeling_starcoder2.py (6)
tensorrt_llm/_torch/models/modeling_starcoder2.py (5)
Starcoder2ForCausalLM(249-304)forward(70-86)forward(139-174)forward(213-245)load_weights(267-304)tests/unittest/utils/util.py (1)
default_dtype(406-410)tensorrt_llm/_torch/attention_backend/utils.py (1)
get_attention_backend(15-37)tensorrt_llm/_torch/metadata.py (1)
KVCacheParams(9-31)tensorrt_llm/_torch/pyexecutor/cuda_graph_runner.py (2)
CUDAGraphRunner(25-413)attn_metadata(131-132)tensorrt_llm/mapping.py (1)
Mapping(336-493)
🪛 Ruff (0.14.4)
tensorrt_llm/_torch/models/modeling_starcoder2.py
124-124: Avoid specifying long messages outside the exception class
(TRY003)
223-226: Avoid specifying long messages outside the exception class
(TRY003)
267-267: Do not use mutable data structures for argument defaults
Replace with None; initialize within function
(B006)
tests/unittest/_torch/modeling/test_modeling_starcoder2.py
117-117: Avoid specifying long messages outside the exception class
(TRY003)
146-146: Value being cast to int is already an integer
Remove unnecessary int call
(RUF046)
168-168: Consider [*context_sequence_lengths, 1, 1] instead of concatenation
Replace with [*context_sequence_lengths, 1, 1]
(RUF005)
245-245: Unused lambda argument: param_num
(ARG005)
426-426: Unused lambda argument: param_num
(ARG005)
542-542: Loop control variable step not used within loop body
Rename unused step to _step
(B007)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Pre-commit Check
|
PR_Github #24096 [ run ] triggered by Bot. Commit: |
|
PR_Github #24096 [ run ] completed with state |
9129c6e to
7d135ba
Compare
|
/bot run |
|
PR_Github #24515 [ run ] triggered by Bot. Commit: |
|
PR_Github #24515 [ run ] completed with state |
808368a to
86bff1c
Compare
180a560 to
c1ece3e
Compare
|
PR_Github #25212 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #25256 [ run ] triggered by Bot. Commit: |
|
PR_Github #25256 [ run ] completed with state |
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
Signed-off-by: Yibin Li <[email protected]>
72c473e to
cf69b40
Compare
|
/bot run --disable-fail-fast |
|
@2ez4bz @Wanli-Jiang all comments are addressed, could you review again? Thank you! |
|
PR_Github #25394 [ run ] triggered by Bot. Commit: |
|
PR_Github #25394 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #25407 [ run ] triggered by Bot. Commit: |
|
PR_Github #25407 [ run ] completed with state |
…#8923) Signed-off-by: Yibin Li <[email protected]>
Summary by CodeRabbit
New Features
Tests
Description
This PR implements PyTorch backend support for Starcoder2 3B, 7B, and 15B checkpoint, as well as the FP8 quantized checkpoint. Several tests are added to check network raw outputs or full e2e accuracy tests on GSM8K.
Token level output comparision against HF implementation:
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.
Details
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.