Skip to content

perf(dsv4 hca decode): early-resolve gather_kv/merge_norm + L2 swimlane level flag - #785

Open
wangqin1723-max wants to merge 1 commit into
hw-native-sys:mainfrom
wangqin1723-max:perf/dsv4-hca-early-resolve
Open

perf(dsv4 hca decode): early-resolve gather_kv/merge_norm + L2 swimlane level flag#785
wangqin1723-max wants to merge 1 commit into
hw-native-sys:mainfrom
wangqin1723-max:perf/dsv4-hca-early-resolve

Conversation

@wangqin1723-max

Copy link
Copy Markdown
Contributor

Summary

  • decode_sparse_attn_hca.py: add allow_early_resolve to hca_gather_kv and merge_norm, completing the producer sets for the already-flagged qk_pv / proj_a_mm consumers so they can pre-stage (early dispatch).
  • decode_attention_hca.py: --enable-l2-swimlane now takes a granularity level (1=AICore timing, 2=+dispatch/fanout, 3=+sched phases, 4=+orch phases; bare flag = 4/full).

Performance

hca_gather_kv is the main lever — it completes qk_pv's producer set so qk_pv can pre-stage (its dispatch bubble → ~0) and stabilizes the HCA decode AICore time. merge_norm is neutral (proj_a_mm is an O_GROUPS parallel reduction — core-contention-bound rather than dispatch-fanin-bound); kept for producer-set completeness.

6-run AICore end-to-end on this config (a2a3, --start-pos 8192): 310.9 / 312.9 / 314.4 / 319.0 / 320.7 / 326.7 us (median ~317, σ≈6).

Validation

  • golden PASS (kv_cache + x_out), a2a3 device, --start-pos 8192.

…ne level flag

- decode_sparse_attn_hca.py: allow_early_resolve on hca_gather_kv and
  merge_norm (complete the qk_pv / proj_a_mm producer sets so those
  flagged consumers can pre-stage).
- decode_attention_hca.py: --enable-l2-swimlane takes a granularity
  level (1=AICore timing, 2=+dispatch/fanout, 3=+sched phases,
  4=+orch phases; bare flag = 4/full).
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds optional L2 swimlane performance levels and enables earlier dependency resolution for two sparse attention SPMD stages.

Changes

Decode HCA updates

Layer / File(s) Summary
Configurable L2 swimlane level
models/deepseek/v4/decode_attention_hca.py
The flag accepts an optional integer performance level, defaults to 0, and uses 4 when passed without a value.
Early SPMD dependency resolution
models/deepseek/v4/decode_sparse_attn_hca.py
Sparse-K gathering and merge-norm dispatches enable allow_early_resolve=True.

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

Possibly related PRs

Poem

A rabbit bounds through lanes of four,
While gather tasks begin the chore.
Merge and norm resolve with grace,
And flags now choose their running pace.
Hop, hop—decode finds its flow!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main changes: early-resolve updates and the L2 swimlane level flag.
Description check ✅ Passed The description is directly related to the changes and accurately explains the new early-resolve and swimlane granularity behavior.
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.

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.

❤️ Share

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

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the --enable-l2-swimlane argument in decode_attention_hca.py to support new granularity levels (0-4) and adds allow_early_resolve=True to SPMD contexts in decode_sparse_attn_hca.py to enable early resolution. The reviewer recommends restoring the choices constraint for --enable-l2-swimlane with the updated range (0, 1, 2, 3, 4) to ensure robust command-line validation.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +660 to +670
parser.add_argument(
"--enable-l2-swimlane",
nargs="?",
const=4,
default=0,
type=int,
metavar="PERF_LEVEL",
help="Enable L2 swimlane perf capture at the given granularity level. Bare flag "
"= level 4 (full). Levels: 1=AICore timing, 2=+dispatch/fanout, 3=+sched "
"phases, 4=+orch phases; 0 (default) disables.",
)

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.

medium

The choices constraint was removed when updating --enable-l2-swimlane to support the new granularity levels. To prevent invalid inputs (e.g., values outside the 0-4 range) and ensure robust command-line validation, please restore the choices constraint with the updated valid range (0, 1, 2, 3, 4).

Suggested change
parser.add_argument(
"--enable-l2-swimlane",
nargs="?",
const=4,
default=0,
type=int,
metavar="PERF_LEVEL",
help="Enable L2 swimlane perf capture at the given granularity level. Bare flag "
"= level 4 (full). Levels: 1=AICore timing, 2=+dispatch/fanout, 3=+sched "
"phases, 4=+orch phases; 0 (default) disables.",
)
parser.add_argument(
"--enable-l2-swimlane",
nargs="?",
const=4,
default=0,
type=int,
choices=(0, 1, 2, 3, 4),
metavar="PERF_LEVEL",
help="Enable L2 swimlane perf capture at the given granularity level. Bare flag "
"= level 4 (full). Levels: 1=AICore timing, 2=+dispatch/fanout, 3=+sched "
"phases, 4=+orch phases; 0 (default) disables.",
)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@models/deepseek/v4/decode_attention_hca.py`:
- Around line 660-669: Restrict the --enable-l2-swimlane PERF_LEVEL argument in
the parser configuration to the documented values 0 through 4. Restore
choices=(0, 1, 2, 3, 4) or add equivalent validation before runtime_cfg is
constructed, while preserving the bare-flag default of level 4.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 32ac0e85-9ecf-4ec5-a934-946dd7d3d34f

📥 Commits

Reviewing files that changed from the base of the PR and between 6e897cd and 342935a.

📒 Files selected for processing (2)
  • models/deepseek/v4/decode_attention_hca.py
  • models/deepseek/v4/decode_sparse_attn_hca.py

Comment on lines +660 to +669
parser.add_argument(
"--enable-l2-swimlane",
nargs="?",
const=4,
default=0,
type=int,
metavar="PERF_LEVEL",
help="Enable L2 swimlane perf capture at the given granularity level. Bare flag "
"= level 4 (full). Levels: 1=AICore timing, 2=+dispatch/fanout, 3=+sched "
"phases, 4=+orch phases; 0 (default) disables.",

Copy link
Copy Markdown

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

Restrict PERF_LEVEL to the documented range.

Removing choices means values outside the supported levels, such as 5 or -1, are accepted and forwarded to run_jit. Restore choices=(0, 1, 2, 3, 4) or validate the range before constructing runtime_cfg.

Proposed fix
         const=4,
         default=0,
         type=int,
+        choices=(0, 1, 2, 3, 4),
         metavar="PERF_LEVEL",
📝 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
parser.add_argument(
"--enable-l2-swimlane",
nargs="?",
const=4,
default=0,
type=int,
metavar="PERF_LEVEL",
help="Enable L2 swimlane perf capture at the given granularity level. Bare flag "
"= level 4 (full). Levels: 1=AICore timing, 2=+dispatch/fanout, 3=+sched "
"phases, 4=+orch phases; 0 (default) disables.",
parser.add_argument(
"--enable-l2-swimlane",
nargs="?",
const=4,
default=0,
type=int,
choices=(0, 1, 2, 3, 4),
metavar="PERF_LEVEL",
help="Enable L2 swimlane perf capture at the given granularity level. Bare flag "
"= level 4 (full). Levels: 1=AICore timing, 2=+dispatch/fanout, 3=+sched "
"phases, 4=+orch phases; 0 (default) disables.",
🤖 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 `@models/deepseek/v4/decode_attention_hca.py` around lines 660 - 669, Restrict
the --enable-l2-swimlane PERF_LEVEL argument in the parser configuration to the
documented values 0 through 4. Restore choices=(0, 1, 2, 3, 4) or add equivalent
validation before runtime_cfg is constructed, while preserving the bare-flag
default of level 4.

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.

1 participant