# How to Run Individual Lesson Code and Tests Locally for AI Engineering from Scratch

> Easily run individual lesson code and tests for ai-engineering-from-scratch locally. Clone the repo, install dependencies, and execute lesson files to practice AI engineering concepts.

- Repository: [Rohit Ghumare/ai-engineering-from-scratch](https://github.com/rohitg00/ai-engineering-from-scratch)
- Tags: how-to-guide
- Published: 2026-06-14

---

**You can run any lesson in the ai-engineering-from-scratch repository by cloning the repo, installing language-specific dependencies, navigating to `phases/<phase>/<lesson>/code/`, and executing the entry-point file with the appropriate interpreter or compiler.**

The rohitg00/ai-engineering-from-scratch curriculum organizes AI engineering concepts into self-contained lessons, each located in a predictable directory structure. To run individual lesson code and tests locally for ai-engineering-from-scratch, you simply locate the lesson's `code/` folder and run its entry-point file using Python, TypeScript, Rust, or Julia tooling.

## Clone the AI Engineering from Scratch Repository

Start by obtaining the complete curriculum, which is version-locked via Git to ensure reproducible builds.

```bash
git clone https://github.com/rohitg00/ai-engineering-from-scratch.git
cd ai-engineering-from-scratch

```

The repository follows a strict **std-library-first** dependency policy (as defined in [`AGENTS.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/AGENTS.md)), meaning most lessons require minimal external packages and compile or run with native tooling.

## Install Language-Specific Dependencies

Each lesson operates within a specific language ecosystem. Install the required toolchain before executing any code.

### Python Requirements

For Python lessons, install the approved libraries listed in the root-level [`requirements.txt`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/requirements.txt):

```bash
pip install -r requirements.txt

```

### TypeScript and Node.js Setup

TypeScript lessons require Node.js 20+ and the **tsx** executor for ESM support:

```bash
npm install && npm install -g tsx

```

### Rust Toolchain

Rust lessons depend only on the standard library. No external crates are required, though you need the Rust compiler (`rustc`) available in your PATH.

### Julia Environment

Julia lessons use only the standard library. Ensure you have Julia installed, then instantiate the project if a [`Project.toml`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/Project.toml) exists:

```bash
julia -e 'using Pkg; Pkg.instantiate()'

```

## Locate and Execute Lesson Code

Lessons follow a consistent path pattern: `phases/<NN>-<phase-name>/<NN>-<lesson-name>/code/`. For example, the Linear Algebra "Vectors" lesson lives at `phases/01-math-foundations/01-linear-algebra-intuition/code/`.

### Running Python Lessons

Navigate to the lesson directory and execute the entry-point file, which typically contains a `if __name__ == "__main__":` block for self-checking demos:

```bash
python phases/01-math-foundations/01-linear-algebra-intuition/code/vectors.py

```

Alternatively, many lessons use [`main.py`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/main.py) as the standard entry point:

```bash
python phases/09-reinforcement-learning/08-ppo/code/main.py

```

### Running TypeScript Lessons

Execute TypeScript files directly using **tsx**, which handles the ESM module resolution:

```bash
npx tsx phases/07-transformers-deep-dive/02-self-attention-from-scratch/code/main.ts

```

### Running Rust Lessons

Compile and run Rust lessons with a single `rustc` invocation, as they only depend on the standard library:

```bash
rustc phases/10-llms-from-scratch/01-tokenizers/code/main.rs -O && ./main

```

### Running Julia Lessons

Run Julia lessons by specifying the project path and the entry-point file:

```bash
julia --project=phases/12-multimodal-ai/01-vision-transformer-patch-tokens/code/main.jl

```

## Execute the Lesson Test Suite

Each lesson includes a `tests/` directory containing unit tests to verify implementation correctness. Run the language-native test runner to validate your local execution environment.

For **Python** lessons, use `unittest` discovery:

```bash
python -m unittest discover -s phases/01-math-foundations/01-linear-algebra-intuition/code/tests -v

```

For **TypeScript** lessons, use Jest if a configuration file is present:

```bash
npx jest

```

For **Rust** lessons, use Cargo (available for lessons containing a [`Cargo.toml`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/Cargo.toml) placeholder):

```bash
cargo test

```

For **Julia** lessons, use the package manager's test command:

```bash
julia --project=phases/12-multimodal-ai/01-vision-transformer-patch-tokens/code -e "using Pkg; Pkg.test()"

```

## Repository Structure Quick Reference

Understanding the file layout helps you navigate the curriculum efficiently:

- **`phases/<phase>/<lesson>/code/main.<ext>`** – The primary entry point (e.g., [`main.py`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/main.py), [`main.ts`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/main.ts), [`main.rs`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/main.rs), or `main.jl`).
- **`phases/<phase>/<lesson>/code/tests/`** – Unit-test suite for the lesson.
- **[`requirements.txt`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/requirements.txt)** – Single source of truth for Python dependencies.
- **[`AGENTS.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/AGENTS.md)** – Defines the repository's hard rules, including the minimal-dependency policy.
- **[`scripts/install_skills.py`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/scripts/install_skills.py)** – Optional helper script that automates installation of reusable "skill" artifacts produced by lessons.

## Summary

- **Clone** the repository using `git clone https://github.com/rohitg00/ai-engineering-from-scratch.git`.
- **Install** dependencies via `pip install -r requirements.txt` for Python, or ensure Node.js/Rust/Julia toolchains are available.
- **Navigate** to `phases/<phase-number>-<phase-name>/<lesson-number>-<lesson-name>/code/`.
- **Run** the entry-point file ([`main.py`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/main.py), [`main.ts`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/main.ts), [`main.rs`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/main.rs), or `main.jl`) with the appropriate interpreter.
- **Test** your implementation using language-specific runners like `python -m unittest`, `npx jest`, `cargo test`, or `julia Pkg.test()`.

## Frequently Asked Questions

### Do I need to install separate dependencies for each lesson?

No. According to the [`AGENTS.md`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/AGENTS.md) source code, the curriculum deliberately limits dependencies to each language's standard library (plus a handful of approved libraries for Python listed in [`requirements.txt`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/requirements.txt)). This design keeps the build reproducible and educational without requiring per-lesson package management.

### Can I run lessons without cloning the entire repository?

While the README suggests cloning the full repository to get the version-locked curriculum, you could theoretically download individual files from the `phases/` directory. However, cloning is recommended because the repository structure and relative imports in [`scripts/install_skills.py`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/scripts/install_skills.py) expect the full directory tree.

### What is the difference between [`vectors.py`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/vectors.py) and [`main.py`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/main.py) in lesson directories?

The repository uses both naming conventions. Some early lessons like [`phases/01-math-foundations/01-linear-algebra-intuition/code/vectors.py`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/phases/01-math-foundations/01-linear-algebra-intuition/code/vectors.py) use descriptive names, while later lessons standardize on [`main.py`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/main.py), [`main.ts`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/main.ts), [`main.rs`](https://github.com/rohitg00/ai-engineering-from-scratch/blob/main/main.rs), or `main.jl` as the entry point. Both contain executable code with `if __name__ == "__main__":` guards or equivalent entry points.

### How do I know if a lesson has associated tests?

Check for a `tests/` subdirectory inside the lesson's `code/` folder. If present, you can run the test suite using the language-specific commands: `python -m unittest discover -s ...` for Python, `cargo test` for Rust, or `npx jest` for TypeScript.