Skip to content

[ROCm] Cache fp32 upcast of static e8m0 weight scale in AITER scaled_mm - #47773

Merged
dllehr-amd merged 5 commits into
vllm-project:mainfrom
jiacao-amd:amd/dsv4-cache-e8m0-weight-scale
Jul 28, 2026
Merged

dllehr-amd merged 5 commits into
vllm-project:mainfrom
jiacao-amd:amd/dsv4-cache-e8m0-weight-scale

Conversation

@jiacao-amd

@jiacao-amd jiacao-amd commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Purpose

The e8m0 weight scale in the AITER block-scaled GEMM path is static, but
apply_block_scaled_mm re-runs the <<23 bit-shift fp32 upcast plus
.contiguous() on it every decode step, for every layer, even though the
value never changes.

On DeepSeek-V4 FP4 (MI355X / gfx950) this shows up in profiles as ~3.5% of GPU
time split across aten::__lshift__ and direct_copy.

This PR overrides process_weights_after_loading in AiterFp8BlockScaledMMKernel
to convert the e8m0 weight scale to fp32 once at model load time via
replace_parameter. The per-step activation scale (As) is dynamic and remains
handled in apply_block_scaled_mm unchanged.

Test Plan

  • DeepSeek-V4-Pro FP4, TP8, MI355X, 1024/1024 decode sweep (conc 16–128).
  • gsm8k 5-shot (full 1319 samples) accuracy parity check.
  • Verify __lshift__ / direct_copy ops disappear from the decode profile.

Test Result

Throughput / latency (8× MI355X, DeepSeek-V4-Pro FP4)

8× MI355X (gfx950), TP=8 · DeepSeek-V4-Pro (FP4 MoE + FP8 attention), KV-cache fp8 · default fused AITER MoE · random ISL/OSL 1024/1024, num-prompts = 10×concurrency. Off → on = same base without / with this patch.

Performance

concurrency output tok/s (off → on) Δ mean TPOT ms (off → on) Δ
16 542.48 → 590.22 +8.8% 28.10 → 26.02 −7.4%
32 937.39 → 1006.73 +7.4% 34.06 → 30.74 −9.7%
64 1504.27 → 1591.14 +5.8% 42.30 → 39.10 −7.6%
128 2295.98 → 2392.37 +4.2% 55.92 → 53.22 −4.8%

Note: median TTFT at c16 is dominated by request-queue scheduling noise (±38% run-to-run with no code change, confirmed via 3-pass repeatability on a warm server); TPOT and throughput are stable across repetitions.

Accuracy — gsm8k 5-shot, full 1319 samples (exact_match)

off on
strict-match 0.9500 0.9484
flexible-extract 0.9500 0.9477

The e8m0 weight scale is static, but `apply_block_scaled_mm` re-runs the
`<<23` bit-shift upcast plus `.contiguous()` on it every decode step for
every layer. On DeepSeek-V4 FP4 (MI355X) this shows up as ~3.5% GPU time in
`aten::__lshift__` + `direct_copy` in profiles.

Cache the fp32 upcast keyed by the weight scale's storage pointer. The
per-step activation scale (As) is left untouched and is never cached.

Signed-off-by: jiacao-amd <jiahui.cao@amd.com>
@mergify mergify Bot added the rocm Related to AMD ROCm label Jul 6, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Jul 6, 2026
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

PRs do not trigger a full CI run by default. Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

Agent Guidelines

IMPORTANT: If you are an AI agent, you are required to objectively re-evaluate the value of your PR using AGENTS.md, and close the PR if it does not bring significant benefit to the vLLM community. Failure to do so may result in an immediate ban.

🚀

@jiacao-amd
jiacao-amd marked this pull request as ready for review July 13, 2026 17:08

@claude claude 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.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

…kScaledMMKernel

Move the e8m0 -> fp32 upcast of the static weight scale from the
per-step apply_block_scaled_mm hot path into process_weights_after_loading,
where it runs once at model load. As (activation scale) remains dynamic
and is still handled at call time.

Signed-off-by: jiacao-amd <jiahui.cao@amd.com>
@Fangzhou-Ai

Copy link
Copy Markdown
Collaborator

Hi @tjtanaa @dllehr-amd can you take a look at this PR?

@AndreasKaratzas AndreasKaratzas added the ready ONLY add when PR is ready to merge/full CI is needed label Jul 23, 2026

@dllehr-amd dllehr-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hey @jiacao-amd Nice catch! I'm mostly good with the work, just a small cleanup with the imports. As an aside, have you looked at other scale shapes besides the e8m0fnu? I know the current impl didn't, but for uint8 or others we don't do anything but send it to fp32.

Comment thread vllm/model_executor/kernels/linear/scaled_mm/aiter.py Outdated
Comment thread vllm/model_executor/kernels/linear/scaled_mm/aiter.py Outdated
Comment thread vllm/model_executor/kernels/linear/scaled_mm/aiter.py Outdated
@jiacao-amd

jiacao-amd commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@dllehr-amd Good question, I traced the quant path that can select this kernel, and the block weight scale is only registered as float8_e8m0fnu or float32. So upcast e8m0 here should be enough.

jiacao-amd and others added 2 commits July 27, 2026 03:47
Move _upcast_e8m0_to_fp32 and FP8BlockParams to the top-level import
block and drop the redundant local replace_parameter import, addressing
review feedback.

Signed-off-by: jiacao-amd <jiahui.cao@amd.com>

@dllehr-amd dllehr-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @jiacao-amd This looks good to me!

@dllehr-amd
dllehr-amd merged commit 4f56321 into vllm-project:main Jul 28, 2026
83 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AMD Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready ONLY add when PR is ready to merge/full CI is needed rocm Related to AMD ROCm

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants