flash-attn-training

Ports fused flash-attention training ops to GGML-based model trainers with parity and VRAM gates.

151|22|Updated Apr 19, 2026
One-click install
npx skills add https://github.com/scragnog/HOT-Step-CPP --skill flash-attn-training-scragnog
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: flash-attn-training
Source: https://github.com/scragnog/HOT-Step-CPP/tree/main/.claude/skills/flash-attn-training
Command: npx skills add https://github.com/scragnog/HOT-Step-CPP --skill flash-attn-training-scragnog

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? GGML's autodiff had no attention backward, forcing every trainer to retain an O(S²) softmax per layer that capped training crop lengths and VRAM headroom. This Skill documents the custom fused flash-attention forward/backward ops and the exact contract for safely adopting them in each trainer. ## Core Features & Use Cases - Adoption contract: Six non-negotiable requirements per trainer port, including byte-identical exact mode, a supports_op probe, CPU f32 parity rungs, and measured drift classes. - Per-trainer porting checklist: Concrete file lists and measured results for the AS1.5 LM, MM3 LM, and MM3 DiT trainers, including crop-ceiling and step-time numbers. - Measurement discipline and trap list: Nineteen documented pitfalls (DLL locks, packed-output alignment, TF32 lane maps, crop-max pinning) plus a table of validated RTX 5090 measurements. - Use Case: When adding --attn flash to a new ace-train subcommand or debugging why flash mode is slower or uses more VRAM than expected, follow the checklist and trap list to avoid repeating measured mistakes. ## Quick Start Ask the assistant to port flash attention mode to the MM3 DiT trainer following the adoption contract and per-trainer checklist in this skill.

Frequently Asked Questions about flash-attn-training

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add flash attention to a GGML model trainer?

Add a sibling attention function returning the same shape as the manual chain, gate it behind a per-trainer flag defaulting to exact, add a supports_op probe at real shapes, a CPU f32 parity rung, a VRAM model branch, and a drift A/B measurement. The skill provides the full checklist per trainer.

Why is flash attention slower than exact attention at equal crop?

Paired measurements on the DiT show flash is about 8.5% slower per token at equal graph shape; its win is the larger crop it affords, not per-token speed. The deficit is concentrated in the cross-attention backward kernel, which recomputes shared tiles.

Does flash attention training work with GQA and causal masks?

Yes, the fused ops accept any additive F16 mask, GQA with Nkv less than Nh at batch 1, cross-attention with S_kv different from S, and non-contiguous q/k/v views. Causal masking uses one triangular minus-INF mask and skips fully masked tiles.

Why does flash mode silently fall back to CPU in ggml?

The backend scheduler registers CPU alongside CUDA, so an unsupported op is silently split onto the CPU instead of erroring. The contract requires a supports_op probe at the run's real shapes that aborts with a named error when the op is unsupported.

What precision does flash attention training use on Ampere GPUs?

The default precision resolves to TF32 on sm_80 and newer because op_params zero-init maps to GGML_PREC_DEFAULT; GGML_PREC_F32 selects the scalar f32 kernels. Run logs must record the resolved precision, not just the requested mode.

When should I not enable flash attention training?

Keep it off when a trainer uses a frozen KV prefix (the fused kernel cannot take the rectangular mask), when short crops already fit in memory since flash shows no benefit there, and until ear validation confirms adapter quality.