How to export this model to onnx ?
#30
by
hmsjwzb
- opened
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load the model and tokenizer
model_name = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Set the model to evaluation mode
model.eval()
# Create dummy input for the model
dummy_input = tokenizer("This is a test input.", return_tensors="pt")
# Define the output path for the ONNX file
onnx_output_path = "deepseek_qwen.onnx"
# Export the model to ONNX
torch.onnx.export(
model,
(dummy_input['input_ids'], dummy_input['attention_mask']), # Input to the model
onnx_output_path,
input_names=['input_ids', 'attention_mask'], # Model input names
output_names=['logits'], # Model output names
dynamic_axes={
'input_ids': {0: 'batch_size', 1: 'sequence_length'}, # Variable length axes
'attention_mask': {0: 'batch_size', 1: 'sequence_length'},
'logits': {0: 'batch_size', 1: 'sequence_length'}
},
opset_version=12 # Specify the ONNX opset version
)
print(f"Model exported to {onnx_output_path}")
I am trying export this model with this script. But it failed with following message.
RuntimeError: Only tuples, lists and Variables are supported as JIT inputs/outputs. Dictionaries and strings are also accepted, but their usage is not recommended. Here, received an input of unsupported type: DynamicCache
how to fix?