forked from LechengKong/OneForAll
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllama_exp.py
More file actions
26 lines (21 loc) · 826 Bytes
/
Copy pathllama_exp.py
File metadata and controls
26 lines (21 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import torch
from transformers import LlamaTokenizer, LlamaForCausalLM
## v2 models
model_path = "openlm-research/open_llama_3b_v2"
## v1 models
# model_path = 'openlm-research/open_llama_3b'
# model_path = 'openlm-research/open_llama_7b'
# model_path = 'openlm-research/open_llama_13b'
tokenizer = LlamaTokenizer.from_pretrained(model_path)
model = LlamaForCausalLM.from_pretrained(
model_path,
torch_dtype=torch.float16,
device_map="auto",
)
prompt = "Q: Among machine learning, biology, and chemistry, which one is computer science most pertained to?\nA:"
input_ids = tokenizer(prompt, return_tensors="pt").input_ids
generation_output = model.generate(
input_ids=input_ids.to("cuda:0"), max_new_tokens=32
)
print(tokenizer.decode(generation_output[0]))
print(torch.cuda.max_memory_allocated("cuda:0"))