fix: model dtype is not same as lora dtype in FSDP train#183
Open
0hujun wants to merge 2 commits intomodelscope:mainfrom
Open
fix: model dtype is not same as lora dtype in FSDP train#1830hujun wants to merge 2 commits intomodelscope:mainfrom
0hujun wants to merge 2 commits intomodelscope:mainfrom
Conversation
1 task
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces the _ensure_lora_dtype method to align LoRA parameter data types with the base model, ensuring compatibility with FSDP2. Review feedback suggests several improvements, including more robust detection of the base data type to handle mixed precision, narrowing exception handling, and wrapping parameter updates in torch.no_grad() for safety.
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.
PR type
PR information
As described in #182,in ascend npu, model param dtype is bf16, but create lora param dtype is fp32 as default,that got AssertionError: FSDP expects uniform original parameter dtype but got FSDP expects uniform original parameter dtype but got {torch.bfloat16, torch.float32}
So, when lora param has created, convert all LoRA parameters to the base model dtype.
Experiment results
Train fine as usual