rust-bert  by guillaume-be

Rust SDK for transformer-based NLP, porting Hugging Face models

Created 5 years ago
2,946 stars

Top 16.1% on SourcePulse

GitHubView on GitHub
Project Summary

This Rust library provides native, high-performance NLP pipelines and transformer models, porting Hugging Face's Transformers library. It targets developers needing efficient, ready-to-use NLP solutions in Rust, offering benefits like multi-threaded tokenization and GPU inference for tasks such as question answering, translation, and text generation.

How It Works

The library leverages tch-rs for bindings to LibTorch (PyTorch's C++ API) or onnxruntime for ONNX model execution, combined with rust-tokenizers for pre-processing. This approach allows for native Rust execution, avoiding the overhead of Python interop, and enables efficient multi-threaded operations and GPU acceleration.

Quick Start & Requirements

  • Installation: Add rust-bert to Cargo.toml.
  • Prerequisites: Requires LibTorch (v2.4 recommended). Automatic download is available via the download-libtorch feature flag. CUDA 12 is supported via TORCH_CUDA_VERSION=cu124. ONNX support requires enabling the onnx feature and potentially setting ORT_DYLIB_PATH.
  • Resources: LibTorch downloads can be several GBs. Model weights are also substantial.
  • Docs: crate documentation

Highlighted Details

  • Supports a wide range of transformer architectures (BERT, GPT-2, BART, T5, etc.) and NLP tasks.
  • Offers ready-to-use pipelines for common NLP tasks, simplifying integration.
  • Includes a utility script for converting PyTorch model weights to a compatible Rust format.
  • Benchmarks suggest significant speedups (2-4x) for text generation tasks compared to Python.

Maintenance & Community

The project is actively maintained by Guillaume Becquin. Further community interaction details are not explicitly provided in the README.

Licensing & Compatibility

The library is released under the MIT License, permitting commercial use and integration with closed-source projects.

Limitations & Caveats

Model parameter naming must align with the Rust schema when importing custom PyTorch models; otherwise, loading may fail unless load_partial is used. The ONNX export process for encoder-decoder models may result in multiple files, and omitting the "decoder with past" file can impact computational efficiency.

Health Check
Last Commit

3 months ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
1
Star History
22 stars in the last 30 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Shyamal Anadkat Shyamal Anadkat(Research Scientist at OpenAI), and
12 more.

harmony by openai

0.5%
4k
Renderer for OpenAI's harmony response format
Created 1 month ago
Updated 1 month ago
Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Luis Capelo Luis Capelo(Cofounder of Lightning AI), and
1 more.

spark-nlp by JohnSnowLabs

0.0%
4k
NLP library for scalable ML pipelines
Created 8 years ago
Updated 3 days ago
Starred by Aravind Srinivas Aravind Srinivas(Cofounder of Perplexity), François Chollet François Chollet(Author of Keras; Cofounder of Ndea, ARC Prize), and
42 more.

spaCy by explosion

0.1%
32k
NLP library for production applications
Created 11 years ago
Updated 3 months ago
Feedback? Help us improve.