Update README.md
Browse files
README.md
CHANGED
@@ -144,7 +144,25 @@ johnhew@cs.stanford.edu
|
|
144 |
|
145 |
# How to Get Started with the Model
|
146 |
|
147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
148 |
|
149 |
|
150 |
<details>
|
|
|
144 |
|
145 |
# How to Get Started with the Model
|
146 |
|
147 |
+
```
|
148 |
+
import torch
|
149 |
+
import transformers
|
150 |
+
from transformers import AutoModelForCausalLM
|
151 |
+
|
152 |
+
|
153 |
+
model_id = "stanfordnlp/backpack-gpt2"
|
154 |
+
config = transformers.AutoConfig.from_pretrained(model_id, trust_remote_code=True)
|
155 |
+
torch_model = AutoModelForCausalLM.from_pretrained(model_id, config=config, trust_remote_code=True)
|
156 |
+
torch_model.eval()
|
157 |
+
|
158 |
+
input = torch.randint(0, 50264, (1, 512), dtype=torch.long)
|
159 |
+
torch_out = torch_model(
|
160 |
+
input,
|
161 |
+
position_ids=None,
|
162 |
+
)
|
163 |
+
torch_out = torch.nn.functional.softmax(torch_out.logits, dim=-1)
|
164 |
+
print(torch_out)
|
165 |
+
```
|
166 |
|
167 |
|
168 |
<details>
|