MCPcopy Create free account
hub / github.com/FreedomIntelligence/LLMZoo / train

Function train

train.py:40–67  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38
39
40def train():
41 parser = transformers.HfArgumentParser((ModelArguments, DataArguments, TrainingArguments))
42 model_args, data_args, training_args = parser.parse_args_into_dataclasses()
43
44 model, tokenizer = build_model(model_args, training_args)
45
46 data_module = make_supervised_data_module(tokenizer=tokenizer, data_args=data_args)
47
48 trainer = Trainer(model=model, tokenizer=tokenizer, args=training_args, **data_module)
49
50 if model_args.lora:
51 old_state_dict = model.state_dict
52 model.state_dict = (
53 lambda self, *_, **__: get_peft_model_state_dict(self, old_state_dict())
54 ).__get__(model, type(model))
55 if torch.__version__ >= "2":
56 model = torch.compile(model)
57
58 if list(pathlib.Path(training_args.output_dir).glob("checkpoint-*")):
59 trainer.train(resume_from_checkpoint=True)
60 else:
61 trainer.train()
62
63 trainer.save_state()
64 if model_args.lora:
65 model.save_pretrained(os.path.join(training_args.output_dir, "lora"))
66 tokenizer.save_pretrained(os.path.join(training_args.output_dir, "lora"))
67 safe_save_model_for_hf_trainer(trainer=trainer, output_dir=training_args.output_dir)
68
69
70if __name__ == "__main__":

Callers 2

train_fast.pyFile · 0.90
train.pyFile · 0.85

Calls 3

build_modelFunction · 0.90

Tested by

no test coverage detected