Views
No views yet
1import transformers
2from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
3
4assert transformers.__version__ >= "4.34.1"
5
6model = AutoModelForCausalLM.from_pretrained("cyberagent/calm2-7b-chat", device_map="auto", torch_dtype="auto")
7tokenizer = AutoTokenizer.from_pretrained("cyberagent/calm2-7b-chat")
8streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
9
10prompt = """USER: AIによって私達の暮らしはどのように変わりますか?
11ASSISTANT: """
12
13token_ids = tokenizer.encode(prompt, return_tensors="pt")
14output_ids = model.generate(
15 input_ids=token_ids.to(model.device),
16 max_new_tokens=300,
17 do_sample=True,
18 temperature=0.8,
19 streamer=streamer,
20)USER: {user_message1}
ASSISTANT: {assistant_message1}<|endoftext|>
USER: {user_message2}
ASSISTANT: {assistant_message2}<|endoftext|>
USER: {user_message3}
ASSISTANT: {assistant_message3}<|endoftext|>1@article{touvron2023llama,
2 title={LLaMA: Open and Efficient Foundation Language Models},
3 author={Touvron, Hugo and Lavril, Thibaut and Izacard, Gautier and Martinet, Xavier and Lachaux, Marie-Anne and Lacroix, Timoth{\'e}e and Rozi{\`e}re, Baptiste and Goyal, Naman and Hambro, Eric and Azhar, Faisal and Rodriguez, Aurelien and Joulin, Armand and Grave, Edouard and Lample, Guillaume},
4 journal={arXiv preprint arXiv:2302.13971},
5 year={2023}
6}