Skip to content

[FlyDSL] fix(flydsl): stabilize GDN prepare triangular solve - #4952

Merged
valarLip merged 1 commit into
ROCm:mainfrom
junna2016:xjn_fix_flydsl_k14
Aug 25, 2026
Merged

valarLip merged 1 commit into
ROCm:mainfrom
junna2016:xjn_fix_flydsl_k14

Conversation

@junna2016

Copy link
Copy Markdown
Contributor

Motivation

The FlyDSL fused GDN prefill prepare kernel introduced in ROCm/aiter#4598 can become numerically unstable on production Qwen3.5 inputs.

The original diagonal-block inversion repeatedly converted intermediate results from FP32 to BF16. For inputs with highly correlated keys, slow gate decay, and beta values close to one, the accumulated rounding error grows rapidly and produces severely inaccurate w_bar and u_bar results. Downstream GDN stages can consequently produce NaNs.

This PR stabilizes the triangular solve while preserving the existing kernel interface and avoiding observable end-to-end performance regression.

Technical Details

  • Replace the BF16-rounded diagonal-block inverse with an FP32 forward-substitution solve.
  • Keep intermediate inverse values in FP32 throughout the solve.
  • Use wave-level register communication for the 16×16 triangular solve.
  • Preserve the existing BF16 MFMA implementation for the remaining matrix operations.
  • Preserve the public API, supported shapes, output layouts, and dispatch behavior.
  • Add a numerical regression case representing production Qwen3.5 inputs:
    • repeated normalized keys;
    • slow gate decay (g = -1e-3);
    • beta close to one (beta = 0.835).
  • Compare the FlyDSL output against the existing Triton implementation.

The change is limited to the FlyDSL GDN prefill prepare kernel and does not affect other GDN backends.

Test Plan

  • Run the new repeated-key numerical stress test against the Triton reference.
  • Run the existing GDN prepare correctness and validation tests.
  • Validate the fix using captured Qwen3.5-4B layer-0 inputs.
  • Run Qwen3.5-4B end-to-end inference with 2K and 8K prompts.
  • Compare kernel latency before and after the fix on an AMD Instinct MI308X GPU.
  • Run Ruff and Black checks on the modified Python files.

Single-kernel benchmark configuration:

  • GPU: AMD Instinct MI308X (gfx942)
  • Shape: B=1, T=2048, Hg=16, H=32, K=128, V=128
  • Chunk size: BT=64
  • Input dtype: BF16
  • Gate/beta dtype: FP32
  • Warmup: 20 iterations
  • Measurement: 100 iterations using GPU events

Test Result

Single-operator accuracy

The following results use captured Qwen3.5-4B layer-0 inputs and compare the FlyDSL fused prepare kernel with the Triton reference.

Output Metric Before After
g_cumsum max absolute error 0 0
w_bar max absolute error 3391.9995 0.0089493
w_bar relative L2 error 1372.4407 0.0095596
w_bar cosine similarity 0.0010283 0.9999542
u_bar max absolute error 8575.9990 0.0451660
u_bar relative L2 error 291.7593 0.0024756
u_bar cosine similarity 0.0030643 0.9999969
Downstream output finite values No, contains NaNs Yes

The fix removes the numerical explosion and downstream NaNs while closely matching the Triton reference.

Single-kernel performance

Implementation Mean latency
Original BF16 inverse 100.702 µs
FP32 stable inverse 106.222 µs

The stable solve adds approximately 5.5% latency to the isolated gdn_prepare_kernel. This kernel-level difference did not produce an observable end-to-end TTFT regression.

Model-level validation

Qwen3.5-4B inference was compared against the existing hybrid GDN implementation.

Input length Output comparison
2K First 62 of 64 tokens identical; 96.875% token-position agreement
8K 64 of 64 output tokens identical

TTFT sanity measurements:

Input length Hybrid baseline Fixed FlyDSL Difference
2K 125.43 ms 122.79 ms -2.1%
8K 586.26 ms 580.79 ms -0.9%

These model-level measurements confirm that the accuracy fix introduces no observable end-to-end performance regression. The small TTFT differences are within normal measurement variance.

All targeted correctness tests, adapter tests, Ruff checks, and Black checks passed.

Submission Checklist

@junna2016
junna2016 requested a review from a team August 24, 2026 03:18
@github-actions github-actions Bot changed the title fix(flydsl): stabilize GDN prepare triangular solve [FlyDSL] fix(flydsl): stabilize GDN prepare triangular solve Aug 24, 2026
@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; main branch always runs both MI35X and MI300X
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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 4952 --add-label <label>

PR title tags:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf] and op tags like [MLA] are left untouched. Add the no-auto-title label to opt this PR out of title tagging.

@valarLip
valarLip requested a review from yiijin August 24, 2026 03:28
@junna2016
junna2016 force-pushed the xjn_fix_flydsl_k14 branch 2 times, most recently from 7dbca50 to 94353fd Compare August 24, 2026 06:01
@huizzhan
huizzhan self-requested a review August 24, 2026 07:10
@valarLip
valarLip merged commit 987203b into ROCm:main Aug 25, 2026
54 checks passed
huizzhan added a commit that referenced this pull request Aug 25, 2026
The prepare kernel itself reached mainline through #4598 and was
stabilized by #4952, so this branch keeps only the test coverage those
PRs did not carry over: the standalone unit tests and the end-to-end
use_prepare_flydsl cases.

Co-authored-by: Cursor <[email protected]>
apinge pushed a commit to apinge/aiter that referenced this pull request Oct 22, 2026
apinge added a commit to apinge/aiter that referenced this pull request Oct 22, 2026
Keep the FP32 MFMA diagonal inverse from upstream ROCm#4952. Preserve merge residuals with two BF16 components per FP32 operand and retain the correlated-key regression without relaxing its tolerance.

(cherry picked from commit 8e3d2d1d24cc0931b5c62d24da0e5aa277f6b15b)
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.

2 participants