fix(core): replace hard assertion with warning for NVTE_* env conflicts - #1
Open
xiaohong42 wants to merge 1 commit into
Open
fix(core): replace hard assertion with warning for NVTE_* env conflicts#1xiaohong42 wants to merge 1 commit into
xiaohong42 wants to merge 1 commit into
Conversation
Replace the AssertionError in `_set_attention_backend` with a warning and automatic override when NVTE_FLASH_ATTN, NVTE_FUSED_ATTN, or NVTE_UNFUSED_ATTN environment variables conflict with the configured `attention_backend`. Problem: When running inside Docker containers whose base images pre-set these environment variables (e.g., ROCm training images set NVTE_FLASH_ATTN=0 and NVTE_FUSED_ATTN=1 for their own TransformerEngine CK backend), Megatron-Core raises an AssertionError during model initialization if the `attention_backend` config (flash, auto, etc.) expects different values. Users cannot modify the base image and have no clean way to unset Docker ENV variables at the image level. Solution: - Issue a `warnings.warn()` when a mismatch is detected, informing the user of the override and how to silence the warning. - Proceed to set the correct value as before (the line after the old assert already did this for the None case). This preserves the intent of catching misconfigurations while avoiding crashes in containerized environments where users inherit env variables they did not explicitly set. Signed-off-by: xiaohong42 <xiaohong42@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
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
When running inside Docker containers whose base images pre-set
NVTE_FLASH_ATTN,NVTE_FUSED_ATTN, orNVTE_UNFUSED_ATTNenvironment variables (e.g., ROCm training images setNVTE_FLASH_ATTN=0andNVTE_FUSED_ATTN=1for their TransformerEngine CK backend), Megatron-Core raises anAssertionErrorduring model initialization if the configuredattention_backend(flash, auto, etc.) expects different values.Users cannot modify the base image and have no clean way to unset Docker
ENVvariables at the image level (docker execsessions also inherit them).Solution
Replace the hard
assertincheck_and_set_env_variable()with:warnings.warn()that informs the user of the mismatch and the override.os.environ[...] = str(expected_value)assignment that forces the correct value.This preserves the intent of catching misconfigurations while avoiding crashes in containerized environments where users inherit env variables they did not explicitly set.
Changes
megatron/core/models/common/language_module/language_module.py: ReplaceAssertionErrorwithwarnings.warn()+ override in_set_attention_backend().Testing
Verified that:
attention_backend=autoworks with pre-setNVTE_FLASH_ATTN=0/NVTE_FUSED_ATTN=1(previously crashed).attention_backend=flashworks with pre-setNVTE_FUSED_ATTN=1(previously crashed).