nanoGPT icon indicating copy to clipboard operation
nanoGPT copied to clipboard

Torch >= 2.2.0 inference issues on MPS

Open davmacario opened this issue 11 months ago • 3 comments

When running

python sample.py --init_from=gpt2 --num_samples=2 --max_new_tokens=100

having set device = 'mps' on my M1 Pro MacBook (MacOS 14.4), with Torch 2.2.1 and 2.2.0, I get this output:

Overriding: init_from = gpt2
Overriding: num_samples = 2
Overriding: max_new_tokens = 100
loading weights from pretrained gpt: gpt2
forcing vocab_size=50257, block_size=1024, bias=True
overriding dropout rate to 0.0
number of parameters: 123.65M
No meta.pkl found, assuming GPT-2 encodings...

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
---------------

!!!!!!。!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
---------------

The character ! corresponds to token 0, meaning that the model only generates 0's at the output.
This does not happen when using Torch 2.1.x.

I know this is probably a Torch bug, but I could use the help trying to pinpoint the actual cause of this issue (and possibly submit a bug report to Torch). Let me know if someone has had the same issue.

davmacario avatar Mar 20 '24 03:03 davmacario

I had the same issue on a M1 Pro Macbook with Torch 2.2.0

adriankobras avatar Apr 23 '24 14:04 adriankobras

I encountered a similar issue as well. I reproduced a Transformer on mps and encountered a similar error, but it worked fine on cpu. I upgraded to torch 2.3.0 and it seems to have fixed it(Although I didn't see any mention of bug fixes in the logs).

sun1638650145 avatar Apr 25 '24 12:04 sun1638650145

Alright, thanks @sun1638650145, I'll give it a try and possibly update the issue!

davmacario avatar May 16 '24 22:05 davmacario