Skip to content

fix(raft): NameError on 'model' in gradient clipping of RaftTrainer - #980

Open
sarankumar1325 wants to merge 1 commit into
OptimalScale:mainfrom
sarankumar1325:fix/raft-trainer-undefined-model
Open

sarankumar1325 wants to merge 1 commit into
OptimalScale:mainfrom
sarankumar1325:fix/raft-trainer-undefined-model

Conversation

@sarankumar1325

Copy link
Copy Markdown

What

Found with ruff --select F821:

  1. src/lmflow/pipeline/utils/raft_trainer.py, RaftTrainer._one_train: the gradient-clipping branch (args.max_grad_norm > 0 and not DeepSpeed, i.e. the default) uses hasattr(model, "clip_grad_norm_") / model.clip_grad_norm_ / model.parameters(), but no model exists in that method (it was left over from transformers.Trainer, where model is a local). That raises NameError on the first optimizer step. The rest of _one_train trains self.tmp_model, so the three references now use it.
  2. src/lmflow/models/vision2seq_model.py, vision_feature_select: the ValueError for an unknown feature type formatted self.select_feature, which does not exist on that class, so users got an AttributeError instead of the intended message. It now reports self.select_vision_feature_type.

Tests

Added tests/pipeline/test_raft_trainer_names.py, which parses raft_trainer.py with symtable (no transformers/GPU needed) and asserts _one_train has no undefined global names. It fails on main and passes with this change. ruff check / ruff format --check are 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).

…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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant