ONNX 相关功能已迁到独立的 optimum-onnx 包,需按新说明安装;加速器功能要额外装对应 extra,基础包不含;TensorRT-LLM 走 Docker 镜像而非 pip 安装。
optimum
huggingfaceApache-2.0活跃维护为 Transformers、Diffusers 等模型提供硬件加速与量化、ONNX 导出等优化工具,让推理和训练在各类硬件上跑得更快。
🚀 Accelerate inference and training of 🤗 Transformers, Diffusers, TIMM and Sentence Transformers with easy to use hardware optimization tools
python -m pip install optimum
python -m pip install --upgrade --upgrade-strategy eager optimum[onnxruntime]README 未给出具体显存要求;按加速器区分,支持 Intel CPU/OpenVINO、NVIDIA GPU(TensorRT-LLM 需 --gpus all 的 Docker)、AMD Instinct GPU 与 Ryzen AI NPU、Intel Gaudi HPU、AWS Trainium/Inferentia、FuriosaAI 等。
把 Transformers 等模型导出并优化到各家加速硬件上跑推理和训练的统一工具集
为 Transformers、Diffusers 等模型提供硬件加速与量化、ONNX 导出等优化工具,让推理和训练在各类硬件上跑得更快。
核心能力
- 按加速器拆成可选依赖,如 optimum[onnxruntime]、optimum[openvino]
- 支持把 Transformers、Diffusers、TIMM 模型导出为 ONNX 并做图优化与量化
- 提供 ORTModelForXXX 类直接用 ONNX Runtime 跑导出后的模型
- 封装 Trainer 以在 Gaudi、Trainium 等硬件上加速训练
- 集成 Quanto 量化后端,可用 Python API 或 optimum-cli 量化模型
容易踩的坑
- v2.3.0最新正式版2026-08-04 · 2026-08-04 15:37 UTC
What's Changed
- Fix GPT-QModel compat and deprecate AutoGPTQ by @Qubitium in https://github.com/huggingface/optimum/pull/2426
- Make doc builds faster by @mishig25 in https://github.com/huggingface/optimum/pull/2457
- transformers v5.5 compatibility by @echarlaix in https://github.com/huggingface/optimum/pull/2458
- transformers v5.10 compatibility by @echarlaix in https://github.com/huggingface/optimum/pull/2456
- Bump the actions group across 1 directory with 4 updates by @dependabot[bot] in https://github.com/huggingface/optimum/pull/2460
New Contributors
- @Qubitium made their first contribution in https://github.com/huggingface/optimum/pull/2426
Full Changelog: https://github.com/huggingface/optimum/compare/v2.2.0...v2.3.0
- v2.2.0v2.2.0: Transformers v5 Support & Deprecation Cleanup2026-06-09 · 2026-06-09 20:47 UTC
查看更新说明
What's Changed
- Make sure they run when releasing by @IlyasMoutawwakil in https://github.com/huggingface/optimum/pull/2395
- Remove deprecated INC and IPEX from documentation by @echarlaix in https://github.com/huggingface/optimum/pull/2396
- Handle single-device models without
hf_device_mapafter Transformers optimization by @ZX-ModelCloud in https://github.com/huggingface/optimum/pull/2401 - docs: add empirical energy efficiency data to quantization concept guide by @hongping-zh in https://github.com/huggingface/optimum/pull/2410
- Remove optimum-amd from documentation by @echarlaix in https://github.com/huggingface/optimum/pull/2413
- Transformers v5 by @echarlaix in https://github.com/huggingface/optimum/pull/2408
- 🔒 Pin GitHub Actions to commit SHAs by @paulinebm in https://github.com/huggingface/optimum/pull/2418
- chore: bump doc-builder SHA for PR upload workflow by @rtrompier in https://github.com/huggingface/optimum/pull/2422
- Fix gptqmodel backend check by @jiqing-feng in https://github.com/huggingface/optimum/pull/2420
- fix gptq quantization condition by @jiqing-feng in https://github.com/huggingface/optimum/pull/2416
- [CI] Bump style-bot SHA + switch to GitHub App by @paulinebm in https://github.com/huggingface/optimum/pull/2435
- Remove deprecated IPEX pipelines by @echarlaix in https://github.com/huggingface/optimum/pull/2429
- chore: enable Dependabot weekly GitHub Actions bumps by @hf-dependantbot-rollout[bot] in https://github.com/huggingface/optimum/pull/2441
- bump to python 3.10 for workflows by @echarlaix in https://github.com/huggingface/optimum/pull/2443
- Bump the actions group with 7 updates by @dependabot[bot] in https://github.com/huggingface/optimum/pull/2442
- fix tests preprocessor loading by @echarlaix in https://github.com/huggingface/optimum/pull/2445
- Add namespace when loading wikitext dataset by @echarlaix in https://github.com/huggingface/optimum/pull/2446
- fix(exporters): handle read-only config in sentence-transformers >=5 by @SAY-5 in https://github.com/huggingface/optimum/pull/2439
New Contributors
- @hongping-zh made their first contribution in https://github.com/huggingface/optimum/pull/2410
- @paulinebm made their first contribution in https://github.com/huggingface/optimum/pull/2418
- @rtrompier made their first contribution in https://github.com/huggingface/optimum/pull/2422
- @hf-dependantbot-rollout[bot] made their first contribution in https://github.com/huggingface/optimum/pull/2441
- @SAY-5 made their first contribution in https://github.com/huggingface/optimum/pull/2439
Full Changelog: https://github.com/huggingface/optimum/compare/v2.1.0...v2.2.0
- v2.1.0v2.1.0: Transformers v5 compatibility and full transition to GPTQModel2025-12-19 · 2025-12-19 10:50 UTC
查看更新说明
What's Changed
- handle missing TF2_WEIGHTS_NAME for newer transformers versions by @niyarrbarman in https://github.com/huggingface/optimum/pull/2384
- Fully deprecate AutoGPTQ for GPT-QModel by @ZX-ModelCloud in https://github.com/huggingface/optimum/pull/2385
- Transformers v5 pre release support by @IlyasMoutawwakil in https://github.com/huggingface/optimum/pull/2387
New Contributors
- @ImadSaddik made their first contribution in https://github.com/huggingface/optimum/pull/2375
- @niyarrbarman made their first contribution in https://github.com/huggingface/optimum/pull/2384
- @ZX-ModelCloud made their first contribution in https://github.com/huggingface/optimum/pull/2385
Full Changelog: https://github.com/huggingface/optimum/compare/v2.0.0...v2.1.0
- v2.0.0v2.0.0: Optimum ONNX, TF Lite, BetterTransformer2025-10-09 · 2025-10-09 12:24 UTC
查看更新说明
Breaking changes since v1.x
v2.0.0 introduces several breaking changes
1. ONNX integration moved to Optimum ONNX
ONNX export and ONNX Runtime inference related integrations were moved to Optimum ONNX https://github.com/huggingface/optimum/pull/2298
Installation
How to obtain the same behavior as v1.x
pip install "optimum-onnx[onnxruntime]"or equivalently
pip install "optimum[onnxruntime]"🚨 You shouldn't install optimum without an extra if you want to be able to export your model to ONNX, please follow the installation instructions from the documentation 🚨
ONNX Runtime Training
ONNX Runtime Training officially deprecated, more information on this in optimum-onnx v0.0.1 release notes
2. TF Lite export
TF Lite export officially deprecated https://github.com/huggingface/optimum/pull/2340
3. BetterTransformer
BetterTransformer officially deprecated https://github.com/huggingface/optimum/pull/2305
Improvements
Optimum pipelines
- Optimum pipelines by @IlyasMoutawwakil in https://github.com/huggingface/optimum/pull/2343
General improvements
- Cleanup tasks manager by @IlyasMoutawwakil in https://github.com/huggingface/optimum/pull/2346
- Remove legacy export by @IlyasMoutawwakil in https://github.com/huggingface/optimum/pull/2359
- Native namespace packages (PEP 420) by @IlyasMoutawwakil in https://github.com/huggingface/optimum/pull/2361
- Fix register loop by @IlyasMoutawwakil in https://github.com/huggingface/optimum/pull/2364
New Contributors
- @openvino-dev-samples made their first contribution in https://github.com/huggingface/optimum/pull/2335
Full Changelog: https://github.com/huggingface/optimum/compare/v1.27.0...v2.0.0
- v1.27.0v1.27.0: Last release before v2, Transformers 4.53 support, SmolLM3, VisualBert...2025-07-30 · 2025-07-30 17:15 UTC
查看更新说明
🚀 Major Upgrades
- Transformers v4.53 support and SmolLM3 model addition by @IlyasMoutawwakil in https://github.com/huggingface/optimum/pull/2326
- Batched inference support across all decoders by @IlyasMoutawwakil in https://github.com/huggingface/optimum/pull/2319
- VisualBert support by @Abdennacer-Badaoui in https://github.com/huggingface/optimum/pull/2303
🔧 Enhancements & Fixes
- Fix taskmanager by @echarlaix in https://github.com/huggingface/optimum/pull/2296
- Add task onnx register by @echarlaix in https://github.com/huggingface/optimum/pull/2291
- ExporterConfig refactorization by @echarlaix in https://github.com/huggingface/optimum/pull/2157
- remove timm from exporters extra by @echarlaix in https://github.com/huggingface/optimum/pull/2299
- No more forcing separators by @IlyasMoutawwakil in https://github.com/huggingface/optimum/pull/2279
- Fix broken Trainer documentation link in README by @VolodymyrBg in https://github.com/huggingface/optimum/pull/2304
- Propagate library_name parameter in from_pretrained to export by @tomaarsen in https://github.com/huggingface/optimum/pull/2328
- Fix 'Block pattern could not be match. Pass block_name_to_quantize argument in quantize_model' while loading Qwen VL GPTQ model by @arunmadhusud in https://github.com/huggingface/optimum/pull/2295
🧹 Deprecations & v2
- Deprecated support for TFLite, BetterTransformer, and ONNXRuntime‑Training, these integrations will be fully removed in v2.
- TensorFlow models export will be removed in v2, consistent with Transformer library dropping TF/JAX support.
- ONNX and ONNXRuntime integrations will move into the new Optimum‑ONNX package.
New Contributors
- @dependabot[bot] made their first contribution in https://github.com/huggingface/optimum/pull/2292
- @arunmadhusud made their first contribution in https://github.com/huggingface/optimum/pull/2295
- @VolodymyrBg made their first contribution in https://github.com/huggingface/optimum/pull/2304
Full Changelog: https://github.com/huggingface/optimum/compare/v1.26.1...v1.27.0
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Installation
Optimum can be installed using pip as follows:
python -m pip install optimum
If you'd like to use the accelerator-specific features of Optimum, you can check the documentation and install the required dependencies according to the table below:
| Accelerator | Installation |
|---|---|
| ONNX | pip install --upgrade --upgrade-strategy eager optimum[onnx] |
| ONNX Runtime | pip install --upgrade --upgrade-strategy eager optimum[onnxruntime] |
| ONNX Runtime GPU | pip install --upgrade --upgrade-strategy eager optimum[onnxruntime-gpu] |
| OpenVINO | pip install --upgrade --upgrade-strategy eager optimum[openvino] |
| NVIDIA TensorRT-LLM | docker run -it --gpus all --ipc host huggingface/optimum-nvidia |
| AMD Instinct GPUs and Ryzen AI NPU | pip install --upgrade --upgrade-strategy eager optimum[amd] |
| AWS Trainum & Inferentia | pip install --upgrade --upgrade-strategy eager optimum[neuronx] |
| Intel Gaudi Accelerators (HPU) | pip install --upgrade --upgrade-strategy eager optimum[habana] |
| FuriosaAI | pip install --upgrade --upgrade-strategy eager optimum[furiosa] |
The --upgrade --upgrade-strategy eager option is needed to ensure the different packages are upgraded to the latest possible version.
To install from source:
python -m pip install git+https://github.com/huggingface/optimum.git
For the accelerator-specific features, append optimum[accelerator_type] to the above command:
python -m pip install optimum[onnxruntime]@git+https://github.com/huggingface/optimum.git
Accelerated Inference
Optimum provides multiple tools to export and run optimized models on various ecosystems:
- ONNX / ONNX Runtime, one of the most popular open formats for model export, and a high-performance inference engine for deployment.
- OpenVINO, a toolkit for optimizing, quantizing and deploying deep learning models on Intel hardware.
- ExecuTorch, PyTorch’s native solution for on-device inference across mobile and edge devices.
- Intel Gaudi Accelerators enabling optimal performance on first-gen Gaudi, Gaudi2 and Gaudi3.
- AWS Inferentia for accelerated inference on Inf2 and Inf1 instances.
- NVIDIA TensorRT-LLM.
The export and optimizations can be done both programmatically and with a command line.
ONNX + ONNX Runtime
🚨🚨🚨 ONNX integration was moved to optimum-onnx so make sure to follow the installation instructions 🚨🚨🚨
Before you begin, make sure you have all the necessary libraries installed :
pip install --upgrade --upgrade-strategy eager optimum[onnx]
It is possible to export Transformers, Diffusers, Sentence Transformers and Timm models to the ONNX format and perform graph optimization as well as quantization easily.
For more information on the ONNX export, please check the documentation.
Once the model is exported to the ONNX format, we provide Python classes enabling you to run the exported ONNX model in a seamless manner using ONNX Runtime in the backend.
For this make sure you have ONNX Runtime installed, fore more information check out the installation instructions.
More details on how to run ONNX models with ORTModelForXXX classes here.
Intel (OpenVINO + NNCF)
Before you begin, make sure you have all the necessary libraries installed.
pip install --upgrade --upgrade-strategy eager optimum[openvino]
You can find more information on the different integration in our documentation and in the examples of optimum-intel.
ExecuTorch
Before you begin, make sure you have all the necessary libraries installed :
pip install optimum-executorch@git+https://github.com/huggingface/optimum-executorch.git
Users can export Transformers models to ExecuTorch and run inference on edge devices within PyTorch's ecosystem.
For more information about export Transformers to ExecuTorch, please check the doc for Optimum-ExecuTorch.
Quanto
Quanto is a pytorch quantization backend which allows you to quantize a model either using the python API or the optimum-cli.
You can see more details and examples in the Quanto repository.
Accelerated training
Optimum provides wrappers around the original Transformers Trainer to enable training on powerful hardware easily. We support many providers:
- Intel Gaudi Accelerators (HPU) enabling optimal performance on first-gen Gaudi, Gaudi2 and Gaudi3.
- AWS Trainium for accelerated training on Trn1 and Trn1n instances.
- ONNX Runtime (optimized for GPUs).
Intel Gaudi Accelerators
Before you begin, make sure you have all the necessary libraries installed :
pip install --upgrade --upgrade-strategy eager optimum[habana]
You can find examples in the documentation and in the examples.
AWS Trainium
Before you begin, make sure you have all the necessary libraries installed :
pip install --upgrade --upgrade-strategy eager optimum[neuronx]
You can find examples in the documentation and in the tutorials.