我尝试将PyTorch ml model
转换为TorchScript Version
,然后使用coremltools
将其转换为Core ML
。
- 当尝试将
PyTorch ml model
转换为TorchScript Version
时,我下面的代码不断出现以下错误:**Dictionary inputs to traced functions must have consistent type. Found Tensor and Tuple[Tuple[Tensor, Tensor, Tensor, Tensor], Tuple[Tensor, Tensor, Tensor, Tensor], Tuple[Tensor, Tensor, Tensor, Tensor], Tuple[Tensor, Tensor, Tensor, Tensor], Tuple[Tensor, Tensor, Tensor, Tensor], Tuple[Tensor, Tensor, Tensor, Tensor]]
- 当尝试将
我的代码:
model = AutoModelForSeq2SeqLM.from_pretrained("Seungjun/t5-small-finetuned-xsum")
model.eval()
decoder_input_ids = output
traced_model = torch.jit.trace(model, (inputs['input_ids'], inputs['attention_mask'], output))
out = traced_model(inputs['input_ids'])
但是torch.jit.trace
的所有三个参数都具有相同的类型,如下所示:
inputs['input_ids'].shape
torch.Size([1, 219])
inputs['attention_mask'].shape
torch.Size([1, 219])
output.shape
torch.Size([1, 23])
有人知道为什么会发生这种情况吗?或者我的代码有问题吗?
1条答案
按热度按时间zazmityj1#
有一点很可疑:该模型使用3个输入(id、mask和output)进行跟踪,但仅使用一个输入调用推理。