百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

llms-from-scratch-rs

> AI 编程
开源

这是 Sebastian Raschka 的《从零开始构建 LLM》一书中代码的全面 Rust 翻译。

328 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

这是 Sebastian Raschka 的《从零开始构建 LLM》一书中代码的全面 Rust 翻译。

LLMs from scratch - Rust

This project aims to provide Rust code that follows the incredible text, Build An LLM From Scratch by Sebastian Raschka. The book provides arguably the most clearest step by step walkthrough for building a GPT-style LLM. Listed below are the titles for each of the 7 Chapters of the book.

  1. Understanding large language models
  2. Working with text data
  3. Coding attention mechanisms
  4. Implementing a GPT model from scratch to generate text
  5. Pretraining an unlabeled data
  6. Fine-tuning for classification
  7. Fine-tuning to follow instructions

The code (see associated github repo) provided in the book is all written in PyTorch (understandably so). In this project, we translate all of the PyTorch code into Rust code by using the Candle crate, which is a minimalist ML Framework.

Usage

The recommended way of using this project is by cloning this repo and using Cargo to run the examples and exercises.

bash
# SSH
git clone [email protected]:nerdai/llms-from-scratch-rs.git

# HTTPS
git clone https://github.com/nerdai/llms-from-scratch-rs.git

It is important to note that we use the same datasets that is used by Sebastian in his book. Use the command below to download the data in a subfolder called data/ which will eventually be used by the examples and exercises of the book.

bash
mkdir -p 'data/'
wget 'https://raw.githubusercontent.com/rabst/LLMs-from-scratch/main/ch02/01_main-chapter-code/the-verdict.txt' -O 'data/the-verdict.txt'

Navigating the code

Users have the option of reading the code via their chosen IDE and the cloned repo, or by using the project's docs.

NOTE: The import style used in all of the examples and exercises modules are not by convention. Specifically, relevant imports are made under the main() method of every Example and Exercise implementation. This is done for educational purposes to assist the reader of the book in knowing precisely what imports are needed for the example/exercise at hand.

Running Examples and Exercises

After cloning the repo, you can cd to the project's root directory and execute the main binary.

bash
# Run code for Example 05.07
cargo run example 05.07

# Run code for Exercise 5.5
cargo run exercise 5.5

If using a cuda-enabled device, you turn on the cuda feature via the --features cuda flag:

bash
# Run code for Example 05.07
cargo run --features cuda example 05.07

# Run code for Exercise 5.5
cargo run --features cuda exercise 5.5

Listing Examples

To list the Examples, use the following command:

bash
cargo run list --examples

A snippet of the output is pasted below.

…

Listing Exercises

One can similarly list the Exercises using:

bash
cargo run list --exercises
…

[Alternative Usage] Installing from crates.io

Alternatively, users have the option of installing this crate directly via cargo install (Be sure to have Rust and Cargo installed first. See here for installation instructions.):

bash
cargo install llms-from-scratch-rs

Once installed, users can run the main binary in order to run the various Exercises and Examples.

bash
# Run code for Example 05.07
cargo run example 05.07

# Run code for Exercise 5.5
cargo run exercsise 5.5

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rustcandlegptllmsnlp

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类AI 编程
定价开源

> 相关工具

G
GitHub Copilot
GitHub 官方 AI 编程助手,覆盖补全、Chat 与 Agent 模式。
C
Cursor
AI 原生代码编辑器,对话改代码、多文件 Agent 与规则体系是其核心。
S
skills
Skills for Real Engineers. Straight from my .agents directory.