Skip to content

feat(runtime): add fp32 support to ReduceSum kernel - #604

Open
AMDmoore wants to merge 1 commit into
mainfrom
feat/reduce_sum_support_f32
Open

feat(runtime): add fp32 support to ReduceSum kernel#604
AMDmoore wants to merge 1 commit into
mainfrom
feat/reduce_sum_support_f32

Conversation

@AMDmoore

Copy link
Copy Markdown
Contributor

Summary

  • Add a reduce_sum_f32_kernel (float accumulate + float store) and a HIP_DTYPE_FLOAT32 dispatch branch to hip_reduce_sum.
  • Map HIPDNN_EP_DATATYPE_FLOAT -> HIP_DTYPE_FLOAT32 in wrap_reduce_sum and update its unsupported-dtype message.
  • Update the hip_reduce_sum header doc to list FLOAT32.

Why

Quantized LLMs (e.g. Nemotron INT4-RTN) upcast to fp32 before a sum for numerical stability (Cast(fp16->fp32) -> ... -> ReduceSum), which triggered the runtime error [REAL] wrap_reduce_sum: unsupported data_type=f32(0) and blocked the model. This mirrors the existing reduce_mean_f32_kernel added for the same fp32-upcast pattern, so ReduceSum and ReduceMean now have matching dtype coverage.

Test plan

  • Rebuild custom kernels + runtime and rerun the Nemotron model_benchmark; confirm the unsupported data_type=f32 error is gone.
  • Confirm no regression on existing fp16/i32/i64 ReduceSum paths.

AI assistance

Cursor (Claude) assisted with implementing the fp32 kernel path following the existing ReduceMean fp32 precedent; the change was reviewed for correctness.

Made with Cursor

@github-actions

Copy link
Copy Markdown

Thanks for opening a PR!

This project follows LLVM's incremental-development and AI-tool-use
guidance. See CONTRIBUTING.md
for the project workflow.

Before requesting review, please check that:

  1. The change is focused. Substantial work links the relevant issue
    or design discussion.
  2. The PR documents relevant test results and updates affected
    documentation.
  3. If AI tools provided substantial assistance, the description
    explains what was assisted and how it was validated, and commit
    trailers identify the tool. The contributor has reviewed and
    understands the result.

Reviewers are assigned through
CODEOWNERS where ownership
is configured.

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

L2 Accuracy Results (EP vs CPU)

Model Combined L2 Total Elems Skipped NaN/Inf
conv_test_hybrid 4.8668E-07 64 0
GroupQueryAttention_seq256 25.2366 2621440 0
MatMulNBits_o_seq128 259.906 368640 0
QMoE_seq128 34.957 368640 0

Threshold: 0.01 | Run: 3495 - Commit: ccd14d5

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

MorphiZen EP Performance Results

Model QPS Session (s) 1st Infer (ms) CPU% Mem (MB)
full_model_seq128 7.51 6.36 362 3 1244
GroupQueryAttention_seq128 4427.13 1.7157 10 6 311
matmul_down_seq128 530.08 2.60 70 3 352

EPContext Export Performance

Model QPS Session (s) 1st Infer (ms) CPU% Mem (MB)
full_model_seq128 7.53 45.61 363 3 15590

EPContext Import Performance

Model QPS Session (s) 1st Infer (ms) CPU% Mem (MB)
full_model_seq128 7.52 9.69 362 3 15760

OGA Benchmark Results

Model Warmup Reps Prompt Len Gen Tokens TTFT (ms) TPS Peak Mem (GB) GPU Mem (GB)
gpt-oss-20b-webgpu-int4-rtn-block-32 1 5 128 128 170.8 79.7 1.33 13.54
Llama-3.1-8B-awq-g128-int4-asym-fp16-onnx-dml 1 5 128 128 247.2 40.3 1.22 6.43

OGA Wheel Smoke (Python benchmark_e2e.py)

Model TTFT (ms) TPS
Llama-3.1-8B-awq-g128-int4-asym-fp16-onnx-dml 196 39.5

Run: 3495 - Commit: ccd14d5

@AMDmoore
AMDmoore force-pushed the feat/reduce_sum_support_f32 branch from d9536a2 to ccd14d5 Compare July 31, 2026 11:10
Add a reduce_sum_f32_kernel (float accumulate + float store) and a HIP_DTYPE_FLOAT32 dispatch branch to hip_reduce_sum. Map HIPDNN_EP_DATATYPE_FLOAT -> HIP_DTYPE_FLOAT32 in wrap_reduce_sum, update its unsupported-dtype message, and list FLOAT32 in the header doc.

Quantized LLMs (e.g. Nemotron INT4-RTN) upcast to fp32 before a sum for numerical stability (Cast(fp16->fp32) -> ... -> ReduceSum), which hit the runtime error 'wrap_reduce_sum: unsupported data_type=f32'. This mirrors the existing reduce_mean_f32_kernel added for the same fp32-upcast pattern.

AI assistance: Cursor assisted with implementing the fp32 kernel path following the existing ReduceMean fp32 precedent; the change was reviewed for correctness.

Co-authored-by: Cursor <cursoragent@cursor.com>
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