-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
97e5f58
commit 02480a0
Showing
4 changed files
with
121 additions
and
35 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
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
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,39 @@ | ||
import transformers | ||
import torch | ||
|
||
model_id = "meta-llama/Meta-Llama-3-8B-Instruct" | ||
|
||
pipeline = transformers.pipeline( | ||
"text-generation", | ||
model=model_id, | ||
model_kwargs={"torch_dtype": torch.bfloat16, "cache_dir": "./cache"}, | ||
device="cuda", | ||
) | ||
|
||
messages = [ | ||
{ | ||
"role": "system", | ||
"content": "You are a pirate chatbot who always responds in pirate speak!", | ||
}, | ||
{"role": "user", "content": "Give three tips for staying healthy."}, | ||
] | ||
|
||
prompt = pipeline.tokenizer.apply_chat_template( | ||
messages, tokenize=False, add_generation_prompt=True | ||
) | ||
|
||
terminators = [ | ||
pipeline.tokenizer.eos_token_id, | ||
pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>"), | ||
] | ||
|
||
outputs = pipeline( | ||
prompt, | ||
max_new_tokens=256, | ||
eos_token_id=terminators, | ||
do_sample=True, | ||
temperature=0.6, | ||
top_p=0.9, | ||
) | ||
print(outputs[0]["generated_text"]) | ||
# print(outputs[0]["generated_text"][len(prompt):]) |
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