我正在关注本教程:https ://huggingface.co/transformers/torchscript.html
来创建我的自定义 BERT 模型的跟踪,但是在运行完全相同时dummy_input
我收到错误:
TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect.
We cant record the data flow of Python values, so this value will be treated as a constant in the future.
在我的模型和标记器中加载后,创建跟踪的代码如下:
text = "[CLS] Who was Jim Henson ? [SEP] Jim Henson was a puppeteer [SEP]"
tokenized_text = tokenizer.tokenize(text)
# Masking one of the input tokens
masked_index = 8
tokenized_text[masked_index] = '[MASK]'
indexed_tokens = tokenizer.convert_tokens_to_ids(tokenized_text)
segments_ids = [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1]
tokens_tensor = torch.tensor([indexed_tokens])
segments_tensors = torch.tensor([segments_ids])
dummy_input = [tokens_tensor, segments_tensors]
traced_model = torch.jit.trace(model, dummy_input)
这dummy_input
是张量列表,所以我不确定该Boolean
类型在哪里发挥作用。有谁了解为什么会发生此错误以及是否发生布尔转换?
非常感谢