-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[None][feat] AutoDeploy: chunked prefill support #8158
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
base: main
Are you sure you want to change the base?
Conversation
Some long-context prompts to play around with chunked prefill and with some sanity check that the chunked context is correctly read/written:
|
c89c01c
to
3ebbbe2
Compare
3ebbbe2
to
c0dcca0
Compare
/bot run |
PR_Github #21240 [ run ] triggered by Bot |
📝 WalkthroughWalkthroughEnables optional chunked prefill in auto-deploy: makes config flag mutable, wires a ContextChunkingConfig into micro-batch scheduling when enabled, truncates cache indices to active KV blocks during context handling, and updates integration/unit tests and test lists to parameterize and validate chunked vs non-chunked behavior. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant AE as create_autodeploy_executor
participant S1 as BindCapacityScheduler
participant S2 as BindMicroBatchScheduler
participant K as KVCacheManager
rect rgba(230,240,255,0.5)
note over AE: Initialization
C->>AE: ad_config, engine, kv_cache_manager, attn_page_size
AE->>AE: if enable_chunked_prefill: ctx_chunk_config=ContextChunkingConfig(FIFO, unit_size=attn_page_size) else None
AE->>S1: BindCapacityScheduler(max_num_requests=ad_config.max_batch_size, kv_cache_manager=K.impl, peft_cache_manager=None)
AE->>S2: BindMicroBatchScheduler(max_batch_size=ad_config.max_batch_size, max_num_tokens=engine.cache_seq_interface.info.max_num_tokens, ctx_chunk_config=ctx_chunk_config)
AE-->>C: executor
end
sequenceDiagram
autonumber
participant R as Request (context)
participant EX as Executor._prepare_inputs
participant K as KV Cache
rect rgba(240,255,240,0.5)
note over EX: Context handling
R->>EX: page_assignments, end_compute
EX->>K: query active KV blocks (0..end_compute)
EX->>EX: truncate page_assignments to active subset
EX-->>R: prepared inputs (active cache indices)
end
note over R,EX: When chunked prefill enabled, scheduling uses ctx_chunk_config during batching
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py (1)
65-69
: Fix logging call (formatting bug causes runtime error).
ad_logger.info("...", self.num_blocks)
uses %-formatting with no placeholders → TypeError.Use f-string or add placeholder:
- ad_logger.info("Using fake cache manager with head_dim=0 and num pages:", self.num_blocks) + ad_logger.info("Using fake cache manager with head_dim=0 and num pages: %s", self.num_blocks)tests/integration/defs/accuracy/test_llm_api_autodeploy.py (1)
44-63
: Constraint violation:max_num_tokens
must exceedmax_batch_size
.The comment on line 62 states that
max_num_tokens
must be strictly greater thanmax(attn_page_size, max_batch_size)
. However,max_num_tokens
is set to 512 whilemax_batch_size
is also 512, violating this constraint (512 is not > 512).Apply this diff to satisfy the constraint:
if enable_chunked_prefill: config["enable_chunked_prefill"] = True config[ - "max_num_tokens"] = 512 # NOTE: must be > max(attn_page_size, max_batch_size) + "max_num_tokens"] = 1024 # NOTE: must be > max(attn_page_size, max_batch_size) return configAlternatively, if memory constraints require
max_num_tokens
to remain at 512, reducemax_batch_size
to a value less than 512 when chunked prefill is enabled.
🧹 Nitpick comments (4)
tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py (2)
139-141
: Silence unused-argument lint in tests.Rename param to
_request
to address Ruff ARG002.- def get_cache_indices(self, request): + def get_cache_indices(self, _request): # Return many dummy page IDs; ADEngine will truncate as needed return list(range(1024))
170-218
: Optional: guard tests on CUDA.Tests hardcode
cuda
. Add skip to avoid local failures.@pytest.mark.parametrize("attn_page_size", [256, 2]) def test_ad_engine_chunked_prefill_equivalence(attn_page_size: int): + if not torch.cuda.is_available(): + pytest.skip("CUDA required")Also consider adding the same guard to
test_engine
andtest_demo_engine_sampling
.tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py (2)
208-212
: Cache index truncation for context prefill looks correct.Slicing to
num_active_blocks
matchesend_compute
. Please update the preceding comment (“will be used in the future”) since it’s now used.
381-388
: Surface chunking policy via config (future-proofing).Policy is hardcoded to FIRST_COME_FIRST_SERVED. Consider adding it to
AutoDeployConfig
(with sane default) so tests can exercise other policies without code changes.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (8)
tensorrt_llm/_torch/auto_deploy/llm_args.py
(1 hunks)tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py
(3 hunks)tests/integration/defs/accuracy/test_llm_api_autodeploy.py
(6 hunks)tests/integration/test_lists/test-db/l0_b200.yml
(1 hunks)tests/integration/test_lists/test-db/l0_dgx_h100.yml
(1 hunks)tests/integration/test_lists/test-db/l0_dgx_h200.yml
(1 hunks)tests/integration/test_lists/test-db/l0_h100.yml
(1 hunks)tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py
(2 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/auto_deploy/llm_args.py
tests/integration/defs/accuracy/test_llm_api_autodeploy.py
tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py
tensorrt_llm/_torch/auto_deploy/shim/ad_executor.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/auto_deploy/llm_args.py
tests/integration/defs/accuracy/test_llm_api_autodeploy.py
tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py
tensorrt_llm/_torch/auto_deploy/shim/ad_executor.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/auto_deploy/llm_args.py
tests/integration/defs/accuracy/test_llm_api_autodeploy.py
tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py
tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py
🧬 Code graph analysis (3)
tensorrt_llm/_torch/auto_deploy/llm_args.py (1)
tensorrt_llm/llmapi/llm_args.py (1)
Field
(70-97)
tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py (4)
tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (3)
device
(218-219)SequenceInfo
(50-804)to
(542-550)tensorrt_llm/_torch/attention_backend/flashinfer.py (1)
page_size
(185-189)tensorrt_llm/_torch/auto_deploy/shim/interface.py (1)
to
(49-53)tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py (2)
ADEngine
(72-299)forward
(277-299)
tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py (5)
tensorrt_llm/llmapi/llm_args.py (1)
ContextChunkingPolicy
(917-923)tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py (2)
get_cache_indices
(139-141)get_num_kv_blocks
(143-146)tensorrt_llm/_torch/pyexecutor/resource_manager.py (2)
get_cache_indices
(647-658)get_num_kv_blocks
(692-693)tensorrt_llm/_torch/auto_deploy/custom_ops/attention_interface.py (1)
page_assignments
(420-422)tensorrt_llm/_torch/pyexecutor/scheduler.py (2)
BindCapacityScheduler
(70-97)BindMicroBatchScheduler
(169-188)
🪛 Ruff (0.14.0)
tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py
139-139: Unused method argument: request
(ARG002)
⏰ 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
🔇 Additional comments (9)
tensorrt_llm/_torch/auto_deploy/shim/ad_executor.py (1)
390-399
: Scheduler kwargs update LGTM.Keyword args improve clarity; passing
ctx_chunk_config
intoBindMicroBatchScheduler
aligns with chunked prefill.tensorrt_llm/_torch/auto_deploy/llm_args.py (1)
139-139
: Field addition LGTM.
enable_chunked_prefill
is appropriately added and mutable; integrates with executor setup.Double-check that
attn_page_size
yields intendedchunk_unit_size
across backends (triton/torch set tomax_seq_len
via validator, flashinfer uses tokens_per_block).tests/integration/test_lists/test-db/l0_dgx_h200.yml (1)
121-121
: No change needed:[False-4]
variant exists.tests/integration/test_lists/test-db/l0_b200.yml (1)
78-78
: Test ID [False-1] exists
This suffix correctly maps to enable_chunked_prefill=False and world_size=1 in TestLlama3_1_8B::test_auto_dtype.tests/integration/test_lists/test-db/l0_h100.yml (1)
119-122
: Param variants align with test definitions. IDs[False-1]
,[True-1]
forTestLlama3_1_8B
and[False]
,[True]
forTestNemotronH
correctly match the pytest parametrization.tests/integration/test_lists/test-db/l0_dgx_h100.yml (1)
44-44
: YAML entry correct
TheTestLlama3_1_8B.test_auto_dtype
intest_llm_api_autodeploy.py
is parametrized overworld_size=[1,2,4]
andenable_chunked_prefill=[False,True]
, yielding an item[False-2]
.tests/integration/defs/accuracy/test_llm_api_autodeploy.py (3)
73-87
: LGTM!The test parameterization correctly exercises both chunked and non-chunked prefill paths across multiple world sizes, providing good test coverage for the new feature.
126-140
: LGTM: Skip logic appropriately handles known limitation.The skip logic correctly prevents test execution when chunked prefill is enabled for NemotronH, with proper issue tracking via GitHub issue #8272. The test parameterization ensures coverage for the non-chunked case.
93-116
: Constraint satisfied:max_num_tokens
(512) > defaultattn_page_size
(64).
tests/unittest/_torch/auto_deploy/unit/singlegpu/shim/test_engine.py
Outdated
Show resolved
Hide resolved
c0dcca0
to
0422fa0
Compare
/bot run |
PR_Github #21241 [ run ] triggered by Bot |
PR_Github #21240 [ run ] completed with state |
PR_Github #21241 [ run ] completed with state |
Signed-off-by: Lucas Liebenwein <[email protected]>
Signed-off-by: Lucas Liebenwein <[email protected]>
d060ec9
to
02a3404
Compare
/bot run |
PR_Github #21254 [ run ] triggered by Bot |
PR_Github #21254 [ run ] completed with state |
/bot run --disable-fail-fast |
PR_Github #21364 [ run ] triggered by Bot |
PR_Github #21364 [ run ] completed with state |
Summary by CodeRabbit
New Features
Tests
Description
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-list
parameter 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.md
and the
scripts/test_to_stage_mapping.py
helper.kill
kill
Kill all running builds associated with pull request.
skip
skip --comment COMMENT
Skip 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-pipeline
Reuse 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.