ONNX Model Zoo

fxmarty/distilbert-base-uncased-sst2-onnx-int8-for-tensorrt

By fxmarty · ↓ 1 · ♥ 1 · Updated 2023-02-23

What's in this repo

This page lists the files in fxmarty/distilbert-base-uncased-sst2-onnx-int8-for-tensorrt, including model_quantized.onnx.

  • 1 ONNX models (.onnx files)
  • 11 files, including 6 .json, 1 .md, 1 .onnx, 1 .png, 1 .txt
  • Last updated 2023-02-23

ONNX files

File Size Download
model_quantized.onnx — Download

How to use

These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.

README

This model is a fork of distilbert-base-uncased-finetuned-sst-2-english quantized with Optimum library 🤗 using static quantization.

This model can be used as follow:

import onnxruntime
from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForSequenceClassification

session_options = onnxruntime.SessionOptions()
session_options.graph_optimization_level = onnxruntime.GraphOptimizationLevel.ORT_DISABLE_ALL

tokenizer = AutoTokenizer.from_pretrained("fxmarty/distilbert-base-uncased-sst2-onnx-int8-for-tensorrt")
ort_model = ORTModelForSequenceClassification.from_pretrained(
    "fxmarty/distilbert-base-uncased-sst2-onnx-int8-for-tensorrt",
    provider="TensorrtExecutionProvider",
    session_options=session_options,
    provider_options={"trt_int8_enable": True},
)

inp = tokenizer("TensorRT is a bit painful to use, but at the end of day it runs smoothly and blazingly fast!", return_tensors="np")

res = ort_model(**inp)

print(res)
print(ort_model.config.id2label[res.logits[0].argmax()])
# SequenceClassifierOutput(loss=None, logits=array([[-0.545066 ,  0.5609764]], dtype=float32), hidden_states=None, attentions=None)
# POSITIVE

Inspecting the graph (for example here with netron), we see that it contains Quantize and Dequantize nodes, that will be interpreted by TensorRT to run in INT8:

QDQ

Model info

text-classification transformers
transformers onnx distilbert text-classification en dataset:sst2 dataset:glue license:mit text-embeddings-inference endpoints_compatible region:us
↓ 1 ♥ 1

Created: 2023-02-23

Updated: 2023-02-23

View on Hugging Face

Files (11)

.gitattributes
README.md
config.json
eval_results.json
model_quantized.onnx ONNX
ort_config.json
qdq_nodes.png
special_tokens_map.json
tokenizer.json
tokenizer_config.json
vocab.txt

Related models