Repository navigation
fix(raft): NameError on 'model' in gradient clipping of RaftTrainer - #980
Open
sarankumar1325 wants to merge 1 commit into
Open
sarankumar1325 wants to merge 1 commit into
sarankumar1325 wants to merge 1 commit into
Conversation
…ture error message RaftTrainer._one_train referenced an undefined 'model' in the gradient clipping branch (a leftover from transformers.Trainer), raising NameError whenever max_grad_norm > 0 without DeepSpeed. Use self.tmp_model, which is what the rest of the method trains. Also report select_vision_feature_type in the ValueError raised by Vision2Seq.vision_feature_select instead of the non-existent self.select_feature. Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
This branch has not been deployed
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.
What
Found with
ruff --select F821:src/lmflow/pipeline/utils/raft_trainer.py,RaftTrainer._one_train: the gradient-clipping branch (args.max_grad_norm > 0and not DeepSpeed, i.e. the default) useshasattr(model, "clip_grad_norm_")/model.clip_grad_norm_/model.parameters(), but nomodelexists in that method (it was left over fromtransformers.Trainer, wheremodelis a local). That raisesNameErroron the first optimizer step. The rest of_one_traintrainsself.tmp_model, so the three references now use it.src/lmflow/models/vision2seq_model.py,vision_feature_select: theValueErrorfor an unknown feature type formattedself.select_feature, which does not exist on that class, so users got anAttributeErrorinstead of the intended message. It now reportsself.select_vision_feature_type.Tests
Added
tests/pipeline/test_raft_trainer_names.py, which parsesraft_trainer.pywithsymtable(notransformers/GPU needed) and asserts_one_trainhas no undefined global names. It fails onmainand passes with this change.ruff check/ruff format --checkare clean on the touched files. I did not run an end-to-end RAFT training, and the vision2seq message fix has no test.AI assistance
This PR was prepared with AI assistance (Grok Bot, on behalf of @sarankumar1325).