Expand FLASHATTENTION_DISABLE_DROPOUT to not bring in unneeded headers - #2669
Merged
Conversation
janeyx99
force-pushed
the
fully-yank-dropout
branch
from
June 22, 2026 13:50
be9b2c9 to
0869d1a
Compare
janeyx99
commented
Jun 23, 2026
| // flash_api.cpp will write into this buffer via placement-new of an at::PhiloxCudaState | ||
| // (guarded by FLASHATTENTION_DISABLE_DROPOUT) and the forward kernel (in flash_fwd_kernel.h) | ||
| // will read it back via reinterpret_cast. Size validated by static_assert in flash_api.cpp. | ||
| uint64_t philox_args[4]; |
Contributor
Author
There was a problem hiding this comment.
To explain why this buffer, the PhiloxCudaState struct is 24 bytes, which we round up here for some cushion:
struct PhiloxCudaState {
union Payload { uint64_t val; int64_t* ptr; }; // 8 bytes
Payload seed_; // 8
Payload offset_; // 8
uint32_t offset_intragraph_ = 0; // 4
bool captured_ = false; // 1 (+3 tail padding to keep struct alignment 8)
};
Collaborator
There was a problem hiding this comment.
nit; maybe add an abridged verison in the doc block
janeyx99
force-pushed
the
fully-yank-dropout
branch
from
June 26, 2026 19:42
0869d1a to
bbda511
Compare
janeyx99
marked this pull request as ready for review
June 26, 2026 19:49
janeyx99
commented
Jun 26, 2026
| std::lock_guard<std::mutex> lock(gen->mutex_); | ||
| params.philox_args = gen->philox_cuda_state(counter_offset); | ||
| std::lock_guard<std::mutex> lock(gen.mutex()); | ||
| new (params.philox_args) at::PhiloxCudaState(gen.get<at::CUDAGeneratorImpl>()->philox_cuda_state(counter_offset)); |
Contributor
Author
There was a problem hiding this comment.
Note: this is a placement-new, which is a variation of new where we give new an existing memory address to put the constructed value in. This is why there's no matching delete!
janeyx99
force-pushed
the
fully-yank-dropout
branch
2 times, most recently
from
June 28, 2026 03:34
911f627 to
a5b4358
Compare
|
It will be really good to see it (and #2688 later) merged upstream, since vllm would need it in our stable ABI transition. |
drisspg
reviewed
Jul 1, 2026
janeyx99
force-pushed
the
fully-yank-dropout
branch
from
July 22, 2026 16:41
a5b4358 to
ef0665d
Compare
Summary:
Previously, using the FLASHATTENTION_DISABLE_DROPOUT flag still pulled
in unneed dependencies from ATen for at::Generator and Philox related
headers. This change sets up the codebase so that using the flag will
not pull in these unnecessary headers.
There are two major changes of note:
1. We remove needing an RNG gen in the schema--the Python frontend
always passed in None so this should not be BC breaking to most
users.
2. Instead of referencing the PhiloxState directly, in order to detach
dependencies when dropout is not needed, we introduce an opaque
buffer that will hold the philox state when dropout is desired.
Test Plan:
pytest tests/test_flash_attn.py::test_flash_attn_output -k "113-203-64 and dtype0 and mha"
pytest tests/test_flash_attn.py::test_flash_attn_varlen_output -k "113-203-64 and dtype0 and mha"
g++ -c -O1 -std=c++17 -D_GLIBCXX_USE_CXX11_ABI=1 <torch+cutlass+cuda -I flags> \
csrc/flash_attn/flash_api.cpp -o /tmp/fa.o
nm -C /tmp/fa.o | grep -E 'mha_(fwd|bwd|varlen)\(' | grep -c Generator
returns 0
g++ -E -DFLASHATTENTION_DISABLE_DROPOUT <same -I flags> csrc/flash_attn/flash_api.cpp \
| grep -c 'CUDAGeneratorImpl.h\|philox_unpack.cuh'
also returns 0
Reviewers:
Subscribers:
Tasks:
Tags:
Add trivially copyable assert
Add back gen
janeyx99
force-pushed
the
fully-yank-dropout
branch
from
July 22, 2026 20:00
ef0665d to
509557b
Compare
drisspg
approved these changes
Jul 23, 2026
ussoewwin
added a commit
to ussoewwin/flash-attention
that referenced
this pull request
Aug 8, 2026
ussoewwin
added a commit
to ussoewwin/flash-attention
that referenced
this pull request
Aug 11, 2026
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.
TL;DR: If we expand the disable dropout macro and drop generator support we can enable stable ABI builds for flash, vLLM, and sglang (and other downstream libs). I did quite a bit of recursive GitHub searching which leads me to believe that majority of C++ users are just passing in an null opt for the gen arg anyway. cc @tridao
So we do the two things:
Breaking: Custom RNG generator support removed from the C++ APIs
The raw FA2 forward and backward entry points no longer accept a custom
torch.Generator; the argument must beNone.Passing a
torch.Generatorobject into the raw extension entry points (fwd/varlen_fwd/bwd/varlen_bwd) now raises a pybindTypeError: ... incompatible function argumentsas the argument slot is nowTensor?and only acceptsNone.Passing a
Tensorwill hit:RuntimeError: flash-attn: the RNGgeneratorargument is no longer supported and must be None; dropout (when enabled) uses the default CUDA generator.Workaround: If your use case was to be able to get deterministic behavior, use
torch.manual_seedto control the default generator in Python instead:Test Plan
Everything is run on GPU: H100 (sm_90) with torch
2.10.0+cu129. I ended up building with 12.8 cuz 12.9 causes nans.I added a new test case to enforce the BC break (note below).
Part 1 — confirming nothing regressed with default dropout enabled build
build command:
CUDA_HOME=/usr/local/cuda-12.8 FLASH_ATTN_CUDA_ARCHS=90 pip install -e . --no-build-isolation -vThere are dropout kernels in the binary:
Dense forward+backward across head dims 64 & 128, both dtypes, dropout {0.0, 0.17}, all masking modes (causal/local/alibi/deterministic) — confirms the new opaque-philox plumbing didn't break the default path
Variable-length forward+backward, same configs
GQA head-grouping path with
dropout_p=0.17at d=128.KV-cache + splitkv entry point (
num_splits1 & 0), no dropout — confirm that the schema change is okayPart 2 — dropout=0 tests pass dropout disabled build
build command:
CUDA_HOME=/usr/local/cuda-12.8 FLASH_ATTN_CUDA_ARCHS=90 FLASH_ATTENTION_DISABLE_DROPOUT=TRUE pip install -e . --no-build-isolation -vThe disabled build should drop the dropout (
Is_dropout=true) kernels entirely — confirm none remain in the binary (.sois also 271 MB vs 341 MB for the enabled build).There are no references to Philox and Generator in the binary:
Dense forward+backward at dropout=0 (head dims 64 & 128, both dtypes, all masking modes) — confirms attention is still correct after stripping the ATen RNG headers.
Variable-length forward+backward at dropout=0, same configs.
dropout_p > 0must still be rejected (not silently ignored) in the disabled build.