You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

M1 Mac CPU环境下无法运行Transformer微调的问题求助

M1 Mac CPU环境下无法运行Transformer微调的问题求助

各位大佬好,我最近在M1 Mac上尝试用CPU微调DistilBert模型,碰到了一个搞不懂的问题,想请大家帮忙看看。

我用的代码如下:

from transformers import DistilBertForSequenceClassification, Trainer, TrainingArguments

training_args = TrainingArguments(
    output_dir='./results',          # output directory
    num_train_epochs=1,              # total number of training epochs
    per_device_train_batch_size=16,  # batch size per device during training
    per_device_eval_batch_size=64,   # batch size for evaluation
    warmup_steps=500,                # number of warmup steps for learning rate scheduler
    weight_decay=0.01,               # strength of weight decay
    logging_dir='./logs',            # directory for storing logs
    logging_steps=10,
    use_mps_device=False
)

model = DistilBertForSequenceClassification.from_pretrained("distilbert-base-uncased")

trainer = Trainer(
    model=model,                         # the instantiated Transformers model to be trained
    args=training_args,                  # training arguments, defined above
    train_dataset=train_dataset,         # training dataset
    eval_dataset=val_dataset             # evaluation dataset
)

device = torch.device("cpu")
model.to(device)

trainer.train()

运行这段代码后,我遇到了这个错误:

RuntimeError: Placeholder storage has not been allocated on MPS device!

奇怪的是,如果我把use_mps_device改成True,模型反而能正常用GPU训练,可明明我已经通过model.to(device)把模型转到CPU上了啊?

我现在的需求是用CPU来跑训练,但怎么都搞不定,有没有大佬知道这是哪里出问题了,该怎么解决呢?

备注:内容来源于stack exchange,提问作者Nin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 11:13:15