MAC M1 芯片训练huggingface上的模型,报错RuntimeError: Placeholder storage has not been allocated on MPS device!

       第一次使用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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值