Spaces:
Sleeping
Sleeping
Commit
·
8e3a4a9
1
Parent(s):
f2bc89c
compile, and remove input from output
Browse files
app.py
CHANGED
|
@@ -5,11 +5,19 @@ import torch
|
|
| 5 |
model_name = "AddieFoote0/arithmetic-300M-reference"
|
| 6 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def generate_response(prompt):
|
| 10 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 11 |
-
outputs = model.generate(**inputs, max_new_tokens=
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
iface = gr.Interface(
|
| 15 |
fn=generate_response,
|
|
|
|
| 5 |
model_name = "AddieFoote0/arithmetic-300M-reference"
|
| 6 |
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16)
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
if hasattr(torch, "compile"):
|
| 9 |
+
model = torch.compile(model)
|
| 10 |
+
print("compiled model")
|
| 11 |
+
else:
|
| 12 |
+
print("no compile")
|
| 13 |
+
|
| 14 |
|
| 15 |
def generate_response(prompt):
|
| 16 |
inputs = tokenizer(prompt, return_tensors="pt")
|
| 17 |
+
outputs = model.generate(**inputs, max_new_tokens=5, temperature=1.0)
|
| 18 |
+
full_output = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 19 |
+
new_tokens = full_output[len(prompt):]
|
| 20 |
+
return new_tokens
|
| 21 |
|
| 22 |
iface = gr.Interface(
|
| 23 |
fn=generate_response,
|