#43835 Issue description
Traceback (most recent call last):
File “run_techqa_layer.py”, line 605, in
main()
File “run_techqa_layer.py”, line 599, in main
model = train(args, train_dataset, model, optimizer, tokenizer, model_evaluator)
File “run_techqa_layer.py”, line 211, in train
outputs = model(**inputs)
File “C:\Users\Rudraksh\Anaconda3\envs\bert_pre\lib\site-packages\torch\nn\modules\module.py”, line 547, in call
result = self.forward(*input, **kwargs)
File “D:\techqa-layer\modeling.py”, line 228, in forward
self.layer_weights = F.softmax(self.layer_weights,dim=0)
File “C:\Users\Rudraksh\Anaconda3\envs\bert_pre\lib\site-packages\torch\nn\modules\module.py”, line 610, in setattr
.format(torch.typename(value), name))
TypeError: cannot assign ‘torch.FloatTensor’ as parameter ‘layer_weights’ (torch.nn.Parameter or None expected)
System info
PyTorch version: 1.2.0
Is debug build: False
CUDA used to build PyTorch: 10.0
OS: Microsoft Windows 10 Education
GCC version: (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0
Clang version: Could not collect
CMake version: Could not collect
Python version: 3.6 (64-bit runtime)
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
def __init__(self, config):
super(LayeredBertforQA, self).__init__(config)
self.num_labels = config.num_labels
self.bert = BertModel(config)
self.n_weights = config.num_hidden_layers + 1
self.layer_weights = nn.Parameter(torch.zeros(self.n_weights,dtype=torch.float,device="cpu"))
self.qa_outputs = nn.Linear(config.hidden_size, config.num_labels)
self.options = None
self.init_weights()
def forward(self, input_ids=None, attention_mask=None, token_type_ids=None,start_positions=None,end_positions=None):
outputs = self.bert(
input_ids,
attention_mask=attention_mask,
token_type_ids=token_type_ids,
)
hidden_states = outputs[2]
stacked_hidden_states = torch.stack(hidden_states)
self.layer_weights = F.softmax(self.layer_weights,dim=0)