-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for apple silicon #3
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ | |
from transformers.models.mistral.modeling_mistral import MistralAttention | ||
from transformers import AutoTokenizer, AutoModelForCausalLM | ||
import transformers | ||
import torch | ||
|
||
device = torch.device("mps" if torch.backends.mps.is_available() else "auto") | ||
|
||
original_mistral_forward = MistralAttention.forward | ||
self_extend_forward = partial(MistralSE.self_extend_forward, group_size_1=4, group_size_2=1024) | ||
|
@@ -17,18 +20,18 @@ | |
model_path = 'mistralai/Mistral-7B-Instruct-v0.1' | ||
config = transformers.AutoConfig.from_pretrained(model_path) | ||
config.sliding_window = 200000000 # disable mistral's default SWA mechanism (4096), mistral's true window is 8192. | ||
model = AutoModelForCausalLM.from_pretrained(model_path, config=config, device_map="auto") | ||
model = AutoModelForCausalLM.from_pretrained(model_path, config=config, device_map=device) | ||
|
||
|
||
tokenizer = AutoTokenizer.from_pretrained(model_path) | ||
model.eval() | ||
model.eval().to(device) | ||
|
||
# In the example task file, the passkey is placed within the last 4096 tokens, this means, if you use SWA, mistral will successfully find the passkey. | ||
for line in open("passkey_examples_10k.jsonl", "r"): | ||
example = json.loads(line) | ||
prompt_postfix = "What is the pass key? The pass key is " | ||
prompt = example["input"] + prompt_postfix | ||
input_ids = tokenizer(prompt, return_tensors="pt").input_ids | ||
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. device_map value "auto" can't be used in tensor.to(device) or model.eval().to(device). Valid device values are cpu, cuda, ipu, xpu, mkldnn, opengl, opencl, ideep, hip, ve, fpga, ort, xla, lazy, vulkan, mps, meta, hpu, mtia, privateuseone. |
||
print( "-----------------------------------" ) | ||
print( f"#Tokens of Prompt:", input_ids.shape[1], end=" " ) | ||
print( "Passkey target:", example["target"] ) | ||
|
@@ -47,6 +50,9 @@ | |
answer = answer.replace("\n", "\\n") | ||
print( answer ) | ||
print( "-----------------------------------\n" ) | ||
|
||
if torch.backends.mps.is_available(): | ||
torch.mps.empty_cache() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like a pytorch issue in pytorch/pytorch#105839 ? |
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
device_map value "auto" can't be used in tensor.to(device) or model.eval().to(device). Valid device values are cpu, cuda, ipu, xpu, mkldnn, opengl, opencl, ideep, hip, ve, fpga, ort, xla, lazy, vulkan, mps, meta, hpu, mtia, privateuseone.