Skip to content

[JIT] [Perf] Avoid allocating dummy dispatch tensors for inference collectives - #7217

Closed
xytpai wants to merge 1 commit into
ROCm:mainfrom
xytpai:perf/reuse-inference-dispatch-anchor-1030
Closed

xytpai wants to merge 1 commit into
ROCm:mainfrom
xytpai:perf/reuse-inference-dispatch-anchor-1030

Conversation

@xytpai

@xytpai xytpai commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Summary

For non-Tensor-first custom operators, keep the existing leading Tensor dummy schema but use an existing ordinary inference Tensor as the dispatch anchor when safe, instead of allocating a fresh dummy on every call.

The target is scalar-handle-first collective wrappers such as all_reduce_gfx1250 and fused all-reduce/RMSNorm. Tensor-first operators are unchanged.

Compatibility boundaries

  • No registered schema change, no native ABI/kernel changes and no tensor/address cache.
  • Select a required, exactly Tensor-annotated argument once from the signature (including keyword-only inputs); support positional and keyword calls.
  • Reuse only if this decorator registered the implementation, which ignores dummy. A pre-existing registration still allocates the legacy dummy.
  • Runtime reuse requires exact torch.Tensor, requires_grad=False, and the configured CPU/CUDA device type. Subclasses/Parameters, grad tensors, absent/invalid arguments, device mismatch, non-simple device settings, optional-only signatures and scalar-returning operators retain the original path.
  • Fake/AOT/compile/graph checks and legacy raw torch.ops schema calls included.

Validation

Based on main 55ed07e9427d045d63841c412f088dc8f16c85de; core and gfx1250 custom-allreduce native modules rebuilt in an isolated JIT directory for this main.

  • 37 passed: CPU/GPU inference dispatch, zero-sized/scalar inputs, kwargs/keyword-only calls, old raw schema, pre-existing registration, errors, gradient/subclass fallback, FakeTensorMode, fullgraph capture, AOT-eager, original in-place semantics and changed-input HIP graph replay.
  • GPU-hidden CPU run: 25 passed, 12 skipped. Black/Ruff and diff checks pass.
  • TP2 + TP4, M={1,12,256,2517}, N=6144, BF16 all-reduce, fused RMSNorm and fused per-token FP8 quant: 72 rank cases. Every rank has bitwise old/new outputs, graph replay equality and exactly one fewer torch.empty call.
  • All-reduce checked against an independent distributed sum; residual/RMSNorm/FP8-dequantized outputs against explicit FP32 formulas, with quantization-appropriate tolerances.
  • Direct torch.func.functionalize rejects the pre-existing in-place custom-op schema in this torch version. The unchanged-wrapper control rejects identically; no new support is claimed. Pure functionalization and AOT functionalization of declared mutation are separately tested.

An initial latest-main run used an older native .so and failed on a missing IPC registration symbol; it was not accepted as a result. Both native modules were rebuilt, then TP4/TP2 rerun. A TP2 fixed-port collision was retried using automatic rendezvous; no unrelated service was stopped.

Performance: small eager collective calls, not transport bandwidth

gfx1250 f01, TP4 independent process repeat, same real collective kernels/inputs. 300 warmup calls per arm, then 31 shuffled paired samples of 100 eager calls each. Synchronize and distributed barrier before each sample; completion is the maximum rank time for that sample. No profiler inside timing.

Rows Operation Old dummy allocation (us) Input reuse (us) Paired median saving (us)
1 ar 15.105 14.235 0.884
1 rms 35.516 34.637 0.850
1 quant 55.467 54.959 0.582
12 ar 15.417 14.580 0.867
12 rms 35.771 34.949 0.923
12 quant 55.420 54.767 0.658

Each inference call saves one dummy allocation. In this repeated small-message run the end-to-end saving is 0.58–0.92 us/call; this is host-dispatch overhead, not a faster GPU reduction.

The earlier short-warmup TP4 M1 RMSNorm run was noisy/regressed when comparing independent medians (34.45 -> 42.94 us). All raw samples are retained; the repeat above increases warmup and reports paired samples rather than discarding the negative run. Large M2517 collectives were essentially unchanged in completion time, with small positive/negative noise despite lower CPU submission time. No whole-model or large-message bandwidth gain is claimed.

Artifacts on f01: ~/bench/m3_dispatch_anchor_20261030/ (verified_collectives.json, repeat_collectives_summary.json, per-rank raw samples and logs).

@xytpai
xytpai requested a review from a team October 30, 2026 11:16
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the gfx1201 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7217 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

@github-actions github-actions Bot changed the title [Perf] Avoid allocating dummy dispatch tensors for inference collectives [JIT] [Perf] Avoid allocating dummy dispatch tensors for inference collectives Oct 30, 2026
@github-actions github-actions Bot added the JIT label Oct 30, 2026
@aiter-bot

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 3e8ac60b7490 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. What changes in dependency, cache or compilation behavior, and how did you verify both a clean build and an existing-cache path?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_torch_guard_dispatch_anchor.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

@xytpai

xytpai commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Model ABBA: combined inference-anchor + grouped-GEMM stream changes

Both arms include the prior MoE dispatch change (#7210), existing Gluon layout cache (#7090), ATOM #2761 and the standalone-cache fix (ROCm/ATOM#2858). The candidate adds #7217 + #7219 together. This is a combination test, not attribution to either PR separately.

M3 MXFP4, TP4/gfx1250, Simple, FP8 KV, EAGLE3; fixed synthetic acceptance 0.5933. Performance only, not generated-text accuracy. Same recorded prompt hashes across all four fresh processes. Source imports checked in all worker processes.

Per process: 20 measured short requests, 20 measured long-prefix requests, six measured C2 rounds. cProfile diagnostics run after all timing samples and are excluded. No PyTorch profiler in timing.

Order Arm Short median ms Long-prefix median ms C2 median output tokens/s
1 baseline_a 83.550 103.528 479.37
2 combined_b 88.746 103.825 475.12
3 combined_c 86.588 98.585 491.74
4 baseline_d 89.866 104.429 487.89

Descriptive candidate-vs-baseline comparison using the mean of per-process medians:

  • Short latency: +1.11%.
  • Long-prefix latency: -2.67%.
  • C2 throughput: -0.04%.

This four-process experiment does not establish a robust end-to-end speedup. The raw order/spread and any regressions above are retained. Do not sum the independent operator microbenchmark savings or interpret this combination run as per-PR throughput evidence.

Artifacts: f01 ~/bench/m3_hot_combined_20261030/ (source manifest, all timings/prompt hashes, import provenance and post-timing host profiles).

@zufayu
zufayu requested a review from amd-ruitang3 November 2, 2026 01:22
XiaobingSuper added a commit that referenced this pull request Nov 2, 2026
XiaobingSuper added a commit that referenced this pull request Nov 2, 2026
lirui927 pushed a commit that referenced this pull request Nov 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

No activity for 15 days, so this is now labelled stale. A push or a comment clears it; keep-open exempts it. Nothing is closed automatically.

@github-actions github-actions Bot added the stale The PR hasn't been updated in 2 weeks label Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

JIT stale The PR hasn't been updated in 2 weeks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants