AkimfromParis commited on
Commit
ffa8dce
1 Parent(s): 0349568

Update inference code

Browse files
Files changed (1) hide show
  1. README.md +23 -12
README.md CHANGED
@@ -42,23 +42,34 @@ dtype: bfloat16
42
  ## 💻 Usage
43
 
44
  ```python
45
- !pip install -qU transformers accelerate
46
 
47
- from transformers import AutoTokenizer, AutoModelForCausalLM
48
- import torch
 
 
49
 
50
- tokenizer = AutoTokenizer.from_pretrained(model)
51
- model = AutoModelForCausalLM.from_pretrained("AkimfromParis/Hinoki-Sak-Sta-slerp-7B")
 
52
 
53
- pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer, torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True)
54
 
55
- messages = [{"role": "system", "content": "あなたはAIアシスタントです。"}]
56
- messages.append({"role": "user", "content": "大谷翔平選手について教えてください"})
57
-
58
- prompt = tokenizer.apply_chat_template(conversation=messages, add_generation_prompt=True, tokenize=False)
59
-
60
- pipeline(prompt, max_new_tokens=256, do_sample=False, temperature=0.0, return_full_text=False)
 
 
 
 
 
 
 
61
  ```
 
62
  # Citation
63
  ```
64
  @article{goddard2024arcee,
 
42
  ## 💻 Usage
43
 
44
  ```python
45
+ from transformers import AutoModelForCausalLM, AutoTokenizer
46
 
47
+ model_path = "AkimfromParis/Hinoki-Sak-Sta-slerp-7B"
48
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
49
+ model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
50
+ model.eval()
51
 
52
+ requests = [
53
+ "大谷翔平選手について教えてください",
54
+ ]
55
 
56
+ system_message = "A chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions. USER: {user_input} ASSISTANT:"
57
 
58
+ for req in requests:
59
+ input_req = system_message.format(user_input=req)
60
+ input_ids = tokenizer.encode(input_req, return_tensors="pt").to(device=model.device)
61
+ tokens = model.generate(
62
+ input_ids,
63
+ max_new_tokens=1024,
64
+ do_sample=True,
65
+ pad_token_id=tokenizer.eos_token_id,
66
+ )
67
+ out = tokenizer.decode(tokens[0][len(input_ids[0]):], skip_special_tokens=True)
68
+ print("USER:\n" + req)
69
+ print("ASSISTANT:\n" + out)
70
+ print()
71
  ```
72
+
73
  # Citation
74
  ```
75
  @article{goddard2024arcee,