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

**URL:** <https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999>\
**Category:** Beginners\
**Created:** [June 13, 2023, 1:21am UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999 "2023-06-13T01:21:40Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![florence26](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@florence26](https://discuss.huggingface.co/u/florence26)\
**Post date:** [June 13, 2023, 1:21am UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/1 "2023-06-13T01:21:40Z")

</div>

I am trying to run the basic fine-tuning a pretrained model code from the huggingface page ([Fine-tune a pretrained model](https://huggingface.co/docs/transformers/training)) and am getting a runtime error:

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

I know this is something to do with the device Pytorch is running on but I have no idea how to solve it.

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![pmoraes](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@pmoraes](https://discuss.huggingface.co/u/pmoraes)\
**Post date:** [June 15, 2023, 6:06pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/2 "2023-06-15T18:06:22Z")

</div>

`training_args = TrainingArguments(output_dir="test_trainer", use_mps_device=True)`

Fixed the problem for me.

---

<div class="post-metadata">

**Author:** ![florence26](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@florence26](https://discuss.huggingface.co/u/florence26)\
**Post date:** [June 15, 2023, 9:37pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/3 "2023-06-15T21:37:28Z")

</div>

I have tried this before, but the model outputs a bunch of errors.

 ![Screenshot 2023-06-15 at 22.35.54](https://us1.discourse-cdn.com/hellohellohello/original/3X/5/c/5ca69825ea64bc33bb2fc85afb5d3b70f482b42c.png)

Any help on this?

---

<div class="post-metadata">

**Author:** ![florence26](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@florence26](https://discuss.huggingface.co/u/florence26)\
**Post date:** [June 15, 2023, 9:38pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/4 "2023-06-15T21:38:07Z")

</div>

![Screenshot 2023-06-15 at 22.36.54](https://us1.discourse-cdn.com/hellohellohello/original/3X/1/8/183ceada6a6e4a4374bdd90b79d1c318c023c2d0.png)

---

<div class="post-metadata">

**Author:** ![Xwasta](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/xwasta/32/16942_2.png) [@Xwasta](https://discuss.huggingface.co/u/Xwasta)\
**Post date:** [June 19, 2023, 9:07am UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/5 "2023-06-19T09:07:55Z")

</div>

Thanks! this worked for me as well. I think it has an issue with the pytorch nightly build for apple silicon

---

<div class="post-metadata">

**Author:** ![LoadingALIAS](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/loadingalias/32/17372_2.png) [@LoadingALIAS](https://discuss.huggingface.co/u/LoadingALIAS)\
**Post date:** [July 6, 2023, 12:34am UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/7 "2023-07-06T00:34:52Z")

</div>

This worked for me, too. I was finishing the tutorial series to work out the development environment for tomorrow’s work and hit that MPS issue. @pmoraes solution solved it.

Context:  
Apple M1 MBP  
PyTorch in a conda (MiniForge3) environment

It took nearly 9 minutes over three epochs, and I used the small training and test datasets. The eval loss dropped each epoch, and accuracy increased. It worked.

---

<div class="post-metadata">

**Author:** ![PuikaPuika](https://avatars.discourse-cdn.com/v4/letter/p/e9a140/32.png) [@PuikaPuika](https://discuss.huggingface.co/u/PuikaPuika)\
**Post date:** [July 9, 2023, 1:19pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/8 "2023-07-09T13:19:07Z")

</div>

Where this goes?

---

<div class="post-metadata">

**Author:** ![scythargon](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/scythargon/32/18414_2.png) [@scythargon](https://discuss.huggingface.co/u/scythargon)\
**Post date:** [August 9, 2023, 4:11pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/9 "2023-08-09T16:11:15Z")

</div>

I’m having exact same problem but - while running ControlNet via Automatic11111, I wish I knew where to add this line

---

<div class="post-metadata">

**Author:** ![LMSONE](https://avatars.discourse-cdn.com/v4/letter/l/48db29/32.png) [@LMSONE](https://discuss.huggingface.co/u/LMSONE)\
**Post date:** [September 30, 2023, 10:28am UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/10 "2023-09-30T10:28:59Z")

</div>

Would also really love some help resolving the same issue

using :

Automatic 1111 + ControlNet v1.1.410 + Lineart feature.

I have some understanding of editing code but not a programmer ( so please tell us where to paste the code a) which file - which directory etc - or is it a command via terminal?

* * *

The error appears when trying to generate an image from lineart \_\_ ( ControlNet ) on a pertained model -

Mac: RuntimeError: Placeholder storage has not been allocated on MPS device \_\_

Please explain in lamen terms - what piece of code needs to be replaced and where. I’ve seen other posts but they all relate to M1 Macs. If this issue has been resolved elsewhere for an Intel based Mac please share the link.

Thanks in Advance

---

<div class="post-metadata">

**Author:** ![hanamaruhirosi](https://avatars.discourse-cdn.com/v4/letter/h/f475e1/32.png) [@hanamaruhirosi](https://discuss.huggingface.co/u/hanamaruhirosi)\
**Post date:** [October 4, 2023, 5:50pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/11 "2023-10-04T17:50:38Z")

</div>

try edit COMMANDLINE\_ARGS=“–skip-torch-cuda-test --no-half --use-cpu all” to COMMANDLINE\_ARGS=“–skip-torch-cuda-test --no-half”

---

<div class="post-metadata">

**Author:** ![mox](https://avatars.discourse-cdn.com/v4/letter/m/f04885/32.png) [@mox](https://discuss.huggingface.co/u/mox)\
**Post date:** [October 31, 2023, 1:54pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/12 "2023-10-31T13:54:24Z")

</div>

fixed it with: device=“mps”

---

<div class="post-metadata">

**Author:** ![Darkcat1](https://avatars.discourse-cdn.com/v4/letter/d/8edcca/32.png) [@Darkcat1](https://discuss.huggingface.co/u/Darkcat1)\
**Post date:** [November 18, 2023, 7:30am UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/13 "2023-11-18T07:30:47Z")

</div>

Can someone please do a YouTube video on this? I’m using Pinokio controllnet is saying the same thing. “placeholder storage has not been allocated on mps device!”

---

<div class="post-metadata">

**Author:** ![BCCHANG83](https://avatars.discourse-cdn.com/v4/letter/b/b9bd4f/32.png) [@BCCHANG83](https://discuss.huggingface.co/u/BCCHANG83)\
**Post date:** [March 28, 2024, 3:16am UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/14 "2024-03-28T03:16:33Z")

</div>

this is worked for me

```auto
if torch.backends.mps.is_built():
    device = torch.device("mps") # for mac use

#test prediction

text='//module 2 to 1 mux'

input_ids = tokenizer(text, return_tensors="pt").input_ids.to(device)

generated_ids = model.generate(input_ids, max_length=128).to(device)

print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))

```

---

<div class="post-metadata">

**Author:** ![pdevanshi](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@pdevanshi](https://discuss.huggingface.co/u/pdevanshi)\
**Post date:** [July 6, 2024, 2:33pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/15 "2024-07-06T14:33:33Z")

</div>

I am still facing the issue and nothing seems to work. My device is apple M1 chip.  
Is this the problem with all apple m1chips devices?

---

<div class="post-metadata">

**Author:** ![pdevanshi](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@pdevanshi](https://discuss.huggingface.co/u/pdevanshi)\
**Post date:** [July 6, 2024, 2:42pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/16 "2024-07-06T14:42:08Z")

</div>

this is my error.  
…

[2262]_no\_grad\_embedding\_renorm_(weight, input, max\_norm, norm\_type) → [2264](https://file+.vscode-resource.vscode-cdn.net/Users/devanshipandey/Desktop/textsumm/TextSummarization/research/~/anaconda3/envs/textS/lib/python3.12/site-packages/torch/nn/functional.py:2264) return torch.embedding(weight, input, padding\_idx, scale\_grad\_by\_freq, sparse) RuntimeError: Placeholder storage has not been allocated on MPS device!

---

<div class="post-metadata">

**Author:** ![pdevanshi](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@pdevanshi](https://discuss.huggingface.co/u/pdevanshi)\
**Post date:** [July 6, 2024, 2:54pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/17 "2024-07-06T14:54:35Z")

</div>

Can u share the posts where it worked for apple M1, cant seem to find one and i am facing the same error

---

<div class="post-metadata">

**Author:** ![ThatechMaestro](https://avatars.discourse-cdn.com/v4/letter/t/8491ac/32.png) [@ThatechMaestro](https://discuss.huggingface.co/u/ThatechMaestro)\
**Post date:** [July 7, 2024, 5:08pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/18 "2024-07-07T17:08:01Z")

</div>

@pdevanshi

Also faced the same issue, for endless hours

Got it to work by passing in no\_cuda=true

believe it has something to do with how Trainer handles the models and tensors  
Because my model reverts back to cpu after initialising the Trainer class though being preded by model.to(torch.device(“mps”))

By passing in the the no\_cuda, it uses cpu in all scenarios & avoids the mps saga

```auto
training_args = TrainingArguments(
        output_dir='results',
        overwrite_output_dir=True,
        num_train_epochs=1,
        per_device_train_batch_size=1,
        save_steps=10_000,
        save_total_limit=2,
        no_cuda=True
    )

```

---

<div class="post-metadata">

**Author:** ![pdevanshi](https://avatars.discourse-cdn.com/v4/letter/p/58956e/32.png) [@pdevanshi](https://discuss.huggingface.co/u/pdevanshi)\
**Post date:** [July 8, 2024, 6:40am UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/19 "2024-07-08T06:40:39Z")

</div>

Thank you very much, I will try this

---

<div class="post-metadata">

**Author:** ![MPA](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@MPA](https://discuss.huggingface.co/u/MPA)\
**Post date:** [July 9, 2024, 6:02pm UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/20 "2024-07-09T18:02:55Z")

</div>

it’s a bug,  
line 2157 training\_args.py  
`device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu" )`  
it changed to CPU even though it was mps

---

<div class="post-metadata">

**Author:** ![willsaliba](https://avatars.discourse-cdn.com/v4/letter/w/a698b9/32.png) [@willsaliba](https://discuss.huggingface.co/u/willsaliba)\
**Post date:** [July 16, 2024, 11:55am UTC](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999/21 "2024-07-16T11:55:08Z")

</div>

Thank you that solved the issue for me, and enabled me to train using the apple sillicone GPU by changing the last part of the line to “mps” (instead of “cpu”)

[Next page](https://discuss.huggingface.co/t/runtimeerror-placeholder-storage-has-not-been-allocated-on-mps-device/42999.md?page=2)
