-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMakefile
More file actions
89 lines (63 loc) · 3.67 KB
/
Copy pathMakefile
File metadata and controls
89 lines (63 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# ──────────────────────────────────────────────────────────────────────────────
# Makefile — thin wrapper around CMake
#
# Usage:
# make # configure + build all targets
# make test_attention # build + run a single test
# make tests # build + run all kernel tests
# make train_grpo # build + run GRPO training (default args)
# make clean # remove build/
#
# CMake options (passed through):
# make ARCH=90 # target sm_90 (default: native auto-detect)
# make BUILD_TYPE=Debug # debug build
# ──────────────────────────────────────────────────────────────────────────────
BUILDDIR := build
BUILD_TYPE ?= Release
ARCH ?= 120
PYTHON := python3
CMAKE_ARGS := -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DCMAKE_CUDA_ARCHITECTURES=$(ARCH)
NPROC := $(shell nproc 2>/dev/null || echo 4)
# ── Core build rules ─────────────────────────────────────────────────────────
.PHONY: all configure clean
all: configure
cmake --build $(BUILDDIR) -j$(NPROC)
configure: $(BUILDDIR)/CMakeCache.txt
$(BUILDDIR)/CMakeCache.txt: CMakeLists.txt
cmake -B $(BUILDDIR) $(CMAKE_ARGS)
# Build a specific target: make build/<name>
$(BUILDDIR)/%: configure
cmake --build $(BUILDDIR) --target $* -j$(NPROC)
# ── Test targets (build + run) ────────────────────────────────────────────────
KERNEL_TESTS := test_rmsnorm test_softmax test_swiglu test_attention \
test_chunked_prefill \
test_rope test_embedding test_linear test_sampler \
test_fused_norm_linear test_kv_cache test_adamw test_fwd_bwd
BACKWARD_TESTS := test_linear_backward test_embedding_backward \
test_rmsnorm_backward test_swiglu_backward \
test_rope_backward test_attention_backward
MODEL_TESTS := test_qwen3_backward test_llmengine test_continued_prefill_model test_rollout_engine
CPP_TESTS := test_dataloader test_lr_scheduler test_loading_weights test_cp_env test_cp_dataset
ALL_TESTS := $(KERNEL_TESTS) $(BACKWARD_TESTS) $(MODEL_TESTS) $(CPP_TESTS)
.PHONY: tests $(ALL_TESTS) bench_decode train_sft train_grpo
# Generic: "make test_foo" builds and runs ./build/test_foo
$(ALL_TESTS): %: $(BUILDDIR)/%
./$(BUILDDIR)/$@
bench_decode: $(BUILDDIR)/bench_decode
./$(BUILDDIR)/bench_decode
train_sft: $(BUILDDIR)/train_sft
./$(BUILDDIR)/train_sft
train_grpo: $(BUILDDIR)/train_grpo
./$(BUILDDIR)/train_grpo
tests: $(KERNEL_TESTS) $(MODEL_TESTS) test_loading_weights
# ── Data preparation ─────────────────────────────────────────────────────────
.PHONY: prepare_sft prepare_grpo
prepare_sft:
$(PYTHON) python_scripts/prepare_data.py --mode sft --output data/sft_train.bin
prepare_grpo:
$(PYTHON) python_scripts/prepare_data.py --mode grpo-text \
--dataset trl-lib/DeepMath-103K --output data/deepmath-103k.jsonl
# ── Cleanup ───────────────────────────────────────────────────────────────────
clean:
rm -rf $(BUILDDIR)