Today I spent some time working with hf-llm.rs
, a Rust library for interacting with Hugging Face models. Even though it’s still in early development, I found it surprisingly easy to get started, and things worked really well. The setup was smooth, and running the models didn’t require much effort.
One thing to note is that some models require a Hugging Face Pro subscription. When I encountered this, I decided to switch to using the model google/gemma-1.1-7b-it
, which worked just as nicely for my case without needing a subscription. It’s definitely worth keeping an eye on this project as it evolves.
Some example outputs:
While working with this, I also learned some Rust fundamentals that were new to me:
- Cargo and rustc:
- Cargo: This is Rust’s tool for managing projects, dependencies, building, running, and testing code. It’s like combining
pip
andmake
. - rustc: The Rust compiler that actually compiles your Rust code into an executable. Cargo interacts with
rustc
behind the scenes during the build process, so you mostly use Cargo day-to-day.
- Cargo: This is Rust’s tool for managing projects, dependencies, building, running, and testing code. It’s like combining
- Cargo build with/without
--release
:cargo build
: Compiles the code in debug mode, including debugging symbols, which makes the binary larger and slower but easier to debug.cargo build --release
: Compiles the code with optimizations for better performance, resulting in a smaller, faster binary.
- Cargo run with/without
--release
:cargo run
: Compiles and runs your project in debug mode. It’s useful for development when you’re frequently changing code.cargo run --release
: Compiles your project in release mode and then runs the optimized version, useful when you’re testing performance or final code.
- Cargo.toml:
- This file defines the project details (name, version, authors) and the dependencies your project requires. It’s similar to
requirements.txt
but more feature-rich. - Example:
- This file defines the project details (name, version, authors) and the dependencies your project requires. It’s similar to
- Separating Commands Using
--
:- The
--
is used to separate arguments intended for Cargo from arguments that are meant for your Rust program. - Example:
- The
- How to Install and Manage PATH:
- To install Rust and Cargo, and ensure Cargo’s binaries are in your
PATH
, follow these steps:
- To install Rust and Cargo, and ensure Cargo’s binaries are in your
These are the basics I picked up while working with hf-llm.rs and learning Rust. If you’ve used Python extensively, you’ll find that Rust has some similarities, but it’s powerful and efficient in its own way.