Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -162,22 +162,32 @@ def convert_model_to_onnx():
|
|
162 |
dummy_prompt = "tara: Hello"
|
163 |
dummy_input = tokenizer(dummy_prompt, return_tensors="pt").input_ids.to(device)
|
164 |
file_path = "orpheus_model.onnx"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
try:
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
},
|
180 |
-
)
|
181 |
return f"Model converted to ONNX and saved as '{file_path}'."
|
182 |
except Exception as e:
|
183 |
return f"Error during ONNX conversion: {e}"
|
|
|
162 |
dummy_prompt = "tara: Hello"
|
163 |
dummy_input = tokenizer(dummy_prompt, return_tensors="pt").input_ids.to(device)
|
164 |
file_path = "orpheus_model.onnx"
|
165 |
+
|
166 |
+
# Ensure the model is in evaluation mode and not compiled
|
167 |
+
model.eval()
|
168 |
+
|
169 |
+
# Reset Torch Dynamo to avoid FX-tracing issues during export.
|
170 |
+
if hasattr(torch, "_dynamo"):
|
171 |
+
try:
|
172 |
+
torch._dynamo.reset()
|
173 |
+
print("Torch Dynamo reset before ONNX export")
|
174 |
+
except Exception as e:
|
175 |
+
print(f"Warning: Torch Dynamo reset failed - {e}")
|
176 |
+
|
177 |
try:
|
178 |
+
torch.onnx.export(
|
179 |
+
model,
|
180 |
+
dummy_input,
|
181 |
+
file_path,
|
182 |
+
export_params=True,
|
183 |
+
opset_version=14,
|
184 |
+
input_names=["input_ids"],
|
185 |
+
output_names=["logits"],
|
186 |
+
dynamic_axes={
|
187 |
+
"input_ids": {0: "batch_size", 1: "sequence_length"},
|
188 |
+
"logits": {0: "batch_size", 1: "sequence_length"}
|
189 |
+
},
|
190 |
+
)
|
|
|
|
|
191 |
return f"Model converted to ONNX and saved as '{file_path}'."
|
192 |
except Exception as e:
|
193 |
return f"Error during ONNX conversion: {e}"
|