MCPcopy
hub / github.com/huggingface/transformers / _tune_save_checkpoint

Method _tune_save_checkpoint

src/transformers/trainer.py:4360–4369  ·  view source on GitHub ↗

Save a checkpoint during a Ray Tune hyperparameter search trial.

(self, checkpoint_dir: str)

Source from the content-addressed store, hash-verified

4358 ray.tune.report(metrics, checkpoint=checkpoint)
4359
4360 def _tune_save_checkpoint(self, checkpoint_dir: str) -> None:
4361 """Save a checkpoint during a Ray Tune hyperparameter search trial."""
4362 output_dir = os.path.join(checkpoint_dir, f"{PREFIX_CHECKPOINT_DIR}-{self.state.global_step}")
4363 self.save_model(output_dir, _internal_call=True)
4364 if self.args.should_save:
4365 # Update the `TrainerControl` state to where we are currently
4366 self.state.stateful_callbacks["TrainerControl"] = self.control.state()
4367 self.state.save_to_json(os.path.join(output_dir, TRAINER_STATE_NAME))
4368 torch.save(self.optimizer.state_dict(), os.path.join(output_dir, OPTIMIZER_NAME))
4369 torch.save(self.lr_scheduler.state_dict(), os.path.join(output_dir, SCHEDULER_NAME))
4370
4371 # ---- Callbacks ----
4372

Callers 2

_report_to_hp_searchMethod · 0.95
_objectiveFunction · 0.80

Calls 6

save_modelMethod · 0.95
joinMethod · 0.80
save_to_jsonMethod · 0.80
stateMethod · 0.45
saveMethod · 0.45
state_dictMethod · 0.45

Tested by

no test coverage detected