Update README.md
Browse files
README.md
CHANGED
|
@@ -4,3 +4,43 @@ datasets:
|
|
| 4 |
---
|
| 5 |
|
| 6 |
## Usage:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
## Usage:
|
| 7 |
+
|
| 8 |
+
```python
|
| 9 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 10 |
+
|
| 11 |
+
import torch
|
| 12 |
+
|
| 13 |
+
tokenizer = AutoTokenizer.from_pretrained("TinyPixel/stablelm-ft2", trust_remote_code=True)
|
| 14 |
+
|
| 15 |
+
model = AutoModelForCausalLM.from_pretrained("TinyPixel/stablelm-ft2", torch_dtype=torch.bfloat16, device_map="auto", trust_remote_code=True)
|
| 16 |
+
|
| 17 |
+
text = '''### System:
|
| 18 |
+
|
| 19 |
+
You are a helpful AI assistant.
|
| 20 |
+
|
| 21 |
+
### User:
|
| 22 |
+
|
| 23 |
+
Why is sky blue?
|
| 24 |
+
|
| 25 |
+
### Assistant:
|
| 26 |
+
|
| 27 |
+
'''
|
| 28 |
+
|
| 29 |
+
device = "cuda:0"
|
| 30 |
+
|
| 31 |
+
inputs = tokenizer(text, return_tensors="pt").to(device)
|
| 32 |
+
|
| 33 |
+
outputs = model.generate(**inputs,
|
| 34 |
+
|
| 35 |
+
max_new_tokens=512,
|
| 36 |
+
|
| 37 |
+
do_sample=True,
|
| 38 |
+
|
| 39 |
+
top_p=0.95,
|
| 40 |
+
|
| 41 |
+
temperature=0.7,
|
| 42 |
+
|
| 43 |
+
top_k=50)
|
| 44 |
+
|
| 45 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=False))
|
| 46 |
+
```
|