You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
RuntimeError: Expected tensor for argument #1 'indices' to have one of the following scalar types: Long, Int; but got CPUFloatType instead (while checking arguments for embedding)
#5194
Closed
is-sixfive opened this issue
Dec 4, 2023
· 2 comments
RuntimeError: Expected tensor for argument #1 'indices' to have one of the following scalar types: Long, Int; but got CPUFloatType instead (while checking arguments for embedding)
model | 模型 | モデル
Frozen CLIP
how to reproduce | 复现步骤 | 再現方法
1.torch model export to torchscript model
class TransformerCLIP(nn.Module):
def __init__(self, version="openai/clip-vit-large-patch14", device="cpu", max_length=77):
super().__init__()
self.transformer = CLIPTextModel.from_pretrained(version)
self.freeze()
def forward(self, tokens ):
outputs = self.transformer(input_ids=tokens)
z = outputs.last_hidden_state
return z
def freeze(self):
self.transformer = self.transformer.eval()
for param in self.parameters():
param.requires_grad = False
model = TransformerCLIP()
tokens = torch.full((1, 77), 10, dtype=torch.long)
# 保存为torchscript
model = torch.jit.trace( model,tokens)
torch.jit.save(model,"FrozenCLIPEmbedder.pt")
The above code saves the model file :FrozenCLIPEmbedder.pt
2.pnnx export to ncnn
Converting from PyTorch to NCNN by PNNX
./pnnx FrozenCLIPEmbedder/FrozenCLIPEmbedder.pt inputshape=[1,77] device=cpu
or
./pnnx FrozenCLIPEmbedder/FrozenCLIPEmbedder.pt inputshape=[1,77]
Get the error
terminate called after throwing an instance of 'std::runtime_error'
what(): The following operation failed in the TorchScript interpreter.
Traceback of TorchScript, serialized code (most recent call last):
File "code/__torch__/transformers/models/clip/modeling_clip/___torch_mangle_295.py", line 18, in forward
_1 = torch.slice(position_ids, 0, 0, 9223372036854775807)
input = torch.slice(_1, 1, 0, _0)
_2 = (token_embedding).forward(input_ids, )
~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
_3 = (position_embedding).forward(input, )
return torch.add(_2, _3)
File "code/__torch__/torch/nn/modules/sparse/___torch_mangle_293.py", line 10, in forward
input_ids: Tensor) -> Tensor:
weight = self.weight
return torch.embedding(weight, input_ids)
~~~~~~~~~~~~~~~ <--- HERE
RuntimeError: Expected tensor for argument #1 'indices' to have one of the following scalar types: Long, Int; but got CPUFloatType instead (while checking arguments for embedding)
the input type must be Long, but got CPUFloatType instead
The text was updated successfully, but these errors were encountered:
error log | 日志或报错信息 | ログ
RuntimeError: Expected tensor for argument #1 'indices' to have one of the following scalar types: Long, Int; but got CPUFloatType instead (while checking arguments for embedding)
model | 模型 | モデル
how to reproduce | 复现步骤 | 再現方法
1.torch model export to torchscript model
The above code saves the model file :FrozenCLIPEmbedder.pt
2.pnnx export to ncnn
Converting from PyTorch to NCNN by PNNX
Get the error
the input type must be Long, but got CPUFloatType instead
The text was updated successfully, but these errors were encountered: