Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
```python
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
+
|
| 5 |
+
torch.set_default_device('cuda')
|
| 6 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1_5", trust_remote_code=True, torch_dtype="auto")
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1_5", trust_remote_code=True, torch_dtype="auto")
|
| 8 |
+
prompt = "Are textbooks all you need?"
|
| 9 |
+
inputs = tokenizer(prompt,return_tensors="pt", return_attention_mask=False)
|
| 10 |
+
|
| 11 |
+
outputs = model.generate(
|
| 12 |
+
**inputs,
|
| 13 |
+
max_length=200,
|
| 14 |
+
do_sample=True, # for spontaneity 🤷
|
| 15 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 16 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 17 |
+
)
|
| 18 |
+
text = tokenizer.batch_decode(outputs)[0]
|
| 19 |
+
print(text)
|
| 20 |
+
```
|