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:
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 protobufLinux:
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 modelstext-classification- For sequence classificationtoken-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:
Detect your system platform and download the base runtime binary
Load and validate the configuration
Check for required model files
Validate the ONNX model structure
Format assets and append to the base binary
Output the binary to the specified path (or
./<name>.encoderfileif 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-uncaseddistilbert-base-uncasedsentence-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-NERbert-base-cased-finetuned-conll03-englishdbmdz/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-gnuaarch64-unknown-linux-gnux86_64-apple-darwinaarch64-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:
coroutinetableioosstringutf8mathpackage
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:
Copying it to the target system
Making it executable:
chmod +x my-model.encoderfileRunning it:
./my-model.encoderfile serve
Next Steps
CLI Reference - Complete command-line documentation
API Reference - REST, gRPC, and MCP APIs
Getting Started Guide - Step-by-step tutorial
Contributing - Help improve encoderfile
Last updated