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", device_map="auto", torch_dtype="auto")
7tokenizer = AutoTokenizer.from_pretrained("cyberagent/calm2-7b")
8streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
9
10prompt = "AIによって私達の暮らしは、"
11
12token_ids = tokenizer.encode(prompt, return_tensors="pt")
13output_ids = model.generate(
14 input_ids=token_ids.to(model.device),
15 max_new_tokens=100,
16 do_sample=True,
17 temperature=0.9,
18 streamer=streamer,
19)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}