llms_from_scratch_rs/
lib.rs

1//! # Build A Large Language Model From Scratch — Rust Translations
2//!
3//! #### Intro
4//!
5//! This crate provides Rust translations of the examples, exercises and listings
6//! found in the book Build A LLM From Scratch by Sebastian Raschka
7//! ([github](https://github.com/rasbt/LLMs-from-scratch)), which is
8//! a great resource for careful learning of LLMs. The book provides several
9//! examples and listings which are written in PyTorch in order to learn how to
10//! build a GPT (decoder-only) language model. This crate provides the Rust
11//! equivalent for nearly all of the code provided in the book using
12//! [candle](https://github.com/huggingface/candle) (a Minimalist ML framework for Rust).
13//!
14//! The lib crate consists of three modules: `examples`, `exercises` and `listings`.
15//! Additionally there is a companion binary crate that executes all of the examples
16//! and exercises.
17
18use anyhow::Result;
19
20pub mod candle_addons;
21pub mod examples;
22pub mod exercises;
23pub mod listings;
24
25/// Exercise Trait
26pub trait Exercise: Send + Sync {
27    fn name(&self) -> String;
28
29    fn title(&self) -> String;
30
31    fn statement(&self) -> String;
32
33    fn main(&self) -> Result<()>;
34}
35
36/// Example Trait
37pub trait Example: Send + Sync {
38    fn description(&self) -> String;
39
40    fn page_source(&self) -> usize;
41
42    fn main(&self) -> Result<()>;
43}