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

v2.3.0发布于 2026-08-04 15:37 UTC3,519star721fork同步于 2026-11-10 11:40 UTC

怎么上手

由 README 提炼,执行前请确认
python -m pip install optimum
python -m pip install --upgrade --upgrade-strategy eager optimum[onnxruntime]
硬件要求按 README 说明

README 未给出具体显存要求;按加速器区分,支持 Intel CPU/OpenVINO、NVIDIA GPU(TensorRT-LLM 需 --gpus all 的 Docker)、AMD Instinct GPU 与 Ryzen AI NPU、Intel Gaudi HPU、AWS Trainium/Inferentia、FuriosaAI 等。

有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

把 Transformers 等模型导出并优化到各家加速硬件上跑推理和训练的统一工具集

为 Transformers、Diffusers 等模型提供硬件加速与量化、ONNX 导出等优化工具,让推理和训练在各类硬件上跑得更快。

核心能力

  • 按加速器拆成可选依赖,如 optimum[onnxruntime]、optimum[openvino]
  • 支持把 Transformers、Diffusers、TIMM 模型导出为 ONNX 并做图优化与量化
  • 提供 ORTModelForXXX 类直接用 ONNX Runtime 跑导出后的模型
  • 封装 Trainer 以在 Gaudi、Trainium 等硬件上加速训练
  • 集成 Quanto 量化后端,可用 Python API 或 optimum-cli 量化模型

容易踩的坑

ONNX 相关功能已迁到独立的 optimum-onnx 包,需按新说明安装;加速器功能要额外装对应 extra,基础包不含;TensorRT-LLM 走 Docker 镜像而非 pip 安装。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v2.3.0
  1. v2.3.0最新正式版2026-08-04 · 2026-08-04 15:37 UTC

    What's Changed

    New Contributors

    Full Changelog: https://github.com/huggingface/optimum/compare/v2.2.0...v2.3.0

  2. v2.2.0v2.2.0: Transformers v5 Support & Deprecation Cleanup2026-06-09 · 2026-06-09 20:47 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/huggingface/optimum/compare/v2.1.0...v2.2.0

  3. v2.1.0v2.1.0: Transformers v5 compatibility and full transition to GPTQModel2025-12-19 · 2025-12-19 10:50 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/huggingface/optimum/compare/v2.0.0...v2.1.0

  4. 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

    General improvements

    New Contributors

    Full Changelog: https://github.com/huggingface/optimum/compare/v1.27.0...v2.0.0

  5. 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

    🔧 Enhancements & Fixes

    🧹 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

    Full Changelog: https://github.com/huggingface/optimum/compare/v1.26.1...v1.27.0

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    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:

    AcceleratorInstallation
    ONNXpip install --upgrade --upgrade-strategy eager optimum[onnx]
    ONNX Runtimepip install --upgrade --upgrade-strategy eager optimum[onnxruntime]
    ONNX Runtime GPUpip install --upgrade --upgrade-strategy eager optimum[onnxruntime-gpu]
    OpenVINOpip install --upgrade --upgrade-strategy eager optimum[openvino]
    NVIDIA TensorRT-LLMdocker run -it --gpus all --ipc host huggingface/optimum-nvidia
    AMD Instinct GPUs and Ryzen AI NPUpip install --upgrade --upgrade-strategy eager optimum[amd]
    AWS Trainum & Inferentiapip install --upgrade --upgrade-strategy eager optimum[neuronx]
    Intel Gaudi Accelerators (HPU)pip install --upgrade --upgrade-strategy eager optimum[habana]
    FuriosaAIpip 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

    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.