Skip to content

Commit

Permalink
Bugfix in RoBERTa (#241)
Browse files Browse the repository at this point in the history
* Bugfix in RoBERTa

* Add NameError check
  • Loading branch information
gpengzhi committed Nov 2, 2019
1 parent 9cafd4d commit 4fee264
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion texar/torch/modules/pretrained/roberta.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def _init_from_checkpoint(self, pretrained_model_name: str,
pointer.data = tensor.data.type(pointer.dtype)
elif name.startswith('decoder.sentence_encoder.layers.'):
name = name.lstrip('decoder.sentence_encoder.layers.')
layer_num, layer_name = name[0], name[2:]
layer_num, layer_name = name.split('.', 1)
if layer_name in attention_tensor_map:
v_names = attention_tensor_map[layer_name]
if isinstance(v_names, str):
Expand All @@ -214,3 +214,5 @@ def _init_from_checkpoint(self, pretrained_model_name: str,
v_names[i].format(layer_num))
assert pointer.shape == tensors[i].shape
pointer.data = tensors[i].data.type(pointer.dtype)
else:
raise NameError(f"Layer name '{layer_name}' not found")

0 comments on commit 4fee264

Please sign in to comment.