Skip to content

[None][test] Enable session prefetch for all test stages#16770

Open
sunnyqgg wants to merge 1 commit into
NVIDIA:mainfrom
sunnyqgg:enable_prefetch_all_tests
Open

[None][test] Enable session prefetch for all test stages#16770
sunnyqgg wants to merge 1 commit into
NVIDIA:mainfrom
sunnyqgg:enable_prefetch_all_tests

Conversation

@sunnyqgg

@sunnyqgg sunnyqgg commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary

Changes

  • tests/test_common/session_prefetcher.py: remove the canary stage allowlist and enable prefetch by default for every test stage.
  • tests/unittest/llmapi/test_session_prefetcher.py: cover canary, non-canary, future, and local/no-stage execution plus explicit env overrides.

Test plan

  • python3 -m pytest llmapi/test_session_prefetcher.py -v -p no:cacheprovider in the TensorRT-LLM development container (42 passed)
  • Diff-scoped pre-commit hooks on both changed files
  • git diff --check

Dev Engineer Review

  • Removed the canary-stage allowlist so session/model prefetch is enabled by default.
  • Preserved TRTLLM_TEST_PREFETCH_SESSION=0 as an explicit kill switch and continued disabling prefetch in pytest-xdist workers.
  • Updated documentation and tests for canary, non-canary, future, local/no-stage, and environment-override scenarios.
  • No configuration or test-list files were changed. Validation passed: 42 tests, diff-scoped pre-commit hooks, and git diff --check.

QA Engineer Review

Test functions added:

  • test_enabled_by_default_in_all_stages
  • test_explicit_env_overrides_default

Test functions removed:

  • test_canary_enabled_on_canary_stage_groups
  • test_canary_disabled_elsewhere
  • test_explicit_env_overrides_canary_gate

These test-code changes are not listed in tests/integration/test_lists/ test-db or QA files.

Verdict: needs follow-up — CI/manual QA test-list coverage is not represented for the updated test functions.

Signed-off-by: qgai <qgai@nvidia.com>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Session prefetching now enables by default outside xdist workers, with TRTLLM_TEST_PREFETCH_SESSION as the explicit override. Canary stage gating was removed, and tests now cover default activation and environment-controlled behavior.

Changes

Session prefetch default activation

Layer / File(s) Summary
Default enablement logic
tests/test_common/session_prefetcher.py
Documentation and implementation remove canary stage gating and default SessionPrefetcher.enabled() to enabled unless the environment variable is falsy.
Activation behavior tests
tests/unittest/llmapi/test_session_prefetcher.py
Tests verify default enablement across stage names and explicit 0/1 environment overrides.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: junyixu-nv

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and matches the main change: enabling session prefetch by default across test stages.
Description check ✅ Passed The description covers the summary, changes, and test plan, which is enough even though the template headings are not exact.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/unittest/llmapi/test_session_prefetcher.py (1)

96-106: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Annotate the new test functions.

Add parameter and return annotations to comply with the repository’s Python requirements, for example stage_name: str | None, monkeypatch: pytest.MonkeyPatch, and -> None.

As per coding guidelines, every Python function must be annotated.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unittest/llmapi/test_session_prefetcher.py` around lines 96 - 106,
Annotate the new test functions test_enabled_by_default_in_all_stages and
test_explicit_env_overrides_default with the required parameter and return
types, including pytest.MonkeyPatch, stage_name: str | None where applicable,
and -> None.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/unittest/llmapi/test_session_prefetcher.py`:
- Around line 86-111: Add a regression test for SessionPrefetcher that sets
PYTEST_XDIST_WORKER while leaving prefetch otherwise enabled, and assert
SessionPrefetcher().enabled is false. Keep the existing non-xdist default and
explicit TRTLLM_TEST_PREFETCH_SESSION override tests unchanged.

---

Nitpick comments:
In `@tests/unittest/llmapi/test_session_prefetcher.py`:
- Around line 96-106: Annotate the new test functions
test_enabled_by_default_in_all_stages and test_explicit_env_overrides_default
with the required parameter and return types, including pytest.MonkeyPatch,
stage_name: str | None where applicable, and -> None.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6a5680b7-98df-42d6-b19e-d1e7091817e8

📥 Commits

Reviewing files that changed from the base of the PR and between a19410e and 0d1c0fa.

📒 Files selected for processing (2)
  • tests/test_common/session_prefetcher.py
  • tests/unittest/llmapi/test_session_prefetcher.py

Comment on lines +86 to +111
@pytest.mark.parametrize(
"stage_name",
[
None,
"A10-PyTorch-2",
"DGX_H100-4_GPUs-PyTorch-DeepSeek-1",
"DGX_B200-PyTorch-4",
"Any-Future-Stage",
],
)
def test_enabled_by_default_in_all_stages(monkeypatch, stage_name):
monkeypatch.delenv("TRTLLM_TEST_PREFETCH_SESSION", raising=False)
monkeypatch.delenv("PYTEST_XDIST_WORKER", raising=False)
monkeypatch.setenv("stageName", "A10-PyTorch-2")
assert SessionPrefetcher().enabled
monkeypatch.setenv("stageName", "DGX_H100-4_GPUs-PyTorch-DeepSeek-1")
if stage_name is None:
monkeypatch.delenv("stageName", raising=False)
else:
monkeypatch.setenv("stageName", stage_name)
assert SessionPrefetcher().enabled


def test_canary_disabled_elsewhere(monkeypatch):
monkeypatch.delenv("TRTLLM_TEST_PREFETCH_SESSION", raising=False)
def test_explicit_env_overrides_default(monkeypatch):
monkeypatch.delenv("PYTEST_XDIST_WORKER", raising=False)
monkeypatch.setenv("stageName", "DGX_B200-PyTorch-4")
assert not SessionPrefetcher().enabled
monkeypatch.delenv("stageName", raising=False) # local run, no stage
monkeypatch.setenv("TRTLLM_TEST_PREFETCH_SESSION", "0")
assert not SessionPrefetcher().enabled


def test_explicit_env_overrides_canary_gate(monkeypatch):
monkeypatch.delenv("PYTEST_XDIST_WORKER", raising=False)
monkeypatch.setenv("stageName", "DGX_B200-PyTorch-4") # not a canary stage
monkeypatch.setenv("TRTLLM_TEST_PREFETCH_SESSION", "1")
assert SessionPrefetcher().enabled # manual opt-in anywhere
monkeypatch.setenv("stageName", "A10-PyTorch-1") # canary stage
monkeypatch.setenv("TRTLLM_TEST_PREFETCH_SESSION", "0")
assert not SessionPrefetcher().enabled # kill switch beats the canary
assert SessionPrefetcher().enabled

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Add an xdist regression test.

Both tests explicitly remove PYTEST_XDIST_WORKER, so they do not verify the preserved contract that xdist workers remain disabled even when prefetch is otherwise enabled.

Proposed test
+def test_disabled_in_xdist_even_when_enabled(monkeypatch: pytest.MonkeyPatch) -> None:
+    monkeypatch.setenv("PYTEST_XDIST_WORKER", "gw0")
+    monkeypatch.setenv("TRTLLM_TEST_PREFETCH_SESSION", "1")
+    assert not SessionPrefetcher().enabled

The PR objective explicitly preserves xdist disablement.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@pytest.mark.parametrize(
"stage_name",
[
None,
"A10-PyTorch-2",
"DGX_H100-4_GPUs-PyTorch-DeepSeek-1",
"DGX_B200-PyTorch-4",
"Any-Future-Stage",
],
)
def test_enabled_by_default_in_all_stages(monkeypatch, stage_name):
monkeypatch.delenv("TRTLLM_TEST_PREFETCH_SESSION", raising=False)
monkeypatch.delenv("PYTEST_XDIST_WORKER", raising=False)
monkeypatch.setenv("stageName", "A10-PyTorch-2")
assert SessionPrefetcher().enabled
monkeypatch.setenv("stageName", "DGX_H100-4_GPUs-PyTorch-DeepSeek-1")
if stage_name is None:
monkeypatch.delenv("stageName", raising=False)
else:
monkeypatch.setenv("stageName", stage_name)
assert SessionPrefetcher().enabled
def test_canary_disabled_elsewhere(monkeypatch):
monkeypatch.delenv("TRTLLM_TEST_PREFETCH_SESSION", raising=False)
def test_explicit_env_overrides_default(monkeypatch):
monkeypatch.delenv("PYTEST_XDIST_WORKER", raising=False)
monkeypatch.setenv("stageName", "DGX_B200-PyTorch-4")
assert not SessionPrefetcher().enabled
monkeypatch.delenv("stageName", raising=False) # local run, no stage
monkeypatch.setenv("TRTLLM_TEST_PREFETCH_SESSION", "0")
assert not SessionPrefetcher().enabled
def test_explicit_env_overrides_canary_gate(monkeypatch):
monkeypatch.delenv("PYTEST_XDIST_WORKER", raising=False)
monkeypatch.setenv("stageName", "DGX_B200-PyTorch-4") # not a canary stage
monkeypatch.setenv("TRTLLM_TEST_PREFETCH_SESSION", "1")
assert SessionPrefetcher().enabled # manual opt-in anywhere
monkeypatch.setenv("stageName", "A10-PyTorch-1") # canary stage
monkeypatch.setenv("TRTLLM_TEST_PREFETCH_SESSION", "0")
assert not SessionPrefetcher().enabled # kill switch beats the canary
assert SessionPrefetcher().enabled
`@pytest.mark.parametrize`(
"stage_name",
[
None,
"A10-PyTorch-2",
"DGX_H100-4_GPUs-PyTorch-DeepSeek-1",
"DGX_B200-PyTorch-4",
"Any-Future-Stage",
],
)
def test_enabled_by_default_in_all_stages(monkeypatch, stage_name):
monkeypatch.delenv("TRTLLM_TEST_PREFETCH_SESSION", raising=False)
monkeypatch.delenv("PYTEST_XDIST_WORKER", raising=False)
if stage_name is None:
monkeypatch.delenv("stageName", raising=False)
else:
monkeypatch.setenv("stageName", stage_name)
assert SessionPrefetcher().enabled
def test_explicit_env_overrides_default(monkeypatch):
monkeypatch.delenv("PYTEST_XDIST_WORKER", raising=False)
monkeypatch.setenv("TRTLLM_TEST_PREFETCH_SESSION", "0")
assert not SessionPrefetcher().enabled
monkeypatch.setenv("TRTLLM_TEST_PREFETCH_SESSION", "1")
assert SessionPrefetcher().enabled
def test_disabled_in_xdist_even_when_enabled(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("PYTEST_XDIST_WORKER", "gw0")
monkeypatch.setenv("TRTLLM_TEST_PREFETCH_SESSION", "1")
assert not SessionPrefetcher().enabled
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unittest/llmapi/test_session_prefetcher.py` around lines 86 - 111, Add
a regression test for SessionPrefetcher that sets PYTEST_XDIST_WORKER while
leaving prefetch otherwise enabled, and assert SessionPrefetcher().enabled is
false. Keep the existing non-xdist default and explicit
TRTLLM_TEST_PREFETCH_SESSION override tests unchanged.

@sunnyqgg

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61174 [ run ] triggered by Bot. Commit: 0d1c0fa Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #61174 [ run ] completed with state FAILURE. Commit: 0d1c0fa
/LLM/main/L0_MergeRequest_PR pipeline #49422 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants