Update README.md
Browse files
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 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|