forked from karpathy/nanoGPT
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from klei22/add_mixtral8x7b_example
Add mixtral8x7b example
- Loading branch information
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
pip install accelerate | ||
pip install bitsandbytes | ||
pip install -q -U git+https://github.com/huggingface/transformers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from transformers import AutoModelForCausalLM, AutoTokenizer | ||
|
||
model_id = "mistralai/Mixtral-8x7B-Instruct-v0.1" | ||
tokenizer = AutoTokenizer.from_pretrained(model_id) | ||
|
||
model = AutoModelForCausalLM.from_pretrained(model_id, load_in_4bit=True, device_map="auto") | ||
|
||
text = "Hello my name is" | ||
messages = [ | ||
{"role": "user", "content": "What is your favorite condiment?"}, | ||
{"role": "assistant", "content": "Well, I'm quite partial to a good squeeze of fresh lemon juice. It adds just the right amount of zesty flavor to whatever I'm cooking in the kitchen."}, | ||
{"role": "user", "content": "Do you have mayonnaise recipes?"} | ||
] | ||
|
||
input_ids = tokenizer.apply_chat_template(messages, return_tensors="pt").to("cuda") | ||
|
||
outputs = model.generate(input_ids, max_new_tokens=2000) | ||
print(tokenizer.decode(outputs[0], skip_special_tokens=True)) |