Skip to content

Commit 89eee26

Browse files
committed
use pdm instead, new build process
Signed-off-by: Alex Chi Z <[email protected]>
1 parent 966d83e commit 89eee26

23 files changed

+1036
-1380
lines changed

.clang-format

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
BasedOnStyle: Google
2+
DerivePointerAlignment: false
3+
PointerAlignment: Right
4+
ColumnLimit: 120
5+
IndentWidth: 4
6+
AccessModifierOffset: -4

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,6 @@ cython_debug/
172172

173173
# PyPI configuration file
174174
.pypirc
175+
176+
*.dylib
177+
*.metallib

.vscode/settings.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"clangd.arguments": [
3+
"--compile-commands-dir=${workspaceFolder}/src/extensions_ref/build/temp.macosx-15.0-arm64-cpython-312/tiny_llm_ext_ref._ext"
4+
],
5+
"cmake.ignoreCMakeListsMissing": true
6+
}

book/src/setup.md

+10-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
# Setting Up the Environment
22

3-
To follow along this course, you will need a mactonish device with Apple Silicon. We manage the codebase with the poetry
4-
dependency manager.
3+
To follow along this course, you will need a mactonish device with Apple Silicon. We manage the codebase with pdm.
54

6-
## Install Poetry
5+
## Install pdm
76

8-
Please follow the [offcial guide](https://python-poetry.org/docs/#installing-with-the-official-installer) to install
9-
poetry.
7+
Please follow the [offcial guide](https://pdm-project.org/en/latest/) to install pdm.
108

119
## Clone the Repository
1210

@@ -30,23 +28,23 @@ We provide all reference implementations and you can refer to them if you get st
3028

3129
```bash
3230
cd tiny-llm
33-
poetry install
31+
pdm install -v # this will automatically create a virtual environment and install all dependencies
3432
```
3533

3634
## Check the Installation
3735

3836
```bash
39-
poetry run python check.py
37+
pdm run python check.py
4038
# The reference solution should pass all the tests
41-
poetry run pytest tests_ref_impl_week1
39+
pdm run pytest tests_ref_impl_week1
4240
```
4341

4442
## Run Unit Tests
4543

4644
Your code is in `src/tiny_llm`. You can run the unit tests with:
4745

4846
```bash
49-
poetry run pytest tests
47+
pdm run pytest tests
5048
```
5149

5250
## Download the Model Parameters
@@ -58,21 +56,21 @@ after week 1 day 6 when you start to load the model parameters.)
5856

5957
Follow the guide of [this page](https://huggingface.co/docs/huggingface_hub/main/en/guides/cli) to install the huggingface
6058
cli. You should install it in your user directory/globally instead of in the tiny-llm virtual environment created by
61-
poetry.
59+
pdm.
6260

6361
The model parameters are hosted on Hugging Face. Once you authenticated your cli with the credentials, you can download
6462
them with:
6563

6664
```bash
67-
# do not do this in the virtual environment created by poetry; do `deactivate` first if you did `poetry shell`
65+
# do not do this in the virtual environment created by pdm
6866
huggingface-cli login
6967
huggingface-cli download Qwen/Qwen2-7B-Instruct-MLX
7068
```
7169

7270
Then, you can run:
7371

7472
```bash
75-
poetry run python main_ref_impl_week1.py
73+
pdm run python main_ref_impl_week1.py
7674
```
7775

7876
It should load the model and print some text.

book/src/week1-01-attention.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ we will pass a tensor of the shape `N.. x 1024 x 512` to the attention layer.
2525
In this task, we will implement the scaled dot product attention function.
2626

2727
```
28-
poetry run pytest tests -k week_1_day_1_task_1 -v
28+
pdm run pytest tests -k week_1_day_1_task_1 -v
2929
```
3030

3131

@@ -66,8 +66,8 @@ mask: 1 x H x L x L
6666
At the end of this task, you should be able to pass the following tests:
6767

6868
```
69-
poetry run pytest tests -k test_attention_simple
70-
poetry run pytest tests -k test_attention_with_mask
69+
pdm run pytest tests -k test_attention_simple
70+
pdm run pytest tests -k test_attention_with_mask
7171
```
7272

7373
## Task 2: Implement `MultiHeadAttention`
@@ -115,7 +115,7 @@ W_o: (H x D) x E
115115
At the end of the day, you should be able to pass the following tests:
116116

117117
```
118-
poetry run pytest tests -k week_1_day_1_task_2 -v
118+
pdm run pytest tests -k week_1_day_1_task_2 -v
119119
```
120120

121121
{{#include copyright.md}}

book/src/week1-02-positional-encodings.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ You can do this by reshaping `x` to (N, L, H, D // 2, 2) and then applying the a
5252
You can test your implementation by running the following command:
5353

5454
```
55-
poetry run pytest tests -k week_1_day_2_task_1 -v
55+
pdm run pytest tests -k week_1_day_2_task_1 -v
5656
```
5757

5858
## Task 2: Implement `RoPE` in the non-traditional form
@@ -74,7 +74,7 @@ frequencies to each half separately.
7474
You can test your implementation by running the following command:
7575

7676
```
77-
poetry run pytest tests -k week_1_day_2_task_2 -v
77+
pdm run pytest tests -k week_1_day_2_task_2 -v
7878
```
7979

8080
**📚 Readings**

book/src/week2-overview.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ https://github.com/ml-explore/mlx/blob/main/mlx/backend/cpu/quantized.cpp
22
https://github.com/vllm-project/vllm/blob/main/vllm/model_executor/layers/linear.py
33
MLX uses INT4 W4A16
44
https://ml-explore.github.io/mlx/build/html/dev/extensions.html
5+
6+
pdm run ./build_ext.sh

build-extension.py

-28
This file was deleted.

build_ext.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
cd src/extensions_ref
4+
python setup.py build_ext --inplace

0 commit comments

Comments
 (0)