第一次使用Mac Pro尝试拉取和训练模型,考虑到性能问题选择了"Qwen/Qwen2-0.5B-Instruct"做测试,测试代码也出现过RuntimeError: Placeholder storage has not been allocated on MPS device!,发现是需要把model和model_input都放入mps的问题:
device = "mps"
model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2-0.5B-Instruct",
torch_dtype="auto",
device_map="auto").to(device)
model_inputs = tokenizer([text], return_tensors="pt", padding=True, truncation=True).to(device)
设置完.to(device)之后可以正常运行,注意tensors的格式需要是“pt”
在后续训练环节,按着同样的方式设置,在检查了一万遍后,还是会出现RuntimeError: Placeholder storage has not been allocated on MPS device!的问题,打断点发现初始化训练参数的时候train_args后续会自动把device修改成cpu,加上use_cpu=False和use_mps_device=True后还是会变成cpu,也尝试过禁用mps加速依然不解决问题。
train_args = T