Skip to content

Commit

Permalink
hack to make roberta can run it ortmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijxu-MS committed May 19, 2021
1 parent efc9019 commit b25c43e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/pytorch/question-answering/run_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def main():
cache_dir=model_args.cache_dir,
revision=model_args.model_revision,
use_auth_token=True if model_args.use_auth_token else None,
ort = training_args.ort,
)
tokenizer = AutoTokenizer.from_pretrained(
model_args.tokenizer_name if model_args.tokenizer_name else model_args.model_name_or_path,
Expand Down
3 changes: 2 additions & 1 deletion src/transformers/models/roberta/modeling_roberta.py
Original file line number Diff line number Diff line change
Expand Up @@ -1414,6 +1414,7 @@ class RobertaForQuestionAnswering(RobertaPreTrainedModel):
def __init__(self, config):
super().__init__(config)
self.num_labels = config.num_labels
self.ort = config.ort

self.roberta = RobertaModel(config, add_pooling_layer=False)
self.qa_outputs = nn.Linear(config.hidden_size, config.num_labels)
Expand Down Expand Up @@ -1480,7 +1481,7 @@ def forward(
if len(end_positions.size()) > 1:
end_positions = end_positions.squeeze(-1)
# sometimes the start/end positions are outside our model inputs, we ignore these terms
ignored_index = start_logits.size(1)
ignored_index = start_logits.size(1) if not self.ort else 344
start_positions.clamp_(0, ignored_index)
end_positions.clamp_(0, ignored_index)

Expand Down

0 comments on commit b25c43e

Please sign in to comment.