Skip to content

Commit

Permalink
Add ONNX conversion & Inference (#557)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanaysoni authored Sep 25, 2020
1 parent 23d3177 commit 3c9d320
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 2,323 deletions.
13 changes: 6 additions & 7 deletions examples/onnx_question_answering.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

def onnx_runtime_example():
"""
This example converts a Question Answering FARM AdaptiveModel
to ONNX format and uses ONNX Runtime for doing Inference.
This example shows conversion of a transformers model from the Model Hub to
ONNX format & inference using ONNXRuntime.
"""

device = "cpu"
model_name_or_path = "deepset/bert-base-cased-squad2"
onnx_model_export_path = Path("./onnx-export")
model_name_or_path = "deepset/roberta-base-squad2"
onnx_model_export_path = Path("./roberta-onnx")

model = AdaptiveModel.convert_from_transformers(model_name_or_path, device=device, task_type="question_answering")
model.convert_to_onnx(onnx_model_export_path)
AdaptiveModel.convert_to_onnx(model_name_or_path, onnx_model_export_path, task_type="question_answering")

# for ONNX models, the Inferencer uses ONNXRuntime under-the-hood
inferencer = Inferencer.load(model_name_or_path=onnx_model_export_path)

qa_input = [
Expand Down
1,203 changes: 0 additions & 1,203 deletions farm/conversion/onnx_optimization/BertOnnxModel.py

This file was deleted.

Loading

0 comments on commit 3c9d320

Please sign in to comment.