[PyTorch] Add per-version FlashAttention env vars (NVTE_FLASH_ATTN_V2…#3204
[PyTorch] Add per-version FlashAttention env vars (NVTE_FLASH_ATTN_V2…#3204wdykas wants to merge 1 commit into
Conversation
…/V3/V4) NVTE_FLASH_ATTN enables or disables the whole FlashAttention family, but the choice between FlashAttention 2, 3, and 4 is automatic (package presence and compute capability) with no user override. Some workloads need to pin the FlashAttention generation, e.g. RL training that must produce bitwise-identical logprobs to an inference engine running a specific FlashAttention version: different generations use different tile sizes and online-softmax accumulation orders, so mixed versions between training and inference break batch-invariant / train-inference parity guarantees. Add NVTE_FLASH_ATTN_V2, NVTE_FLASH_ATTN_V3, and NVTE_FLASH_ATTN_V4 (default 1) that disable a specific FlashAttention version even when it is installed, following the existing NVTE_FLASH_ATTN filter pattern. Behavior is unchanged when the variables are unset. Signed-off-by: wdykas <wdykas@nvidia.com>
Greptile SummaryThis PR adds per-version FlashAttention controls for PyTorch attention backend selection. The main changes are:
Confidence Score: 5/5This looks safe to merge after a small hardening cleanup.
transformer_engine/pytorch/attention/dot_product_attention/utils.py Important Files Changed
Reviews (1): Last reviewed commit: "[PyTorch] Add per-version FlashAttention..." | Re-trigger Greptile |
| use_flash_attention_2 = use_flash_attention and int(os.getenv("NVTE_FLASH_ATTN_V2", "1")) | ||
| use_flash_attention_3 = use_flash_attention and int(os.getenv("NVTE_FLASH_ATTN_V3", "1")) | ||
| use_flash_attention_4 = use_flash_attention and int(os.getenv("NVTE_FLASH_ATTN_V4", "1")) |
There was a problem hiding this comment.
Invalid Env Value Crashes Selection
When any new per-version variable is set to a non-integer value such as true, yes, or an empty string, int(os.getenv(...)) raises before backend fallback runs. A single malformed NVTE_FLASH_ATTN_V2, NVTE_FLASH_ATTN_V3, or NVTE_FLASH_ATTN_V4 setting can make get_attention_backend fail instead of selecting another available attention backend.
|
/te-ci pytorch L1 |
set fa version
Description
Please include a brief summary of the changes, relevant motivation and context.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: