update training resuming

Former-commit-id: 2ec75c31f609e65116ac3b621eeb7d8ccbf69135
This commit is contained in:
hiyouga
2023-08-18 01:41:17 +08:00
parent f11c1ae562
commit c2644f939a
7 changed files with 57 additions and 29 deletions

View File

@@ -1,5 +1,4 @@
# Inspired by: https://github.com/huggingface/transformers/blob/v4.29.2/examples/pytorch/summarization/run_summarization.py
import os
from typing import TYPE_CHECKING, Optional, List
from transformers import DataCollatorForSeq2Seq
@@ -11,14 +10,11 @@ from llmtuner.extras.ploting import plot_loss
from llmtuner.tuner.core import load_model_and_tokenizer
from llmtuner.tuner.sft.metric import ComputeMetrics
from llmtuner.tuner.sft.trainer import Seq2SeqPeftTrainer
from transformers.trainer_utils import get_last_checkpoint
from llmtuner.extras.logging import reset_logging, get_logger
if TYPE_CHECKING:
from transformers import Seq2SeqTrainingArguments, TrainerCallback
from llmtuner.hparams import ModelArguments, DataArguments, FinetuningArguments, GeneratingArguments
logger = get_logger(__name__)
def run_sft(
model_args: "ModelArguments",
@@ -62,12 +58,7 @@ def run_sft(
# Training
if training_args.do_train:
checkpoint = None
if training_args.resume_from_checkpoint is not None:
checkpoint = training_args.resume_from_checkpoint
elif last_checkpoint is not None:
checkpoint = last_checkpoint
train_result = trainer.train(resume_from_checkpoint=checkpoint)
train_result = trainer.train(resume_from_checkpoint=training_args.resume_from_checkpoint)
trainer.log_metrics("train", train_result.metrics)
trainer.save_metrics("train", train_result.metrics)
trainer.save_state()