-
I am training a PEFT adapter using QLoRa like this: rainer = transformers.Trainer(
model=model,
train_dataset=data,
args=training_args,
data_collator=transformers.DataCollatorForLanguageModeling(tokenizer, mlm=False),
)
model.config.use_cache = False
trainer.train() Is there any way I can output the adapter_model.bin file to disk after every N gradient steps? |
Beta Was this translation helpful? Give feedback.
Answered by
M-Ali-ML
Aug 13, 2023
Replies: 1 comment
-
use custom made callback class SavePeftModelCallback(TrainerCallback):
def on_save(
self,
args: TrainingArguments,
state: TrainerState,
control: TrainerControl,
**kwargs,
):
checkpoint_folder = os.path.join(args.output_dir, f"{PREFIX_CHECKPOINT_DIR}-{state.global_step}")
peft_model_path = os.path.join(checkpoint_folder, "adapter_model")
kwargs["model"].save_pretrained(peft_model_path)
pytorch_model_path = os.path.join(checkpoint_folder, "pytorch_model.bin")
if os.path.exists(pytorch_model_path):
os.remove(pytorch_model_path)
return control more can be found here |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
alexflint
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use custom made callback
more can be found here