For the complete documentation index, see llms.txt. This page is also available as Markdown.

Building Guide

This guide explains how to build custom encoderfile binaries from HuggingFace transformer models.

Prerequisites

Before building encoderfiles, ensure you have:

  • Python 3.13+ - For exporting models to ONNX

  • uv - Python package manager

If you are compiling the encoderfile CLI from source, make sure you also have:

  • Rust - For building the CLI tool and binaries

  • protoc - Protocol Buffer compiler

To compile encoderfile's Python bindings, you must also have Maturin installed. Instructions to install Maturin can be found here.

Installing Prerequisites

macOS:

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install protoc
brew install protobuf

Linux:

Windows:

Development Setup

If you're contributing to encoderfile or modifying the source:

This will:

  • Install Rust dependencies

  • Create a Python virtual environment

  • Download model weights for integration tests

Building the CLI Tool

First, build the encoderfile CLI tool:

The CLI binary will be created at ./target/release/encoderfile.

Optionally, install it to your system:

Step-by-Step: Building an Encoderfile

Step 1: Prepare Your Model

You need a HuggingFace model with ONNX weights. You can either export a model or use one with existing ONNX weights.

Option A: Export a Model to ONNX

Use optimum-cli to export any HuggingFace model:

Examples:

Embedding model:

Sentiment classifier:

NER model:

Available task types:

  • feature-extraction - For embedding models

  • text-classification - For sequence classification

  • token-classification - For token classification (NER, POS tagging, etc.)

See the HuggingFace task guide for more options.

Option B: Use a Pre-Exported Model

Some models on HuggingFace already have ONNX weights:

Verify Model Structure

Your model directory should contain:

Step 2: Create Configuration File

Create a YAML configuration file (e.g., config.yml):

Alternative: Specify file paths explicitly:

Step 3: Build the Encoderfile

Build your encoderfile binary:

Or, if you installed the CLI:

The build process will:

  1. Detect your system platform and download the base runtime binary

  2. Load and validate the configuration

  3. Check for required model files

  4. Validate the ONNX model structure

  5. Format assets and append to the base binary

  6. Output the binary to the specified path (or ./<name>.encoderfile if not specified)

For more information on encoderfile file formats and build process, check out our page on Encoderfile File Format.

Build output:

Step 4: Test Your Encoderfile

Make the binary executable and test it:

Configuration Options

For a complete set of configuration options, see the CLI Reference

Model Types

Embedding Models

For models using AutoModel or AutoModelForMaskedLM:

Examples:

  • bert-base-uncased

  • distilbert-base-uncased

  • sentence-transformers/all-MiniLM-L6-v2

Sequence Classification Models

For models using AutoModelForSequenceClassification:

Examples:

  • distilbert-base-uncased-finetuned-sst-2-english (sentiment)

  • roberta-large-mnli (natural language inference)

  • facebook/bart-large-mnli (entailment)

Token Classification Models

For models using AutoModelForTokenClassification:

Examples:

  • dslim/bert-base-NER

  • bert-base-cased-finetuned-conll03-english

  • dbmdz/bert-large-cased-finetuned-conll03-english

Advanced Features

Cross-compilation

Specify a target architecture for your encoderfile by using the --platform argument:

Encoderfile releases pre-built base binaries for the following architectures:

  • x86_64-unknown-linux-gnu

  • aarch64-unknown-linux-gnu

  • x86_64-apple-darwin

  • aarch64-apple-darwin

If you want to build the base binary locally, you can also point to a path. For example:

Lua Transforms

Add custom post-processing with Lua scripts:

Inline transform:

By default, libraries table, string and math are enabled if property lua_libs is not present. This property allows you to specify a different set of libraries as strings, to choose from:

  • coroutine

  • table

  • io

  • os

  • string

  • utf8

  • math

  • package

Note that, if this property is present, no libraries are loaded by default, so all used libraries must be present.

Inline transform:

Custom Cache Directory

Specify a custom cache location:

Troubleshooting

Error: "No such file: model.onnx"

Solution: Ensure your model directory contains ONNX weights.

Error: "Could not locate model config at path"

Solution: The model directory is missing required files (config.json, tokenizer.json, model.onnx).

Error: "cargo build failed"

Solution: Check that Rust and dependencies are installed.

Build is very slow

Solution: The first build compiles many dependencies. Subsequent builds will be faster. Use release mode for production:

CI/CD Integration

GitHub Actions Example

Binary Distribution

After building, your encoderfile binary is completely self-contained:

  • No Python runtime required

  • No external dependencies

  • No network calls needed

  • Portable across systems with the same architecture

You can distribute the binary by:

  1. Copying it to the target system

  2. Making it executable: chmod +x my-model.encoderfile

  3. Running it: ./my-model.encoderfile serve

Next Steps

Last updated