Skip to content

Add FA4 fp8 backend to low precision attention api#3947

Draft
howardzhang-cv wants to merge 18 commits intogh/howardzhang-cv/22/basefrom
gh/howardzhang-cv/22/head
Draft

Add FA4 fp8 backend to low precision attention api#3947
howardzhang-cv wants to merge 18 commits intogh/howardzhang-cv/22/basefrom
gh/howardzhang-cv/22/head

Conversation

@howardzhang-cv
Copy link
Contributor

@howardzhang-cv howardzhang-cv commented Feb 25, 2026

Stack from ghstack (oldest at bottom):

Summary

  • Added RoPE fusion compile path for FA4 FP8 low-precision attention (fuse_rope=True), mirroring the FA3 RoPE fusion design
  • New elementary block: fp8_fa4_rope_sdpa — fused RoPE + FP8 quantization + low-precision SDPA using the FA4 backend
  • FA4-specific custom op registration and compile_with_fp8_fusion entry point, reusing the shared FX graph fusion infrastructure (fusion_utils.py, custom_ops.py)
  • Reuses shared Triton quantization kernels and RoPE fusion pass — no new kernels needed, only FA4-specific wiring
  • FA4 supports both Hopper (SM 9.x) and Blackwell (SM 10.x) hardware
  • Added RoPE SDPA numerical accuracy tests and fuse_rope parametrization for the FA4 backend

New Files

  • fp8_fa4/fusion_pass.py: FA4-specific custom op registration, rope_sdpa_fusion_pass, and compile_with_fp8_fusion entry point

Modified Files

  • fp8_fa4/attention.py: Added fp8_fa4_rope_sdpa elementary block
  • fp8_fa4/init.py: Added fp8_fa4_rope_sdpa export
  • fp8_fa4/setup.py: Replaced compile placeholder with real compile_with_fp8_fusion
  • test_fp8_attention.py: Wired up rope_sdpa_fn=fp8_fa4_rope_sdpa in FA4 backend config

Test Plan

python -m pytest test/prototype/attention/test_fp8_attention.py -v

Example Usage

  from torchao.prototype.attention import (
      AttentionBackend,
      LowPrecisionAttentionConfig,
      apply_low_precision_attention,
  )

  model = MyModel()

  # Compile path with RoPE fusion using FA4
  config = LowPrecisionAttentionConfig(
      backend=AttentionBackend.FP8_FA4,
      fuse_rope=True,
  )
  model = apply_low_precision_attention(model, config)

  # Flash activation is handled internally by the wrapper
  output = model(inputs)

Results

Single-Layer Results

Results directly comparing FA4 SDPA versus FA4 fp8 SDPA (including quantization time):
image

Llama3 Model Results

Results comparing Llama3 model with FA4 SDPA versus Llama3 using the FA4 fp8 wrapper. Uses RoPE fusion.
Perplexity: 6.19 -> 6.24
image

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Feb 25, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/3947

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures, 1 Unrelated Failure

As of commit 97eb634 with merge base 5ebd10d (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 25, 2026
@howardzhang-cv howardzhang-cv marked this pull request as draft February 25, 2026 04:30
@howardzhang-cv howardzhang-cv added the topic: new feature Use this tag if this PR adds a new feature label Feb 25, 2026
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 25, 2026
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 25, 2026
[ghstack-poisoned]
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 25, 2026
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 26, 2026
[ghstack-poisoned]
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 27, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: e19aa27
Pull-Request: pytorch#3947
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 28, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: e19aa27
Pull-Request: pytorch#3947
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Feb 28, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: e19aa27
Pull-Request: pytorch#3947
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Feb 28, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: ae76df9
Pull-Request: #3947
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Feb 28, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: c9df159
Pull-Request: #3947
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Feb 28, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: d2d46d6
Pull-Request: #3947
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 2, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: d2d46d6
Pull-Request: pytorch#3947
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Mar 2, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: 3ac9da1
Pull-Request: #3947
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Mar 3, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: 2e69d43
Pull-Request: #3947
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 3, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: 2e69d43
Pull-Request: pytorch#3947
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Mar 3, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: 843d1d7
Pull-Request: #3947
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 3, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: 2e69d43
Pull-Request: pytorch#3947
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 5, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: 2e69d43
Pull-Request: pytorch#3947
howardzhang-cv added a commit to howardzhang-cv/ao that referenced this pull request Mar 5, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: 2e69d43
Pull-Request: pytorch#3947
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Mar 5, 2026
Adds the compile path (fuse_rope=True) for the FA4 backend, mirroring
the FA3 fusion pass structure via the shared custom op and fusion pass
factories.

Key additions:
- fp8_fa4/fusion_pass.py: FA4-specific custom ops and compile helper
- fp8_fa4_rope_sdpa entry point in attention.py
- Replace placeholder compile_fn with real fusion pass in setup.py
- Wire up FA4 rope_sdpa_fn in test backend config

ghstack-source-id: db41738
Pull-Request: #3947
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Mar 6, 2026
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Mar 6, 2026
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Mar 6, 2026
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Mar 7, 2026
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
howardzhang-cv added a commit that referenced this pull request Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. topic: new feature Use this tag if this PR adds a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant