[feat]: fp8 PV mode for the FA4-FP4 attention path - #1654
Open
SolitaryThinker wants to merge 1 commit into
Open
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Contributor
Merge Protections🔴 1 of 1 protections blocking · waiting on 👀 reviews and 🤖 CI
🔴 PR merge requirementsWaiting for
This rule is failing.
|
Adds an opt-in fa4_pv_mode knob (bf16 default / fp8) to the FA4-FP4 attention path on datacenter Blackwell: * fastvideo::fa4_v_to_fp8 custom op: unscaled e4m3 cast of V behind a torch.compile-opaque boundary (a naive in-forward .to() graph-breaks), register_fake mirroring .to()'s preserve_format layout. The kernel's plain-fp8 PV contract needs no mSFV scale factors and no v_descale (implicit dequant scale 1.0) and keeps the output BF16. * fa4_pv_mode extra_impl_args knob consumed by both FlashAttentionImpl._forward_nvfp4 and AttnQatInferImpl._forward_fa4_fp4, validated at construction (fail fast on typos). Default bf16 keeps behavior byte-identical. * attn_qat_infer_receipt() now derives pv_mode from the configured knob instead of a literal, plus a once-per-process log of the V dtype actually fed to the kernel on the first FA4 forward. * _flash_attn_cute_fp4_forward fake fixed to always report BF16 output (the block-scaled kernel never follows V's dtype). * CPU regressions: opcheck on the new op (incl. non-contiguous strides), fullgraph trace of the fp8 path with mocked kernels, knob-typo validation for both consumers, derived-receipt coverage. * docs: fp8 PV documented as opt-in [target] pending an end-to-end compiled benchmark and a quality gate.
SolitaryThinker
force-pushed
the
swe-fa4-fp8-pv
branch
from
July 28, 2026 03:14
73fbbe1 to
95d1735
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The FA4-FP4 attention path always keeps V in BF16 — there is no supported way to select the PV precision. Kernel-level measurements show an fp8 (e4m3) V can be faster at large shapes, but a naive in-forward
.to(torch.float8_e4m3fn)cast graph-breaks undertorch.compile, and the resolution receipt hardcodedpv_mode=bf16as a string literal (it would silently misreport the moment fp8 V flowed).What this changes
fastvideo::fa4_v_to_fp8custom op: the elementwise e4m3 cast behind a registered-op boundary — one opaque graph node, so fullgraph compilation keeps working. The kernel contract was verified against the FP4 kernel source before shipping: with block-scaled Q/K, plain fp8 V is consumed directly (no scale-factor tensor, no dequant scale, standard layout).fa4_pv_modeknob ("bf16"default /"fp8") on the attention impl options, validated at construction, plumbed to both FA4-FP4 consumers. TheFASTVIDEO_FA4_PV_MODEenv var is the user-reachable path (model code constructs attention with fixed literals); explicit kwargs win over the environment.pv_modein the resolution receipt now reports the configured mode (env-aware from the first line), and the actually-observed V dtype is logged once at the first forward — receipts describe runtime state, not intent.Status: [target] — confirmed by the end-to-end compiled benchmark
fp8-PV is an end-to-end wash:
The kernel-level +6.9% does not translate end-to-end (attention is a fraction of the step; the unscaled V cast adds work), and fp8-PV changes numerics (MS-SSIM 0.8958 @720p / 0.7442 @1080p vs bf16-PV) — so it ships opt-in, default-off. All six benchmark cells completed rc=0 with 7 graph breaks each (equal to the bf16 control); receipts confirmed live (
pv_mode=fp8(e4m3)on fp8 cells). W&B runs:hvo1y96a,wo3ovz5a,tnaty1wr,f5jkt3t4,kmlwcfx8,yp114bvh.Test evidence
torch.library.opcheckon the new op (CPU kernel in-test; contiguous and transposed inputs; forward-only suites) — fake-vs-real consistency including strides.fullgraph=Truecompiles with zero graph breaks.Blast radius
Shared-forward attention path — inference (both FA4-FP4 consumers) and training only via the validation-time
ATTN_QAT_INFERswap. With the default knob the change is behavior-neutral (the only functional delta is the corrected fake output dtype, which matches what the real kernel already did). Withfa4_pv_mode=fp8: quality-changing until gated — hence [target] and default-off.