Skip to content

Investigate gfx1201 (RDNA4) training: Flash Linear Attention + Gemma4-31B QLoRA OOM #100

Description

@ulises-c

Currently broken on stable release — investigate nightly releases or other workarounds for Flash Linear Attention (FLA) on gfx1201 (RDNA4 / AMD R9700).

Status: investigated (brainstorm). Findings summarized below; full detail in the comments. Nothing committed to the tree yet.

TL;DR — two kernel stacks, two blockers

The original FLA question turned out to be one of two distinct gfx1201 problems, split by which model we're training:

Qwen targets (Qwen3.6-27B teacher · Qwen3.5-0.8B-Base classifier) Gemma4-31B teacher
Attention arch hybrid Mamba + attention (linear-attention layers) softmax (sliding-window + global)
Needs FLA? YES NO (Makefile:342)
Real blocker FLA Triton kernel deadlock OOM at load (CPU RAM)

1. FLA blocker (the Qwen targets)

flash-linear-attention==0.5.0 JIT-deadlocks at training step 0 on gfx1201. Root cause: Triton 3.6.0's tritonamdgpu-pipeline pass has a use-after-free when num_stages>=2 (gfx12xx isn't in Triton's verified target list). Same bug that crashes SageAttention.

  • Fix: make patch-fla-rocm (rewrites num_stages→1, num_warps→4) — confirmed working at seq 768.
  • Nightly status: not fixed upstream in any nightly; every fix in the wild is a downstream num_stages=1 workaround.
  • Alternatives: TRITON_DISABLE_AUTOTUNING=1 (cheapest, try first) · pin Triton 3.5.1 (avoids the 3.6.0 regression at the source) · TORCH_ROCM_AOTRITON_ENABLE_EXPERIMENTAL=1.

2. Gemma4-31B SFT blocker — NOT FLA, it's load-time CPU RAM

Gemma4 uses softmax attention (no FLA). The actual wall was OOM during model load: from_pretrained(load_in_4bit=True) stages the full ~62 GB BF16 model in CPU RAM before NF4 quantization (a bitsandbytes detail; low_cpu_mem_usage/offload don't prevent it). The 62 GB R9700 box thrashes into zram (~20 h just to load).

  • Fix: load a pre-quantized bnb checkpointunsloth/gemma-4-31B-it-unsloth-bnb-4bit (already NF4, ~19 GB; embedded quant config byte-matches our pipeline; it's the instruction-tuned variant). Drops load RAM from ~62 GB to ~16 GB.

The one gate common to both: bitsandbytes 4-bit runtime on gfx1201

Officially listed in bnb's RDNA arch table; verify with make test-gpu-stack (steps 4/5). May need a source build: cmake -DCOMPUTE_BACKEND=hip -DBNB_ROCM_ARCH="gfx1201".

Hardware estimate — Gemma4-31B QLoRA (seq 1280, batch 1×16, grad-ckpt on, eval off)

Resource Pre-quant checkpoint (recommended) Naive load_in_4bit from BF16
GPU VRAM (peak, train) ~22–27 GB ~22–27 GB
System RAM (peak, load) ~8–16 GB ~62–70 GB ← the blocker
Download ~19 GB ~62 GB
Disk working set ~30 GB ~75 GB

Minimum viable: GPU ≥ 32 GB (R9700 / 5090) · 24 GB (3090) marginal · 20 GB (RTX 4000 Ada) won't fit. System RAM ~16 GB with the pre-quant checkpoint. Disk ~30 GB. Eval stays disabled (TRAIN_EVAL_STRATEGY=no) — its 256K-vocab logits.float() copy adds an ~8.6 GB spike that OOMs even 32 GB.

Corrections logged during the investigation

  • HSA_OVERRIDE_GFX_VERSION: our hang came from 11.0.0 (the RDNA3 value). The correct gfx1201 value is 12.0.1 — but on ROCm 7.2 no override should be needed at all.
  • expandable_segments:True: HANDOFF.md (05-25) says "unsupported on gfx1201"; the PR feat(stage2-sft): format fix, loaders, configs, DPO pair builder #79 session (05-26) re-added it as a working fix (releases freed BF16 shards from VRAM). The Makefile is correct; HANDOFF.md Issue 2 is stale.

Detailed notes (comments below)

  1. Deep dive — FLA vs FA2 on gfx1201 (root cause, nightly status, reference map)
  2. AMD Vision Mamba — hipify path validates the build mechanism, CDNA-only
  3. Brainstorm — scope + untried FLA levers (from PR feat(stage2-sft): format fix, loaders, configs, DPO pair builder #79: autotuning, Triton 3.5.1, AOTriton experimental)
  4. The real Gemma4-31B blocker — CPU-RAM staging at load
  5. Pre-quantized bnb candidate + hardware estimate

Open / next

  • Confirm bnb 4-bit runtime on gfx1201 (make test-gpu-stack; source build if needed) — gates both paths.
  • Spike TRITON_DISABLE_AUTOTUNING=1, then Triton 3.5.1, as cleaner FLA fixes than the per-uv sync patch.
  • Validate Gemma4-31B SFT end-to-end on the R9700 via the pre-quant checkpoint (CUDA-validated only so far).

Refs: PR #79 · apollo-mg RDNA4 gfx1201 gists · scripts/patch_fla_rocm.sh · docs/GPU_SUPPORT.md · HANDOFF.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentationexperiment

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions