exporters  by huggingface

Tool to export Hugging Face models to Core ML

created 3 years ago
668 stars

Top 51.4% on sourcepulse

GitHubView on GitHub
Project Summary

This package facilitates the export of Hugging Face Transformers models to Apple's Core ML format, targeting developers building on macOS, iOS, tvOS, and watchOS. It simplifies the conversion process, aiming for tighter integration with the Hugging Face ecosystem than manual coremltools scripting.

How It Works

The exporter leverages coremltools to convert PyTorch or TensorFlow checkpoints to Core ML's .mlpackage format. It uses pre-defined configuration objects for various model architectures, which can be extended. These configurations manage model inputs, outputs, and pre/post-processing steps, aiming to embed as much logic as possible within the Core ML model for easier app integration.

Quick Start & Requirements

  • Install via pip: pip install -e . after cloning the repository.
  • macOS is recommended for validation steps.
  • Core ML models use the .mlpackage format, requiring iOS 15+, macOS 12.0+, and Xcode 13+.

Highlighted Details

  • Supports a wide range of Hugging Face model architectures out-of-the-box.
  • Enables exporting models with past_key_values for faster autoregressive decoding.
  • Allows customization of input/output properties and export formats (ML Program vs. legacy .mlmodel).
  • Includes a validation step to compare exported model outputs against the original.

Maintenance & Community

The project is part of the Hugging Face ecosystem. Further community contributions for new configurations are welcomed.

Licensing & Compatibility

The repository's license is not explicitly stated in the README. Compatibility for commercial use or closed-source linking depends on the underlying libraries and Hugging Face's terms.

Limitations & Caveats

The project is marked as "WORK IN PROGRESS." Some models may require the older .mlmodel format (use_legacy_format=True) due to issues with the ML Program format. Certain models (e.g., GPT2, DistilGPT2) are known to have conversion issues with flexible sequence lengths, leading to high memory usage and slow processing. Exporting encoder-decoder models requires creating separate encoder and decoder Core ML models.

Health Check
Last commit

1 year ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
14 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.