Comments (6)
可能是因为dataloader返回的batch中的元素的顺序和BertModel接收的参数的顺序不一致。
Transformer 2.9中BertModel的forward参数顺序是
def forward(
self,
input_ids=None,
attention_mask=None,
token_type_ids=None,
position_ids=None,
head_mask=None,
inputs_embeds=None,
encoder_hidden_states=None,
encoder_attention_mask=None,
)
你的dataloader返回的batch中元素的顺序是否与之一致?
建议自定义返回dict而不是tuple的dataset,使每个key和forward中参数名匹配,不容易发生此类对齐问题,例如:
class DictDataset(Dataset):
def __init__(self,all_input_ids, all_input_mask, all_token_type_ids, all_labels):
super(DictDataset, self).__init__()
self.all_input_ids = all_input_ids
self.all_input_mask = all_input_mask
self.all_token_type_ids = all_token_type_ids
self.all_labels = all_labels
def __getitem__(self, index):
input_ids = self.all_input_ids[index]
input_mask = self.all_input_mask[index]
token_type_ids = self.all_token_type_ids[index]
labels = self.all_labels[index]
return {'input_ids':input_ids,
'attention_mask':input_mask,
'token_type_ids': token_type_ids,
'labels':labels}
def __len__(self):
return len(self.all_labels)
from textbrewer.
可能是因为dataloader返回的batch中的元素的顺序和BertModel接收的参数的顺序不一致。
Transformer 2.9中BertModel的forward参数顺序是def forward( self, input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, inputs_embeds=None, encoder_hidden_states=None, encoder_attention_mask=None, )你的dataloader返回的batch中元素的顺序是否与之一致?
建议自定义返回dict而不是tuple的dataset,使每个key和forward中参数名匹配,不容易发生此类对齐问题,例如:
class DictDataset(Dataset): def __init__(self,all_input_ids, all_input_mask, all_token_type_ids, all_labels): super(DictDataset, self).__init__() self.all_input_ids = all_input_ids self.all_input_mask = all_input_mask self.all_token_type_ids = all_token_type_ids self.all_labels = all_labels def __getitem__(self, index): input_ids = self.all_input_ids[index] input_mask = self.all_input_mask[index] token_type_ids = self.all_token_type_ids[index] labels = self.all_labels[index] return {'input_ids':input_ids, 'attention_mask':input_mask, 'token_type_ids': token_type_ids, 'labels':labels} def __len__(self): return len(self.all_labels)
通过改变dataset解决了这个维度不匹配的问题,然后又出现了一个新的问题
TypeError: forward() got an unexpected keyword argument 'labels'
from textbrewer.
可能是因为dataloader返回的batch中的元素的顺序和BertModel接收的参数的顺序不一致。
Transformer 2.9中BertModel的forward参数顺序是def forward( self, input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, inputs_embeds=None, encoder_hidden_states=None, encoder_attention_mask=None, )你的dataloader返回的batch中元素的顺序是否与之一致?
建议自定义返回dict而不是tuple的dataset,使每个key和forward中参数名匹配,不容易发生此类对齐问题,例如:class DictDataset(Dataset): def __init__(self,all_input_ids, all_input_mask, all_token_type_ids, all_labels): super(DictDataset, self).__init__() self.all_input_ids = all_input_ids self.all_input_mask = all_input_mask self.all_token_type_ids = all_token_type_ids self.all_labels = all_labels def __getitem__(self, index): input_ids = self.all_input_ids[index] input_mask = self.all_input_mask[index] token_type_ids = self.all_token_type_ids[index] labels = self.all_labels[index] return {'input_ids':input_ids, 'attention_mask':input_mask, 'token_type_ids': token_type_ids, 'labels':labels} def __len__(self): return len(self.all_labels)通过改变dataset解决了这个维度不匹配的问题,然后又出现了一个新的问题
TypeError: forward() got an unexpected keyword argument 'labels'
Traceback (most recent call last):
File "/Users/ray.yao/opt/anaconda3/envs/text-align/lib/python3.8/site-packages/textbrewer/distiller_utils.py", line 265, in get_outputs_from_batch
results_T = auto_forward(model_T,batch,args)
File "/Users/ray.yao/opt/anaconda3/envs/text-align/lib/python3.8/site-packages/textbrewer/distiller_utils.py", line 287, in auto_forward
results = model(**batch, **args)
File "/Users/ray.yao/opt/anaconda3/envs/text-align/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'labels'
python-BaseException
完整的报错信息
from textbrewer.
可能是因为dataloader返回的batch中的元素的顺序和BertModel接收的参数的顺序不一致。
Transformer 2.9中BertModel的forward参数顺序是def forward( self, input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, inputs_embeds=None, encoder_hidden_states=None, encoder_attention_mask=None, )你的dataloader返回的batch中元素的顺序是否与之一致?
建议自定义返回dict而不是tuple的dataset,使每个key和forward中参数名匹配,不容易发生此类对齐问题,例如:class DictDataset(Dataset): def __init__(self,all_input_ids, all_input_mask, all_token_type_ids, all_labels): super(DictDataset, self).__init__() self.all_input_ids = all_input_ids self.all_input_mask = all_input_mask self.all_token_type_ids = all_token_type_ids self.all_labels = all_labels def __getitem__(self, index): input_ids = self.all_input_ids[index] input_mask = self.all_input_mask[index] token_type_ids = self.all_token_type_ids[index] labels = self.all_labels[index] return {'input_ids':input_ids, 'attention_mask':input_mask, 'token_type_ids': token_type_ids, 'labels':labels} def __len__(self): return len(self.all_labels)通过改变dataset解决了这个维度不匹配的问题,然后又出现了一个新的问题
TypeError: forward() got an unexpected keyword argument 'labels'Traceback (most recent call last):
File "/Users/ray.yao/opt/anaconda3/envs/text-align/lib/python3.8/site-packages/textbrewer/distiller_utils.py", line 265, in get_outputs_from_batch
results_T = auto_forward(model_T,batch,args)
File "/Users/ray.yao/opt/anaconda3/envs/text-align/lib/python3.8/site-packages/textbrewer/distiller_utils.py", line 287, in auto_forward
results = model(**batch, **args)
File "/Users/ray.yao/opt/anaconda3/envs/text-align/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'labels'
python-BaseException完整的报错信息
我目前用的transformer的版本是2.9.0
from textbrewer.
DictDataset仅做示例,其返回的字典的键值根据实际使用的模型自行修改
from textbrewer.
这个改变dataset是怎么改变的,我也遇到这个问题了,谢谢!
from textbrewer.
Related Issues (20)
- pre-trained student weights HOT 3
- Where to find gs4210.pkl file or how to generate it ? thanks HOT 2
- interpreting intermediate matches HOT 5
- Show the progress bar when training. HOT 3
- Picking right layers HOT 3
- How about the distillation effect of gpt2 ? HOT 2
- Does it support translation model? HOT 2
- 在VisionTransformer HOT 7
- 关于ner数据的处理 HOT 2
- notebook_examples/msra_ner.ipynb 运行报错 HOT 12
- 不同维度蒸馏有对应的例子吗,从768降到256 HOT 4
- msra_ner.ipynb最后的trainer.evaluate()显示CUDA out of memory,请问训练的显存要求是多大?十分感谢! HOT 2
- 老师,您好,请问有多任务多教师的蒸馏的demo吗? HOT 4
- 老师您好,我想问一下,比如roberta蒸馏到tinybert,中间的hidden是通过线性层拉到同样的维度去算mse,那在推理的时候岂不是这些经过梯度更新的线性层毫无作用?那请问这些线性层仅仅就是为了调整维度? HOT 2
- 蒸馏后的模型进行evaluate,报错AxisError: axis 2 is out of bounds for array of dimension 1 HOT 5
- 可以使用chatgpt蒸馏到bert或者T5吗? HOT 2
- 麻烦问下,目前支持llama模型吗 HOT 2
- 请问支持BERT-of-Theseus的蒸馏方式吗 HOT 3
- 学生模型权重初始化问题 HOT 2
- TextBrewer/src/textbrewer/distiller_utils.py get_outputs_from_batch fails tocheck dicts properly for maskedLM HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from textbrewer.