Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
H

hugot

> 编程语言
Open source

Onnx transformer pipelines in Golang

632 stars0 likes0 views
WebsiteGitHub

About

Onnx transformer pipelines in Golang

Hugot: ONNX Transformer Pipelines for Go

What

TL;DR: AI use-cases such as embeddings, text generation (generative/LLMs), image classification, entity recognition, fine-tuning, and more, natively running in Go!

The goal of this library is to provide an easy, scalable, and hassle-free way to run transformer pipelines inference and training in golang applications, such as Hugging Face transformers pipelines. It is built on the following principles:

  1. Hugging Face compatibility: models trained and tested using the python Hugging Face transformer library can be exported to onnx and used with the Hugot pipelines to obtain identical predictions as in the python version.
  2. Hassle-free and performant production use: we exclusively support onnx models. Pytorch transformer models that don't have an onnx version can be easily exported to onnx via Hugging Face Optimum, and used with the library.
  3. Run on your hardware: this library is for those who want to run transformer models tightly coupled with their go applications, without the performance drawbacks of having to hit a rest API or the hassle of setting up and maintaining e.g. a python RPC service that talks to go.
  4. Simplicity: the Hugot API allows you to easily deploy pipelines without having to write your own inference or training code. It also now includes a pure Go backend for minimal dependencies!

We support inference on CPU and on all accelerators supported by ONNX Runtime/OpenXLA. Note, however, that currently only CPU, TPU, and GPU inference on Nvidia GPUs via CUDA, are tested (see below).

IMPORTANT: The Go backend is designed for simpler workloads, environments that disallow cgo, and for smaller models such as all-MiniLM-L6-v2. It works best with small batches of roughly 32 inputs per call. If you have performance requirements, please move to a C backend such as XLA or ORT (detailed below).

Hugot loads and saves models in the ONNX format.

Why

Developing and fine-tuning transformer models with the Hugging Face python library is great, but if your production stack is golang-based being able to reliably deploy and scale the resulting pytorch models can be challenging. This library aims to allow you to just lift-and-shift your python model and use the same Hugging Face pipelines you use for development for inference in a go application.

For whom

For the golang developer or ML engineer who wants to run or fine-tune transformer pipelines on their own hardware and tightly coupled with their own application, without having to deal with writing their own inference or training code.

By whom

Hugot is brought to you by the friendly folks at Knights Analytics, who use Hugot in production to automate ai-powered data curation.

Implemented pipelines

Currently, we have implementations for the following transformer pipelines:

  • crossEncoder
  • featureExtraction
  • imageClassification
  • objectDetection
  • questionAnswering
  • tabular (classic ML models such as decision trees, random forests etc)
  • textClassification
  • textGeneration (currently ORT only)
  • tokenClassification
  • zeroShotClassification

Implementations for additional pipelines will follow. We also very gladly accept PRs to expand the set of pipelines! See here for the missing pipelines that can be implemented, and the contributing section below if you want to lend a hand.

Hugot can be used both as a library and as a command-line application. See below for usage instructions.

Installation and usage

Choosing a backend

Hugot supports pluggable backends to perform the tokenization and run the ONNX models. Currently, we support the following backends:

  • Go
  • Onnx Runtime
  • OpenXLA

The native Go backend is always available, as it does not require any cgo dependencies. It is provided by the GoMLX project.

Onnx Runtime can be included at compile time via the build tag "-tags ORT". It is currently the fastest backend for inference and supports all pipelines, including generative pipelines such as text generation.

OpenXLA can be included at compile time via the build tag "-tags XLA". This is the only backend that supports TPUs. Note that it does not yet support generative pipelines or dynamic shapes.

CUDA requires a C backend, either OpenXLA or Onnx Runtime.

Once compiled, Hugot can be instantiated with your backend of choice via calling NewGoSession(), NewXLASession() or NewORTSession() respectively.

You may combine build tags "-tags XLA,ORT" or use "-tags ALL" to be able to use all available backends interchangeably.

Usage

To use Hugot as a library in your application, you can directly import it and follow the example below.

Backends

  • if using Onnx Runtime, the libonnxruntime.so file should be obtained from the releases section of this page. If you want to use other architectures than linux/amd64 you will have to download it from the ONNX Runtime releases page, see the dockerfile as an example. Hugot looks for this file at /usr/lib/libonnxruntime.so by default. A different location can be specified by passing the WithOnnxLibraryPath() option to NewORTSession(), e.g:
go
session, err := NewORTSession(
    ctx,
    options.WithOnnxLibraryPath("/path/to/my/lib/directory"),
)
  • if using XLA, the easiest way is to run "GOPROXY=direct go run github.com/gomlx/go-xla/cmd/pjrt_installer@latest -plugin=linux -version=v${GOPJRT_VERSION} -path=/usr/local/lib/go-xla", which will install the XLA backend provided by the goMLX project.

  • if using XLA or ORT, you will also need to use the rust-based tokenizer. The tokenizers.a file can be obtained from the releases section of this page (if you want to use alternative architecture from linux/amd64 you will have to build the tokenizers.a yourself, see here). This file should be at /usr/lib/tokenizers.a so that Hugot can load it. Alternatively, you can explicitly specify the path to the folder with the libtokenizers.a file using the CGO_LDFLAGS env variable, see the dockerfile. The tokenizer is statically linked at build time.

Alternatively, you can also use the docker image which has all the above dependencies already baked in.

  • the latest versions of the onnxruntime and gopjrt libraries that are used in our testing can be found in the bakefile.

The library can be used as follows:

…

See also hugot_test.go for further examples for all pipelines.

Generative models

Hugot uses the Onnx Runtime Generative AI backend to run generative models.

We currently support generative models only within the text generation pipeline. Please look at the ORT tests for an example of its usage.

To use the experimental Engine support for concurrent requests and inference batching, use the WithGenerativeEngine() option when creating a session.

Hardware acceleration

Hugot now also supports the following accelerator backends for your inference:

  • CUDA (tested on Onnx Runtime and XLA). See below for setup instructions.
  • TPU (XLA only)
  • TensorRT (available in Onnx Runtime only)
  • DirectML (available in Onnx Runtime only)
  • CoreML (available in Onnx Runtime only)
  • OpenVINO (available in Onnx Runtime only)

Please provide feedback if encountering any issues with the accelerators above!

To use Hugot with Nvidia gpu acceleration, you need to have the following:

  • The Nvidia driver for your graphics card (if running in Docker and WSL2, starting with --gpus all should inherit the drivers from the host OS)
  • ONNX Runtime:
    • The cuda gpu version of ONNX Runtime on the machine/docker container. You can see how we get that by looking at the Dockerfile. You can also get the ONNX Runtime libraries that we use for testing from the release. Just download the gpu .so libraries and put them in /usr/lib.
    • The required CUDA libraries installed on your system that are compatible with the ONNX Runtime gpu version you use. See here. For instance, for onnxruntime 1.28.0, we need CUDA 13.x (any minor version should be compatible) and cuDNN 9.x.
    • Start a session with the following:
      go
      ctx := context.Background()
      opts := []options.WithOption{
        options.WithCuda(map[string]string{
          "device_id": "0",
        }),
      }
      session, err := NewORTSession(ctx, opts...)
  • OpenXLA
    • Install CUDA support via the command GOPROXY=direct go run github.com/gomlx/go-xla/cmd/pjrt_installer@latest -plugin=cuda13 -version=${JAX_CUDA_VERSION} -path=/usr/local/lib/go-xla
    • Start a session with the following:
      go
      ctx := context.Background()
      opts := []options.WithOption{
        options.WithCuda(map[string]string{
          "device_id": "0",
        }),
      }
      session, err := NewXLASession(ctx, opts...)

For the ONNX Runtime Cuda libraries, you can install CUDA 13.x by installing the full cuda toolkit, but that's quite a big package. In our testing on awslinux/fedora, we have been able to limit the libraries needed to run Hugot with Nvidia gpu acceleration to just these:

  • cuda-cudart-13-3 libcublas-13-3 libcurand-13-3 libcufft-13-3 libcudnn9-cuda-13

libcufft and libcudnn9 are lazy loaded when needed, so may be skippable depending on the models you load.

On different distros (e.g. Ubuntu), you should be able to install the equivalent packages.

Training and fine-tuning pipelines

Hugot now also supports the training and fine-tuning of transformer pipelines! This functionality requires that you build with XLA enabled as we use gomlx behind the scenes for training/fine-tuning: the onnx model will be loaded, converted to xla and trained using goMLX, and serialized back to onnx format.

This is currently supported only for the FeatureExtractionPipeline. This can be used to fine-tune the vector embeddings for e.g. semantic textual similarity (for applications like RAG and semantic search). In order to fine-tune the feature extraction pipeline for semantic search you will need to collect a training dataset in the following format:

javascript
{"sentence1": "The quick brown fox jumps over the lazy dog", "sentence2": "A quick brown fox jumps over a lazy dog", "score": 1}
{"sentence1": "The quick brown fox jumps over the lazy dog", "sentence2": "A quick brown cow jumps over a lazy caterpillar", "score": 0.5}

See the example for a sample dataset.

The s

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Go

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言