KEMBAR78
Running phi-2 on MacOS with returns garbage · Issue #160841 · pytorch/pytorch · GitHub
Skip to content

Running phi-2 on MacOS with returns garbage #160841

@malfet

Description

@malfet

🐛 Describe the bug

Almost verbatim HF example

import torch
from torch.profiler import profile, ProfilerActivity
from transformers import AutoModelForCausalLM, AutoTokenizer
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype="auto", trust_remote_code=True)
print(next(model.parameters()).dtype)
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2", trust_remote_code=True)

inputs = tokenizer('''def print_prime(n):
   """
   Print all primes between 1 and n
   """''', return_tensors="pt", return_attention_mask=False)

outputs = model.generate(**inputs, max_length=32)
text = tokenizer.batch_decode(outputs)[0]
print(text)

Changing data type to bf16 fixes the problem. This is tru for both CPU and MPS

Versions

CI

cc @kulinseth @DenisVieriu97 @jhavukainen @albanD @snadampal @milpuz01 @aditew01 @nikhil-arm @fadara01

Metadata

Metadata

Assignees

Labels

module: correctness (silent)issue that returns an incorrect result silentlymodule: halfRelated to float16 half-precision floatsmodule: macosMac OS related issuesmodule: mpsRelated to Apple Metal Performance Shaders frameworkmodule: sdpaAll things related to torch.nn.functional.scaled_dot_product_attentiiontriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions