- Notifications
You must be signed in to change notification settings - Fork1.9k
[TRTLLM-8551][feat] add cache_salt in LLM.generate and refactor test_return_logits.py#8317
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
a7c730f toed6de31Compareed6de31 to7f0996dCompareixlmar commentedOct 13, 2025
/bot run --stage-list "A30-PyTorch-1,A30-PyTorch-2" |
tensorrt-cicd commentedOct 13, 2025
PR_Github #21191 [ run ] triggered by Bot |
7f0996d tof8bfeeeCompareixlmar commentedOct 13, 2025
/bot run --stage-list "A30-PyTorch-1" |
tensorrt-cicd commentedOct 13, 2025
PR_Github #21191 [ run ] completed with state |
tensorrt-cicd commentedOct 13, 2025
PR_Github #21206 [ run ] triggered by Bot |
f8bfeee toa81e6e1Comparetensorrt-cicd commentedOct 13, 2025
PR_Github #21206 [ run ] completed with state |
ixlmar commentedOct 13, 2025
/bot run |
📝 WalkthroughWalkthroughAdds an optional cache_salt parameter to BaseLLM.generate and threads it through the sync/async generation path to the executor as cache_salt_id. Updates integration test list. Introduces/expands unit tests for return logits and cache behavior, including parametrization, fixtures, and handling known timeout issues. Changes
Sequence Diagram(s)sequenceDiagram autonumber participant C as Client participant L as BaseLLM participant A as Async Gen Pipeline participant E as Executor Note over C,L: Synchronous call with optional cache_salt C->>L: generate(inputs, ..., cache_salt) L->>A: submit(inputs, ..., cache_salt) A->>E: execute(request, cache_salt_id=cache_salt) E-->>A: tokens, logits, caches A-->>L: RequestOutput L-->>C: RequestOutputEstimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 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: 0
🧹 Nitpick comments (2)
tests/unittest/_torch/sampler/test_return_logits.py (2)
38-58:Consider using a more robust salt generation approach.The
CacheSalterclass uses a class variable_saltthat is mutated across test invocations. While this works for serial test execution, it could lead to non-deterministic behavior if tests are run in parallel or the module is imported multiple times.Consider using a more explicit approach, such as a fixture-scoped counter or UUID generation:
class CacheSalter:-- _salt = 0- @classmethod- def get_salt_unique(cls) -> str:- cls._salt += 1- return str(cls._salt)+ def get_salt_unique(cls, iteration: int) -> str:+ return str(iteration)Or use UUIDs for guaranteed uniqueness:
importuuidclassCacheSalter:@classmethoddefget_salt_unique(cls)->str:returnstr(uuid.uuid4())However, the current implementation is acceptable given that pytest runs module tests serially by default.
138-156:Add explanatory comment for xfail condition
Above thepytest.xfail("Known bug: https://nvbugs/5577178")at line 152, include:# Bug manifests when context_logits gathering is enabled with cache reuseto clarify why only
gather_context_logits and reuse_cachetriggers xfail.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
tensorrt_llm/llmapi/llm.py(3 hunks)tests/integration/test_lists/test-db/l0_a30.yml(1 hunks)tests/unittest/_torch/sampler/test_return_logits.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/llmapi/llm.pytests/unittest/_torch/sampler/test_return_logits.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/llmapi/llm.pytests/unittest/_torch/sampler/test_return_logits.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/llmapi/llm.pytests/unittest/_torch/sampler/test_return_logits.py
🧬 Code graph analysis (1)
tests/unittest/_torch/sampler/test_return_logits.py (5)
tests/unittest/_torch/sampler/test_beam_search.py (1)
llm(37-49)tests/unittest/_torch/sampler/test_best_of_n.py (1)
llm(36-42)tensorrt_llm/llmapi/llm.py (3)
LLM(1087-1103)generate(249-330)generate_async(333-498)tensorrt_llm/scaffolding/task.py (1)
logprobs(99-100)tensorrt_llm/_torch/pyexecutor/llm_request.py (1)
generation_logits(298-307)
🔇 Additional comments (7)
tensorrt_llm/llmapi/llm.py (1)
265-265:LGTM! cache_salt parameter properly added to synchronous generate.The
cache_saltparameter is correctly added to the synchronousgeneratemethod signature, documented, and threaded through togenerate_async(which already supported it). This enables KV cache salting for batched synchronous generation.Also applies to: 286-286, 317-318
tests/integration/test_lists/test-db/l0_a30.yml (1)
24-24:LGTM! Test file added to integration suite.The new test file is appropriately added to the PyTorch test block in the A30 integration test list.
tests/unittest/_torch/sampler/test_return_logits.py (5)
12-15:LGTM! KV cache configuration updated for block reuse.The global KV cache config now enables block reuse, which is necessary to test the cache_salt functionality introduced in this PR.
18-36:LGTM! Fixture parametrization enables comprehensive test coverage.The module-scoped fixtures parametrize key configuration options (gather_context_logits, gather_generation_logits, disable_overlap_scheduler, sampler_type). This creates a test matrix that exercises different combinations, which is appropriate for thorough testing of the return_logits feature.
87-107:Workaround for LLM shutdown timeout is acceptable but should be tracked.The monkeypatch that converts pytest-timeout failures to xfails is a pragmatic workaround for the known bug (nvbugs/5577178). However, this approach could mask real test failures if other timeout issues arise.
Consider adding a more specific check to ensure only the expected shutdown timeout is caught:
def_exit_with_xfail_on_timeout(self,exc_type,exc_value,traceback)->bool:import_pytest.outcomestry:returnold_exit(self,exc_type,exc_value,traceback)except_pytest.outcomes.Failedase:ife.msgand"pytest-timeout"ine.msg.lower():# Add more specific check for shutdown contextif"shutdown"instr(e)or"_shutdown"instr(e):pytest.xfail("Known LLM shutdown issue (https://nvbugs/5577178).")raise# Re-raise if it's a different timeoutelse:raiseThis would help ensure that only shutdown-related timeouts are converted to xfails, while other timeout failures are still caught.
110-116:Test markers appropriately configured for known issues.The timeout and threadleak markers are correctly added to handle the known LLM shutdown issue (nvbugs/5577178). The 120-second timeout is reasonable, and the signal method ensures child processes are also terminated.
200-234:Unconditional xfail for async generation_logits is appropriate.
The async test streams one token at a time, so the nvbugs/5573238 mismatch affects all streaming cases and warrants the unconditional xfail.
tensorrt-cicd commentedOct 13, 2025
PR_Github #21214 [ run ] triggered by Bot |
tensorrt-cicd commentedOct 13, 2025
PR_Github #21214 [ run ] completed with state |
a81e6e1 to90b1100Compareixlmar commentedOct 13, 2025
/bot run --disable-fail-fast |
tensorrt-cicd commentedOct 13, 2025
PR_Github #21235 [ run ] triggered by Bot |
tensorrt-cicd commentedOct 13, 2025
PR_Github #21235 [ run ] completed with state |
0f7d268 to518f2f6Compareixlmar commentedOct 14, 2025
/bot run --disable-fail-fast |
tensorrt-cicd commentedOct 14, 2025
PR_Github #21334 [ run ] completed with state |
ixlmar commentedOct 14, 2025
/bot run --disable-fail-fast |
tensorrt-cicd commentedOct 14, 2025
PR_Github #21335 [ run ] triggered by Bot |
Uh oh!
There was an error while loading.Please reload this page.
10fbddd toe1a2d86Compareixlmar commentedOct 14, 2025
/bot run --disable-fail-fast |
tensorrt-cicd commentedOct 14, 2025
PR_Github #21367 [ run ] triggered by Bot |
tensorrt-cicd commentedOct 14, 2025
PR_Github #21335 [ run ] completed with state |
syuoni left a 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.
LGTM, please update the doc string and API reference, thanks!
Uh oh!
There was an error while loading.Please reload this page.
Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
e1a2d86 to54893d0Compareixlmar commentedOct 14, 2025
/bot run --disable-fail-fast |
tensorrt-cicd commentedOct 14, 2025
PR_Github #21373 [ run ] triggered by Bot |
tensorrt-cicd commentedOct 14, 2025
PR_Github #21367 [ run ] completed with state |
tensorrt-cicd commentedOct 15, 2025
PR_Github #21373 [ run ] completed with state |
ixlmar commentedOct 15, 2025
/bot run |
tensorrt-cicd commentedOct 15, 2025
PR_Github #21444 [ run ] triggered by Bot |
tensorrt-cicd commentedOct 15, 2025
PR_Github #21444 [ run ] completed with state |
0510b34 intoNVIDIA:mainUh oh!
There was an error while loading.Please reload this page.
…return_logits.py (NVIDIA#8317)Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
…return_logits.py (NVIDIA#8317)Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>Signed-off-by: yufeiwu-nv <230315618+yufeiwu-nv@users.noreply.github.com>
…return_logits.py (NVIDIA#8317)Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
…return_logits.py (NVIDIA#8317)Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
…return_logits.py (NVIDIA#8317)Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
…return_logits.py (NVIDIA#8317)Signed-off-by: ixlmar <206748156+ixlmar@users.noreply.github.com>
Uh oh!
There was an error while loading.Please reload this page.
Description
LLMinstance, reducing test time by about 3x.cache_salt, which was supported forLLM.generate_asyncbut not forLLM.generate. The PR resolves this discrepancy.test_return_logits.pyappears not to have been included in the CI tests.Test Coverage
Change pertains to test.
cache_saltis used by existing tests.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 FollowsTRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (seetest 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: DoesNOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: DoesNOT 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: DoesNOT 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: DoesNOT update GitHub pipeline status.--only-multi-gpu-test(OPTIONAL) : Only run the multi-GPU tests. Note: DoesNOT update GitHub check status.--disable-multi-gpu-test(OPTIONAL) : Disable the multi-GPU tests. Note: DoesNOT 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: DoesNOT 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.
Summary by CodeRabbit
New Features
Tests