Skip to content

fix(hip): unify broadcast and reduction shape contracts - #641

Draft
fhanuman wants to merge 1 commit into
pr/shape-stack-02-matmul-gemmfrom
pr/shape-stack-03-broadcast-reduction
Draft

fix(hip): unify broadcast and reduction shape contracts#641
fhanuman wants to merge 1 commit into
pr/shape-stack-02-matmul-gemmfrom
pr/shape-stack-03-broadcast-reduction

Conversation

@fhanuman

@fhanuman fhanuman commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Unify NumPy broadcast and ONNX reduction result-shape rules across converter destination construction, HIP reification, and static verification.

  • use one right-aligned broadcast rule for elementwise operations and converter destinations;
  • preserve legal zero/unit broadcasting with select(lhs == 1, rhs, lhs) rather than integer maximum;
  • share variadic Max/Min lowering through one pairwise broadcast chain;
  • centralize axes, keepdims, and noop_with_empty_axes handling across all six reducers, including ReduceL2;
  • use one output-to-input dimension map so keepdims = 0 preserves the correct surviving dimensions;
  • preserve the validated outs fallback when reduction axes are only known at runtime.

Stack

This is PR 5 of 12 and depends on PR 4:

1. Constant carrier/externalization
2. Shape-rule foundation
3. Reshape provenance
4. MatMul/Gemm
5. Broadcast/Reduction ← this PR
6. Loop carriers
7. Payload/Readback
8. Conv/Pool
9. Gather/Tensor
10. Attention/Normalization
11. Explicit contract enforcement
12. Refinement hardening

AI assistance

AI tools assisted with the shape-rule consolidation and stack reconstruction. The broadcast and reduction layer was checked with the authoritative local build and focused rank-zero, keepdims, noop, converter, reification, and verifier tests.

Made with Cursor

@github-actions

github-actions Bot commented Aug 3, 2026

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 added the large-pr Soft size threshold (>500 LOC or >10 files). Reviewer signal, not a block. label Aug 3, 2026
@github-actions

github-actions Bot commented Aug 3, 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: 3952 - Commit: 354c3f0

@github-actions

github-actions Bot commented Aug 3, 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.26 361 3 1243
GroupQueryAttention_seq128 4359.05 1.75973 12 6 313
matmul_down_seq128 523.29 2.41 71 3 354

EPContext Export Performance

Model QPS Session (s) 1st Infer (ms) CPU% Mem (MB)
full_model_seq128 7.59 46.67 359 3 15589

EPContext Import Performance

Model QPS Session (s) 1st Infer (ms) CPU% Mem (MB)
full_model_seq128 failed - - - -

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 182.0 79.4 1.33 13.53
Llama-3.1-8B-awq-g128-int4-asym-fp16-onnx-dml 1 5 128 128 335.5 40.1 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 208 39.6

Run: 3952 - Commit: 354c3f0

@fhanuman
fhanuman force-pushed the pr/shape-stack-03-broadcast-reduction branch from 8f61689 to 0fb9bd6 Compare August 5, 2026 21:56
@fhanuman
fhanuman force-pushed the pr/shape-stack-03-broadcast-reduction branch from 0fb9bd6 to c09cd39 Compare August 6, 2026 21:00
@fhanuman
fhanuman force-pushed the pr/shape-stack-03-broadcast-reduction branch from c09cd39 to ce462bb Compare August 7, 2026 19:51
@fhanuman
fhanuman force-pushed the pr/shape-stack-03-broadcast-reduction branch from ce462bb to f57da78 Compare August 7, 2026 20:25
@fhanuman
fhanuman force-pushed the pr/shape-stack-03-broadcast-reduction branch from f57da78 to b71eb35 Compare August 10, 2026 21:59
@fhanuman
fhanuman force-pushed the pr/shape-stack-03-broadcast-reduction branch 2 times, most recently from b3a8260 to 6146cf0 Compare August 10, 2026 23:33
@fhanuman
fhanuman force-pushed the pr/shape-stack-03-broadcast-reduction branch from 6146cf0 to ba534eb Compare August 11, 2026 00:42
Share NumPy broadcast and reduction dimension rules across converter destinations, dialect reification, and generated verification while rejecting unsupported runtime and non-contiguous reduction axes before lowering.

Co-Authored-By: GPT-5.6 Sol <noreply@openai.com>
Made-with: Cursor
@fhanuman
fhanuman force-pushed the pr/shape-stack-03-broadcast-reduction branch from ba534eb to 354c3f0 Compare August 11, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

large-pr Soft size threshold (>500 LOC or >10 files). Reviewer signal, not a block.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant