即使使用QLoRA,在Colab中仍可能出现内存耗尽。策略:
per_device_train_batch_size从1或2开始。通过gradient_accumulation_steps进行补偿。
max_seq_length如果内容允许,从512降低到256或384。
torch.compile(实验性)model = torch.compile(model)
可能加速训练并减少内存,但并不总是稳定。
torch.cuda.empty_cache()
在加载模型后或实验之间很有用。
CUDA out of memorygradient_accumulation_steps。max_seq_length。Some weights of the model checkpoint ... were not used如果使用trust_remote_code=True加载或使用PEFT,这是正常的。不严重。
ValueError: Attempting to unscale FP16 gradients.在TrainingArguments中使用optim="adamw_bnb_8bit"或optim="paged_adamw_8bit"。
The model is not in eval mode忽略。Trainer会自动处理模式。