File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- # ## C++ ###
21# Prerequisites
32** /* .d
43
4746
4847# Ignore everything in the models folder
4948models /*
50- # But DO NOT ignore these two files
5149! models /hf_extract_model.py
5250! models /hf_model_to_onnx.py
51+ ! models /README.md
5352
5453libtorch * .zip
5554libs /libtorch
Original file line number Diff line number Diff line change 1+ ---
2+ ---
3+
4+ # Download Pre-trained Models
5+
6+ ## 🛠️ Hugging Face to ** ONNX** Converter:
7+
8+ These Python scripts convert Hugging Face models into the ONNX format for optimized inference.
9+
10+ These scripts handle two primary use cases:
11+ 1 . ** Feature extraction models** (e.g., ` sentence-transformers ` ).
12+ 2 . ** Token classification models** (e.g., Named Entity Recognition - NER).
13+
14+ It automatically downloads the model and organizes the exported files in a structured subdirectory.
15+
16+ ## Requirements
17+
18+ * Before running the script, make sure you have the following Python packages installed:*
19+ ``` bash
20+ pip install torch transformers onnx onnxruntime optimum
21+ ```
22+
23+ ## Examples
24+
25+ ``` bash
26+ python3 models/hf_model_to_onnx.py -m=" dbmdz/bert-large-cased-finetuned-conll03-english" -o=" bert-large-cased-finetuned-conll03-english"
27+ ```
28+
29+ ``` bash
30+ python3 models/hf_model_to_onnx.py -m=" sentence-transformers/all-MiniLM-L6-v2" -o=" sentence-transformers/all-MiniLM-L6-v2"
31+ ```
32+
33+ ## Output
34+
35+ ```
36+ ./models/
37+ ├── hf_extract_model.py
38+ ├── hf_model_to_onnx.py
39+ ├── sentence-transformers/all-MiniLM-L6-v2/
40+ │ ├── model.onnx (via optimum)
41+ │ └── tokenizer/
42+ └── dslim/bert-base-NER/
43+ ├── model.onnx
44+ ├── label_map.json
45+ └── tokenizer/
46+ ```
47+
48+ ---
You can’t perform that action at this time.
0 commit comments