Skip to content

[TRTLLM-12807][test] Guard thop attention kwarg aliases#15335

Open
yuxianq wants to merge 1 commit into
NVIDIA:mainfrom
yuxianq:test/thop-attention-kwarg-source-aliases
Open

[TRTLLM-12807][test] Guard thop attention kwarg aliases#15335
yuxianq wants to merge 1 commit into
NVIDIA:mainfrom
yuxianq:test/thop-attention-kwarg-source-aliases

Conversation

@yuxianq

@yuxianq yuxianq commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Tests
    • Added comprehensive validation for attention operation parameter naming conventions, including support for attribute source aliases and improved expression parsing to ensure consistent kwarg naming across configurations.

Description

Adds a static sync-test guard for the thop.attention(...) call site so kwargs sourced from self / metadata / forward_args must match the source leaf attribute name by default.

Existing intentional aliases are listed explicitly in the test allowlist, including:

context_lengths = metadata.prompt_lens_cuda_runtime
head_size = self.head_dim
host_context_lengths = metadata.prompt_lens_cpu_runtime
host_past_key_value_lengths = metadata.kv_lens_runtime
host_request_types = metadata.host_request_types_runtime
sequence_length = metadata.kv_lens_cuda_runtime
spec_decoding_target_max_draft_tokens = metadata.max_total_draft_tokens
workspace_ = metadata.effective_workspace

The test helper also recognizes getattr(source, "attr", ...) as a source attribute path so the current spec_decoding_target_max_draft_tokens mapping is checked instead of classified as an arbitrary expression.

Test Coverage

  • pytest -q tests/unittest/_torch/attention_backend/test_attention_op_sync.py
  • pre-commit run --files tests/unittest/_torch/attention_backend/test_attention_op_sync.py
  • pre-commit run --from-ref origin/main --to-ref HEAD

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)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • 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

To see a list of available CI bot commands, please comment /bot help.

Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 6d4eff45-8bbe-433f-9376-44a8a71cb500

📥 Commits

Reviewing files that changed from the base of the PR and between bb32597 and c4e1262.

📒 Files selected for processing (1)
  • tests/unittest/_torch/attention_backend/test_attention_op_sync.py

📝 Walkthrough

Walkthrough

This PR extends the attention backend synchronization test with infrastructure to validate that attribute-derived kwargs match their source leaf attributes. It introduces an allowlist for known exceptions, a helper function to parse getattr expressions, and integrates this into kwarg classification to enable a new validation test.

Changes

Attribute kwarg validation

Layer / File(s) Summary
Allowlist and AST parsing for getattr expressions
tests/unittest/_torch/attention_backend/test_attention_op_sync.py
Adds _THOP_KWARG_SOURCE_ALIASES allowlist mapping known kwarg name aliases, and implements _getattr_path helper to parse getattr(...) expressions into (root, attribute_path) metadata.
Kwarg classification integration
tests/unittest/_torch/attention_backend/test_attention_op_sync.py
Updates _classify_kwargs to use _getattr_path for attribute-derived kwarg classification, enabling getattr(...)-based values to be treated like direct attribute chains.
Attribute kwarg validation test
tests/unittest/_torch/attention_backend/test_attention_op_sync.py
Adds test_attr_kwarg_names_match_source_leaf_attrs_except_allowlisted_aliases to assert that attribute-derived kwarg names match resolved source leaf attributes, except for allowlisted exceptions.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a guard for thop attention kwarg aliases, which matches the PR's objective of enforcing that kwargs match source leaf attribute names except for explicit aliases.
Description check ✅ Passed The PR description provides a clear explanation of what the change does, lists the specific allowlist of aliases, explains the test helper improvement, and includes comprehensive test coverage steps and a completed checklist.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@yuxianq

yuxianq commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54038 [ run ] triggered by Bot. Commit: c4e1262 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54038 [ run ] completed with state SUCCESS. Commit: c4e1262
/LLM/main/L0_MergeRequest_PR pipeline #43122 completed with status: 'SUCCESS'

CI Report

Link to invocation

@yuxianq yuxianq requested a review from yihwang-nv June 13, 2026 10:33
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