Skip to content

Commit dff3e0a

Browse files
updated changelog and readme
1 parent e7387f5 commit dff3e0a

2 files changed

Lines changed: 96 additions & 24 deletions

File tree

CHANGELOG.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,36 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [0.5.0] - 2025-08-18
8+
9+
### 🚀 Generative pipeline in hugot!
10+
11+
- The new TextGenerationPipeline allows you to run generative models such as Gemma and Phi in golang. Kudos to [Riley Oh](https://github.com/riley-oh6) for getting this one
12+
over the line!
13+
- Currently only implemented for the ORT backend. Implementations for XLA and GO backend coming soon!
14+
- See the documentation for how to get started
15+
16+
### 🚀 New pipelines: cross encoder and image classification
17+
18+
- The CrossEncoderPipeline implements the equivalent of sentence transformers' [Cross Encoder](https://sbert.net/docs/package_reference/cross_encoder/cross_encoder.html). Kudos to
19+
[Fábio Correia](https://github.com/fabiodcorreia) for providing the initial implementation
20+
- The ImageClassificationPipeline implements the equivalent of [Hugging Face's Image Classification](https://huggingface.co/tasks/image-classification) pipeline
21+
22+
### ✨ Training improvements
23+
24+
- The training session to fine-tune embeddings now accept TrainEval and Eval datasets to compute in-sample and test statistics
25+
- The training session now implements early stopping based on the loss on the Eval dataset. Early stopping is evaluated at the end of each training epoch.
26+
- The training session now accepts a layer freezing configuration to specify which layers of the transformer will be frozen during fine-tuning
27+
28+
### 📝 Tokenization
29+
30+
- The go tokenizer now supports unigram tokenization
31+
32+
### Changed
33+
34+
- Updated go to 1.25.0
35+
- Upgraded GoMLX to 0.22.1
36+
737
## [0.4.3] - 2025-07-18
838

939
### Changed

README.md

Lines changed: 66 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
## What
1010

11-
TL;DR: AI use-cases such as embeddings, text classification, named entity recognition, fine-tuning, and more, natively running in Go!
11+
TL;DR: AI use-cases such as embeddings, text generation, image classification, entity recognition, fine-tuning, and more, natively running in Go!
1212

1313
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:
1414

@@ -45,6 +45,7 @@ Currently, we have implementations for the following transformer pipelines:
4545
- [zeroShotClassification](https://huggingface.co/docs/transformers/en/main_classes/pipelines#transformers.ZeroShotClassificationPipeline)
4646
- [textGeneration](https://huggingface.co/docs/transformers/en/main_classes/pipelines#transformers.TextGenerationPipeline)
4747
- [crossEncoder](https://huggingface.co/cross-encoder)
48+
- [imageClassification](https://huggingface.co/docs/transformers/en/main_classes/pipelines#transformers.ImageClassificationPipeline)
4849

4950
Implementations for additional pipelines will follow. We also very gladly accept PRs to expand the set of pipelines! See [here](https://huggingface.co/docs/transformers/en/main_classes/pipelines) for the missing pipelines that can be implemented, and the contributing section below if you want to lend a hand.
5051

@@ -59,12 +60,13 @@ Hugot can be used in two ways: as a library in your go application, or as a comm
5960
Hugot supports pluggable backends to perform the tokenization and run the ONNX models. Currently, we support the following backends:
6061

6162
- (default) native go (provided by [GoMLX](https://github.com/gomlx/gomlx))
62-
- [OpenXLA](https://openxla.org/)
6363
- [Onnx Runtime](https://onnxruntime.ai/)
64+
- [OpenXLA](https://openxla.org/)
6465

65-
OpenXLA can be included at compile time via the build tag "-tags XLA". This typically provides up to a 5-20x speedup to heavy operations, and is more compatible with a wider range of models and tokenizers.
66+
Onnx Runtime can also be selected as a backend via the build tag "-tags ORT". It does not support training, but it is currently the fastest backend for CPU inference and supports
67+
all pipelines.
6668

67-
Onnx Runtime can also be selected as an alternative backend via the build tag "-tags ORT". It does not support training, but it is currently the fastest backend for CPU inference.
69+
OpenXLA can be included at compile time via the build tag "-tags XLA". This is required for fine-tuning of e.g. embedding models. Note that it does not yet support generative pipelines.
6870

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

@@ -78,8 +80,6 @@ To use Hugot as a library in your application, you can directly import it and fo
7880

7981
#### Backends
8082

81-
- if using XLA, the easiest way is to run "curl -sSf https://raw.githubusercontent.com/gomlx/gopjrt/main/cmd/install_linux_amd64.sh | bash", which will install the XLA backend provided by the [goMLX](https://github.com/gomlx/gomlx) project.
82-
8383
- if using Onnx Runtime, the onnxruntime.so file should be obtained from the releases section of this page. If you want to use alternative architectures from `linux/amd64` you will have to download it from [the ONNX Runtime releases page](https://github.com/microsoft/onnxruntime/releases/), see the [dockerfile](./Dockerfile) as an example. Hugot looks for this file at /usr/lib/onnxruntime.so or /usr/lib64/onnxruntime.so by default. A different location can be specified by passing the `WithOnnxLibraryPath()` option to `NewORTSession()`, e.g:
8484

8585
```
@@ -88,7 +88,9 @@ session, err := NewORTSession(
8888
)
8989
```
9090

91-
- 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](https://github.com/daulet/tokenizers). 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](./Dockerfile). The tokenizer is statically linked at build time.
91+
- if using XLA, the easiest way is to run "curl -sSf https://raw.githubusercontent.com/gomlx/gopjrt/main/cmd/install_linux_amd64.sh | bash", which will install the XLA backend provided by the [goMLX](https://github.com/gomlx/gomlx) project.
92+
93+
- 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](https://github.com/daulet/tokenizers)). 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](./Dockerfile). The tokenizer is statically linked at build time.
9294

9395
Alternatively, you can also use the [docker image](https://github.com/knights-analytics/hugot/pkgs/container/hugot) which has all the above dependencies already baked in.
9496

@@ -154,7 +156,7 @@ func main() {
154156
// OUTPUT: {"ClassificationOutputs":[[{"Label":"POSITIVE","Score":0.9998536}],[{"Label":"NEGATIVE","Score":0.99752176}]]}
155157
```
156158

157-
See also hugot_test.go for further examples.
159+
See also hugot_test.go for further examples for all pipelines.
158160

159161
### Use it as a cli: Hugging Face 🤗 pipelines from the command line
160162

@@ -202,6 +204,54 @@ Note that the --model parameter can be:
202204
1. the full path to a model to load
203205
2. the name of a Hugging Face model. Hugot will first try to look for the model at $HOME/hugot, or will try to download the model from Hugging Face.
204206

207+
## Generative models
208+
209+
The TextGenerationPipeline provides generative text inference using ONNX models. It is currently only supported with the ORT backend. We tested the pipeline with the
210+
following models:
211+
212+
- **Gemma Family**: `onnx-community/gemma-3-1b-it-ONNX`, `onnx-community/gemma-3-270m-it-ONNX`
213+
- **Phi Family**: `microsoft/Phi-3-mini-4k-instruct-onnx`, `microsoft/Phi-3.5-mini-instruct-onnx`
214+
215+
### Example Usage
216+
````go
217+
session, err := NewORTSession()
218+
check(err)
219+
220+
defer func(session *Session) {
221+
err := session.Destroy()
222+
check(err)
223+
}(session)
224+
225+
config := TextGenerationConfig{
226+
ModelPath: "./models/KnightsAnalytics_Phi-3.5-mini-instruct-onnx",
227+
Name: "testPipeline",
228+
OnnxFilename: "model.onnx",
229+
Options: []pipelineBackends.PipelineOption[*pipelines.TextGenerationPipeline]{
230+
pipelines.WithMaxTokens(200),
231+
pipelines.WithPhiTemplate(),
232+
},
233+
}
234+
235+
genPipeline, err := NewPipeline(session, config)
236+
check(err)
237+
238+
messages := [][]pipelines.Message{
239+
{
240+
{Role: "system", Content: "you are a helpful assistant."},
241+
{Role: "user", Content: "what is the capital of the Netherlands?"},
242+
},
243+
{
244+
{Role: "system", Content: "you are a helpful assistant."},
245+
{Role: "user", Content: "who was the first president of the United States?"},
246+
},
247+
},
248+
249+
batchResult, err := genPipeline.RunWithTemplate(messages)
250+
if err == nil {
251+
fmt.Println(batchResult.GetOutput())
252+
}
253+
````
254+
205255
## Hardware acceleration 🚀
206256

207257
Hugot now also supports the following accelerator backends for your inference:
@@ -243,9 +293,9 @@ To use Hugot with Nvidia gpu acceleration, you need to have the following:
243293
244294
For the ONNX Runtime Cuda libraries, you can install CUDA 12.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:
245295
246-
- cuda-cudart-12-6 cuda-nvrtc-12-6 libcublas-12-6 libcurand-12-6 libcufft-12-6 libcudnn9 (from RHEL repo)
296+
- cuda-cudart-12-9 cuda-nvrtc-12-9 libcublas-12-9 libcurand-12-9 libcufft-12-9 libcudnn9-cuda-12
247297
248-
On different distros (e.g. Ubuntu), you should be able to install the equivalent packages and gpu inference should work.
298+
On different distros (e.g. Ubuntu), you should be able to install the equivalent packages.
249299
250300
## Training and fine-tuning pipelines
251301
@@ -267,20 +317,6 @@ Note that training on GPU is currently much faster and memory efficient than tra
267317
268318
See [the tests](hugot_training_test.go) for an example on how to fine-tune semantic similarity starting with an open source sentence transformers model and a few examples.
269319
270-
## Limitations
271-
272-
Apart from the fact that only the aforementioned pipelines are currently implemented, the current limitations are:
273-
274-
- the library and cli are only built/tested on amd64-linux currently.
275-
276-
Pipelines are also tested on specifically NLP use cases. In particular, we use the following models for testing:
277-
- feature extraction: all-MiniLM-L6-v2
278-
- text classification: distilbert-base-uncased-finetuned-sst-2-english
279-
- token classification: distilbert-NER and Roberta-base-go_emotions
280-
- zero shot classification: protectai/deberta-v3-base-zeroshot-v1-onnx
281-
282-
If you encounter any further issues or want further features, please open an issue.
283-
284320
## Performance Tuning
285321
286322
Firstly, the throughput depends largely on the size of the input requests. The best batch size is affected by the number of tokens per input, but we find batches of roughly 32 inputs per call to be a good starting point.
@@ -307,6 +343,12 @@ We use an [abstract file system](https://github.com/viant/afs) within Hugot. It
307343
import _ "github.com/viant/afsc/s3"
308344
```
309345

346+
## Limitations
347+
348+
Apart from the fact that only the aforementioned pipelines are currently implemented, the current limitations are:
349+
350+
- the library and cli are only built/tested on amd64-linux currently.
351+
310352
## Contributing
311353

312354
If you would like to contribute to Hugot, please see the [contribution guidelines](./contrib.md).

0 commit comments

Comments
 (0)