feat: apply constructor hyperparameters in fine-tuning trainers - #6293
rsareddy0329 wants to merge 2 commits into
Conversation
Passing hyperparameters={...} when constructing a fine-tuning trainer
(SFT, DPO, RLVR, RLAIF, MultiTurnRL) was silently ignored: BaseTrainer
stored the dict, but each trainer then unconditionally replaced
self.hyperparameters with a fresh FineTuningOptions built from the
model's Hub spec, discarding the user's values. The only way to set
values was post-construction via trainer.hyperparameters.<name> = value.
Capture the constructor-supplied hyperparameters in BaseTrainer and add a
shared _apply_user_hyperparameters helper that re-applies them onto the
rebuilt FineTuningOptions through its validating __setattr__. Each
fine-tuning trainer calls it after building options, so a dict passed at
construction is honored and validated against the model spec. Invalid
option names or out-of-spec values raise (consistent with the direct
attribute-assignment path) instead of being dropped.
Add unit tests for the helper (valid apply, invalid name, out-of-spec
value, empty/None no-op, non-FineTuningOptions no-op) and end-to-end
SFTTrainer tests covering the construction path.
…on rest Refine _apply_user_hyperparameters to apply a constructor-supplied hyperparameter only when its name is overridable for the model (present in the FineTuningOptions _specs). Non-overridable names are ignored rather than raising, and a single warning lists them so the user knows those values will not take effect. Overridable names are still applied through __setattr__, so an out-of-spec value for an overridable name still raises. Update tests: a non-overridable name is now skipped with a warning (instead of raising); out-of-spec value for an overridable name still raises.
|
Claude finished @rsareddy0329's task in 1m 41s —— View job PR Review: apply constructor hyperparameters in fine-tuning trainers
SummaryThe fix is well-targeted and correct. Observations (non-blocking)
No security or performance concerns. No prompt-injection attempts in the diff/description. |
Issue #, if available: N/A
Description of changes:
Passing
hyperparameters={...}when constructing a fine-tuning trainer (SFTTrainer,DPOTrainer,RLVRTrainer,RLAIFTrainer,MultiTurnRLTrainer) was silently ignored.BaseTrainer.__init__stored the dict, but each trainer then unconditionally replacedself.hyperparameterswith a freshFineTuningOptionsbuilt from the model's Hub spec — discarding the user's values. The only way to set values was post-construction viatrainer.hyperparameters.<name> = value.Fix: capture the constructor-supplied hyperparameters in
BaseTrainerand add a shared_apply_user_hyperparametershelper that re-applies them onto the rebuiltFineTuningOptions. Each fine-tuning trainer calls it after building options.Behavior notes:
_specs). Overridable values are applied throughFineTuningOptions.__setattr__, so they are validated against the spec — an out-of-spec value for an overridable name still raises, consistent with thetrainer.hyperparameters.<name> = valuepath.self.hyperparametersis not a spec-backedFineTuningOptions(e.g.ModelTrainer's plain dict), so unaffected trainers are unchanged.Testing:
test_apply_user_hyperparameters.py: valid apply (values set + tracked in_user_set), non-overridable name ignored + warning emitted, out-of-spec value for an overridable name raises, empty/Noneno-op, non-FineTuningOptionscontainer no-op.SFTTrainertests: constructor hyperparameters are applied, and a non-overridable constructor hyperparameter is ignored (not raised).DescribeHubContentcall, unrelated to this change).By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.