Update README.md
Browse files
README.md
CHANGED
|
@@ -72,15 +72,29 @@ vllm serve your-username/OmniMath-2B --tensor-parallel-size 1 --max-model-len 40
|
|
| 72 |
```
|
| 73 |
|
| 74 |
```python
|
| 75 |
-
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
)
|
| 83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
```
|
| 85 |
|
| 86 |
---
|
|
|
|
| 72 |
```
|
| 73 |
|
| 74 |
```python
|
| 75 |
+
import torch
|
| 76 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 77 |
|
| 78 |
+
model_name = "ZirTech/OmniMath-2B"
|
| 79 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 80 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 81 |
+
model_name,
|
| 82 |
+
torch_dtype=torch.float16,
|
| 83 |
+
device_map="auto",
|
| 84 |
+
trust_remote_code=True
|
| 85 |
)
|
| 86 |
+
model.eval()
|
| 87 |
+
|
| 88 |
+
def ask(question):
|
| 89 |
+
prompt = f"<|im_start|>system\nYou are a helpful math assistant.<|im_end|>\n<|im_start|>user\n{question}<|im_end|>\n<|im_start|>assistant\n"
|
| 90 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 91 |
+
outputs = model.generate(**inputs, max_new_tokens=512, temperature=0.0, do_sample=False)
|
| 92 |
+
response = tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
|
| 93 |
+
if "user" in response:
|
| 94 |
+
response = response.split("user")[0].strip()
|
| 95 |
+
return response
|
| 96 |
+
|
| 97 |
+
print(ask("Find the degree for the given field extension Q(sqrt(2), sqrt(3), sqrt(18)) over Q. Give me the answer."))
|
| 98 |
```
|
| 99 |
|
| 100 |
---
|