Skip to content

[DRAFT][DeepSeek-V4] Emit fp32 directly in linear_bf16_fp32 (drop .float() copy) - #3

Closed
AMD-yanfeiwang wants to merge 1 commit into
mainfrom
fix/dsv4-linear-bf16-fp32-native
Closed

AMD-yanfeiwang wants to merge 1 commit into
mainfrom
fix/dsv4-linear-bf16-fp32-native

Conversation

@AMD-yanfeiwang

@AMD-yanfeiwang AMD-yanfeiwang commented Jun 19, 2026 •

Copy link
Copy Markdown
Owner

Motivation

In the DSV4 indexer kv_score path, linear_bf16_fp32 (AITER branch) computes a bf16 GEMM and then casts to fp32 with .float():

return tgemm.mm(x, y, otype=x.dtype).float()

Profiling DeepSeek-V4 (8xMI355, tp=8) shows this .float() as a separate bfloat16tofloat32_copy kernel launched once per call (per layer, per step), e.g. shapes [256, {512,1024,2048}]. It is launched from compute_kv_score -> linear_bf16_fp32. It is small individually but recurs every decode step, and computing in bf16 then up-casting also loses precision.

Modifications

  • Request fp32 output directly from the GEMM (otype=torch.float32) so the up-cast is fused into the epilogue and the separate copy kernel is removed.

Dependency

This is the consumer-side half. To actually avoid the copy (rather than relocate it), AITER must expose a native fp32-output kernel for these bf16xbf16 shapes — companion draft: AMD-yanfeiwang/aiter fix/dsv4-bf16-fp32-native-gemm. Without it, tgemm falls back internally (correctness unaffected, but the copy/torch-fallback may remain), which is why this is a draft.

Status / TODO

  • Land companion AITER fp32-output GEMM support / tuned configs
  • Re-profile to confirm bfloat16tofloat32_copy is gone in the kv_score path
  • Confirm no GEMM perf regression vs the current tuned bf16 kernel + cast

CI States

Latest PR Test (Base): ❌ Run #27837016614
Latest PR Test (Extra): ❌ Run #27837016436

…at() copy

The AITER path of linear_bf16_fp32 computed a bf16 GEMM and then cast the
result to fp32 with `.float()`. That cast shows up in profiles as a separate
`bfloat16tofloat32_copy` kernel launched once per call in the DSV4 indexer
kv_score path. Request fp32 output from the GEMM directly so the up-cast is
fused into the epilogue, removing the copy and avoiding rounding the result
to bf16 first.

Pairs with an AITER change that provides a native fp32-output kernel for these
bf16xbf16 shapes; without it tgemm falls back internally (no regression in
correctness).
@AMD-yanfeiwang

Copy link
Copy Markdown
Owner Author

Superseded by the upstream PR against sgl-project/sglang: sgl-project#28877 (same branch/commit). Closing this fork-internal PR to avoid duplication.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant