-
Notifications
You must be signed in to change notification settings - Fork 103
fix fleet fa version dispatch #1396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -730,11 +730,12 @@ def cp_flashmask_allgatherkv_balance_forward( | |||||||||||||||||||||||||||||||||||||||||
| deterministic = paddle.get_flags(["FLAGS_cudnn_deterministic"])[ | ||||||||||||||||||||||||||||||||||||||||||
| "FLAGS_cudnn_deterministic" | ||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||
| if "block_mask" in inspect.signature(flashmask_attention).parameters: | ||||||||||||||||||||||||||||||||||||||||||
| if deterministic and query.shape[-1] > 128: | ||||||||||||||||||||||||||||||||||||||||||
| if fa_version == 3: | ||||||||||||||||||||||||||||||||||||||||||
| if "block_mask" in inspect.signature(flashmask_attention).parameters: | ||||||||||||||||||||||||||||||||||||||||||
| if deterministic and query.shape[-1] > 128: | ||||||||||||||||||||||||||||||||||||||||||
| fa_version = 2 | ||||||||||||||||||||||||||||||||||||||||||
| elif deterministic: | ||||||||||||||||||||||||||||||||||||||||||
| fa_version = 2 | ||||||||||||||||||||||||||||||||||||||||||
| elif deterministic: | ||||||||||||||||||||||||||||||||||||||||||
| fa_version = 2 | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if fa_version == 4 and _flash_mask_available: | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+733
to
740
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处应该直接报错,提醒用户H卡上不要指定使用FA4
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以,直接报错也能解决这里的问题,而且语义更明确:用户显式指定 if fa_version == 4 and not _flash_mask_available:
raise NotImplementedError(
"FA4 FlashMask requires cute backend; do not set FLAGS_flash_attn_version=4 on H-card/current environment."
)如果采用这个方案,后面 |
||||||||||||||||||||||||||||||||||||||||||
| output, log_sum_exp = _flash_attn_fwd( | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -61,21 +61,22 @@ def _get_fa_version(hdim): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "xpu" in paddle.get_device(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Xiangrui: For deterministic, NOT support for hdim > 128 currently. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "block_mask" in inspect.signature(flashmask_attention).parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| paddle.get_flags(["FLAGS_cudnn_deterministic"])[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "FLAGS_cudnn_deterministic" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and hdim > 128 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif paddle.get_flags(["FLAGS_cudnn_deterministic"])[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "FLAGS_cudnn_deterministic" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fa_version = paddle.base.framework.get_flags(["FLAGS_flash_attn_version"])[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "FLAGS_flash_attn_version" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if fa_version == 3: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Bug 这里只在原始 在未安装/不支持 cute FlashMask 且用户设置 建议修复方式:先把 flag 解析成实际可用版本,再对有效 v3 套 deterministic 降级,例如: if fa_version == 4 and not _flash_mask_available:
logger.warning(...)
fa_version = 3
if fa_version == 3 and deterministic_fallback_needed:
return 2
return fa_version |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "block_mask" in inspect.signature(flashmask_attention).parameters: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| paddle.get_flags(["FLAGS_cudnn_deterministic"])[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "FLAGS_cudnn_deterministic" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| and hdim > 128 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif paddle.get_flags(["FLAGS_cudnn_deterministic"])[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "FLAGS_cudnn_deterministic" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Fall back to version 3 if flash_mask is not available | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if fa_version == 4 and not _flash_mask_available: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+67
to
81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 此处应该直接报错,提醒用户在H卡上不要指定使用FA4
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以,直接报错也可以作为修复方案。这里的问题不在于一定要 fallback 到 3,而是当前 如果预期是提醒用户 H 卡上不要指定 FA4,建议把这个分支改成明确异常,而不是 warning 后 if fa_version == 4 and not _flash_mask_available:
raise NotImplementedError(
"FA4 FlashMask requires cute backend; do not set FLAGS_flash_attn_version=4 on H-card/current environment."
)这样也能消除我前面指出的 fallback 后继续执行 FA3/后向分发风险。 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| logger.warning( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Bug 这里同样只处理原始
fa_version == 3。当FLAGS_flash_attn_version=4但_flash_mask_available=False时,forward 实际不会进入 v4_flash_attn_fwd,却仍把fa_version=4返回给FlashMaskContextParallel.backward。随后
cp_flashmask_allgatherkv_balance_backward的 v4 分支又要求_flash_mask_available为真;在 deterministic 训练场景下,这次改动会跳过原本的 v2 fallback,并在 backward 分发到 unsupported version。建议修复方式:在 forward 中先计算
effective_fa_version。如果 v4 backend 不可用,应先降为 3,再按 deterministic 规则必要时降为 2,并把这个实际使用的版本返回给 backward。