HaoxingChen commited on
Commit
623eea7
·
verified ·
1 Parent(s): 4c0e9d3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +28 -6
README.md CHANGED
@@ -44,12 +44,34 @@ $ pip install transformers==4.51.3
44
  Then, copy the snippet from the section that is relevant for your use case.
45
  ```python
46
  from transformers import AutoModelForCausalLM, AutoTokenizer
47
- tokenizer = AutoTokenizer.from_pretrained("inclusionAI/GroveMoE-Inst", trust_remote_code=True)
48
- model = AutoModelForCausalLM.from_pretrained("inclusionAI/GroveMoE-Inst", device_map="auto", trust_remote_code=True).eval()
49
- inputs = tokenizer('### Human:\nHow are you?\n### Assistant:\n', return_tensors='pt')
50
- inputs = inputs.to(model.device)
51
- pred = model.generate(**inputs)
52
- print(tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  ```
54
 
55
  ## Citation
 
44
  Then, copy the snippet from the section that is relevant for your use case.
45
  ```python
46
  from transformers import AutoModelForCausalLM, AutoTokenizer
47
+ model_name = "inclusionAI/GroveMoE-Inst"
48
+ # load the tokenizer and the model
49
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
50
+ model = AutoModelForCausalLM.from_pretrained(
51
+ model_name,
52
+ torch_dtype="auto",
53
+ device_map="auto"
54
+ )
55
+ # prepare the model input
56
+ prompt = "Give me a short introduction to large language model."
57
+ messages = [
58
+ {"role": "user", "content": prompt}
59
+ ]
60
+ text = tokenizer.apply_chat_template(
61
+ messages,
62
+ tokenize=False,
63
+ add_generation_prompt=True,
64
+ )
65
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
66
+ # conduct text completion
67
+ generated_ids = model.generate(
68
+ **model_inputs,
69
+ max_new_tokens=16384
70
+ )
71
+ output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
72
+ content = tokenizer.decode(output_ids, skip_special_tokens=True)
73
+
74
+ print("content:", content)
75
  ```
76
 
77
  ## Citation