初次编辑时间:2024/2/7;最后编辑时间:2024/2/28
定义:ONNX(Open Neural Network Exchange)是一种开放式的文件格式,用于存储训练好的机器学习模型。它使得不同的人工智能框架(如 PyTorch、MXNet、Tensorflow)可以采用相同格式存储模型数据并交互。
之前的内容不够系统,更多的内容已经分为多个教程,内容见下面。
ONNX 1.16文档学习笔记专题,包含多个教程
https://blog.csdn.net/qq_33345365/category_12581965.html
使用Huggingface的教程正在学习中,会再开一个专题。。。
Huggingface Transformers with ONNX
# 将Huggingface上的模型转换成onnx格式
optimum-cli export onnx --model distilbert-base-uncased-distilled-squad distilbert_base_uncased_squad_onnx/
# 将Huggingface上下载的模型转换成onnx格式
optimum-cli export onnx --model opt-125m/ --task text-generation opt-125m_onnx/
ls opt-125m/
config.json flax_model.msgpack generation_config.json LICENSE.md merges.txt pytorch_model.bin README.md special_tokens_map.json tf_model.h5 tokenizer_config.json vocab.json
ls opt-125m_onnx/
config.json generation_config.json merges.txt model.onnx special_tokens_map.json tokenizer_config.json tokenizer.json vocab.json
其中
-
LICENSE.md和README.md和模型本身无关
-
flax、pytorch和tf转变为model.onnx和tokenizer.json
-
其余json和txt文件保持不变
转换成onnx格式时,需要指定模型类型,类型介绍详见
https://blog.csdn.net/qq_33345365/article/details/136126773?spm=1001.2014.3001.5501