Skip to content

perf(dsv4 hc_pre): widen linear split-K LINEAR_OK 4->8 (align with hc_head) - #804

Open
wangqin1723-max wants to merge 1 commit into
hw-native-sys:mainfrom
wangqin1723-max:perf/dsv4-hcpre-linear-ok8
Open

perf(dsv4 hc_pre): widen linear split-K LINEAR_OK 4->8 (align with hc_head)#804
wangqin1723-max wants to merge 1 commit into
hw-native-sys:mainfrom
wangqin1723-max:perf/dsv4-hcpre-linear-ok8

Conversation

@wangqin1723-max

Copy link
Copy Markdown
Contributor

What

Align hc_pre_linear's split-K factor with hc_head: LINEAR_OK 4 -> 8. Each cube task's K reduction halves (4096 -> 2048); decode task count doubles (4 -> 8). K_CHUNK (256) and L0B pressure are unchanged, and the result is bit-identical (same atomic-add reduction, same K order per slice). Matches hc_head's LINEAR_OK = 8.

Why

  • Consistency: hc_head already uses LINEAR_OK = 8 for the same linear split-K structure; aligning hc_pre removes a needless divergence.
  • The hc_pre_linear kernel itself gets faster (shorter matmul_acc chain).

A/B (DSv4 moe EP2 decode, even primary dies, 6 interleaved rounds)

metric OK=4 OK=8
hc_pre_linear kernel Exec 9.75 us 6.51 us (-33%)
comb_sinkhorn Exec 14.44 us 14.81 us (unchanged)
hc_pre decode wall (isolated) 45.35 us 44.15 us (-2.6% mean)

The linear kernel speedup is real (-33%), but it does not reliably move the end-to-end wall: linear (6.5us) sits below rms (9.8us) and well below the actual pole comb_sinkhorn (14.7us, the 20-iter serial Sinkhorn recurrence). The -2.6% wall mean is not statistically significant at n=6 (paired diffs are scattered around zero, p ~ 0.19).

Kept for hc_head consistency and to pre-stage the split-K widening for when a later change shifts the hc_pre pole onto linear.

Validation

  • python models/deepseek/v4/hc_pre.py -p a2a3 --enable-l2-swimlane -- golden PASS (decode B=4 S=2 + prefill T=128; x_mixed / post / comb all within tolerance).

Align hc_pre_linear's split-K factor with hc_head (both LINEAR_OK = 8).
Each cube task's K reduction halves (4096 -> 2048) and the decode task
count doubles (4 -> 8); K_CHUNK (256) and L0B pressure are unchanged,
and the result is bit-identical (same atomic-add reduction, same K order
per slice). Matches hc_head's LINEAR_OK = 8.

A/B (DSv4 moe EP2 decode, even primary dies, 6 interleaved rounds):
- hc_pre_linear kernel Exec: 9.75 -> 6.51 us (-33%)
- comb_sinkhorn Exec: ~14.7 us (unchanged -- the actual pole)
- hc_pre decode wall (isolated): 45.4 -> 44.2 us (-2.6% mean; paired
  diffs scattered, p~0.19 -- not yet statistically significant)

linear is not hc_pre's pole today (linear 6.5 < rms 9.8 < sinkhorn 14.7
us), so the kernel speedup does not reliably move the end-to-end wall.
Kept for hc_head consistency and to pre-stage the split-K widening for
when a later change shifts the pole onto linear.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 49634058-b55f-4b57-851e-02bef025bf9b

📥 Commits

Reviewing files that changed from the base of the PR and between 9931cac and fec57dd.

📒 Files selected for processing (1)
  • models/deepseek/v4/hc_pre.py

📝 Walkthrough

Walkthrough

LINEAR_OK is increased from 4 to 8 in hc_pre.py, updating the derived linear tiling and documenting the revised handoff to comb_sinkhorn.

Changes

Linear split-K configuration

Layer / File(s) Summary
Update linear split-K fan-out
models/deepseek/v4/hc_pre.py
LINEAR_OK changes from 4 to 8, and adjacent comments describe the updated K partitioning and atomic-add tiling balance.

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

Poem

A rabbit counts the splits anew,
Four hops become eight in view.
K tiles halve and kernels align,
Atomic adds march down the line.
“Comb_sinkhorn,” I twitch, “looks fine!”

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: widening hc_pre linear split-K from 4 to 8 to match hc_head.
Description check ✅ Passed The description is directly related to the change and explains the what, why, and validation details.
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.

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 increases LINEAR_OK from 4 to 8 in models/deepseek/v4/hc_pre.py to test performance handoffs, matching the configuration in hc_head. The reviewer suggests adding safety assertions to ensure that HC_DIM is divisible by LINEAR_OK and that the resulting split K dimension is divisible by LINEAR_K_CHUNK to prevent potential silent correctness issues.

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.

# Each task's K halves (4096 -> 2048); K_CHUNK (256) and L0B pressure unchanged.
# Counter-pressure: 2x atomic-add producers on the same mixes_raw[0:16,0:32]
# tile at the handoff. Matches hc_head's LINEAR_OK = 8.
LINEAR_OK = 8

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

To prevent silent correctness issues or out-of-bounds slicing if LINEAR_OK or HC_DIM are modified in the future, we should add safety assertions to ensure that HC_DIM is divisible by LINEAR_OK and that the resulting split K dimension is divisible by LINEAR_K_CHUNK. This aligns with the safety checks present in hc_head.py.

Suggested change
LINEAR_OK = 8
LINEAR_OK = 8
assert HC_DIM % LINEAR_OK == 0 and (HC_DIM // LINEAR_OK) % LINEAR_K_CHUNK == 0
References
  1. When assuming specific invariants or configuration coverages in a kernel, make this invariant explicit with a module-level assertion to prevent silent correctness issues if configurations change.

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