Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
299 lines (269 loc) · 13.9 KB
/
Copy pathMakefile
File metadata and controls
299 lines (269 loc) · 13.9 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
.PHONY : checks
checks : style-check lint-check type-check
.PHONY : style-check
style-check :
@echo "======== running isort... ========"
@isort --check .
@echo "======== running black... ========"
@black --check .
.PHONY : lint-check
lint-check :
@echo "======== running ruff... ========="
@ruff check .
.PHONY : type-check
type-check :
@echo "======== running mypy... ========="
@mypy src/
.PHONY : style
style:
@echo "======== formatting with isort... ========"
@isort .
@echo "======== formatting with black... ========"
@black .
.PHONY : docs
docs :
rm -rf docs/build/
sphinx-autobuild -b html --watch src/olmo_core/ --watch README.md docs/source/ docs/build/
.PHONY : build
build :
rm -rf *.egg-info/ dist/
python -m build
python src/scripts/release/check_dist_metadata.py dist/*
####################################################################################################
# Docker build
####################################################################################################
#-----------------#
# Build variables #
#-----------------#
# NOTE: When upgrading dependency versions (like for torch) make sure:
# * The corresponding versions specified in 'pyproject.toml' include the new version.
# * The versions installed in '.github/actions/setup-python-env/action.yml' match if necessary.
# NOTE: See https://hub.docker.com/r/nvidia/cuda/tags?name=devel-ubuntu22.04 for available CUDA versions.
CUDA_VERSION = 12.9.1
CUDA_VERSION_PATH=cu$(shell echo $(CUDA_VERSION) | cut -d"." -f1-2 | tr -d .)
CUDA_NVCC_VERSION = 12.9.86
PYTHON_VERSION = 3.12
TORCH_VERSION = 2.13.0
TORCH_VERSION_SHORT = $(shell echo $(TORCH_VERSION) | tr -d .)
INSTALL_CHANNEL = whl
# Bumped from 7452a58 (2026-01, ~98 commits stale) to pick up dion's torch-2.13 + distributed
# fixes: the megabatch_orthogonalize_async hang fix (#74), allreduce-sync change (#75), FSDP2
# padding fix (#97), and the PyTorch-2.13/Triton-3.7.1 inductor-miscompile fix (#117). The old pin's
# HSDP path deadlocks on an ALLREDUCE on torch 2.13 (works on 2.10).
DION_SHA = "e64832041d8e01989abf609c9550f6307efbff2a"
GROUPED_GEMM_SHA = "f1429a3c44c98f7912aa4b00125144cdf4e7fdb2"
# Compute capabilities the from-source CUDA extensions (grouped-gemm, transformer-engine, ...) are
# built for. The CUDA-13 targets (beaker-image-cu130*) extend these with sm_103 (B300 / Blackwell Ultra).
TORCH_CUDA_ARCH_LIST = 9.0 10.0
FLASH_ATTN_VERSION = 2.8.2
# Archs flash-attn 2 is compiled for (it reads FLASH_ATTN_CUDA_ARCHS, not TORCH_CUDA_ARCH_LIST).
FLASH_ATTN_CUDA_ARCHS = 90;100
FLASH_ATTN_3_SHA = "060c9188beec3a8b62b33a3bfa6d5d2d44975fab"
FA3_MAX_JOBS = 64
# flash-attn 4 provides the `flash_attn.cute` backend (AttentionBackendName.flash_4). Optional:
# leave FLASH_ATTN_4_VERSION empty to skip it. When set, it's installed (as a prebuilt wheel) and
# the image tag gets a '-fa4' suffix (see FA4_TAG). Use FLASH_ATTN_4_EXTRAS='[cu13]' for CUDA 13.
# FA4 is CUDA-13 only; the beaker-image-cu130-fa4* targets enable it (see FA4_ARGS).
FLASH_ATTN_4_VERSION =
FLASH_ATTN_4_EXTRAS =
# Pin for nvidia-cutlass-dsl (FA4's DSL dep). FA4 betas pin it loosely, so pip can float to a
# version whose API dropped symbols the wheel needs (4.6.x removed ThrMma, breaking 4.0.0b16).
FLASH_ATTN_4_CUTLASS_DSL_VERSION =
# TE 2.18: the MXFP8 path passes MXFP8Tensor(with_gemm_swizzled_scales=...), added in TE 2.12, and
# TE >= 2.18 needs the CUDA devel base below (it loads a system libcudart at import).
TE_VERSION = 2.18.0
RING_FLASH_ATTN_VERSION = 0.1.8
LIGER_KERNEL_VERSION = 0.6.4
# NOTE: Quack currently requires CUDA 12.9 or higher and PyTorch 2.9.1
# QUACK_VERSION = 0.2.4
QUACK_VERSION = ""
# B300 (sm_103) image switches. Empty for the default image; set by the CUDA-13 targets (via
# CUDA13_ARGS) to bake in the B300-only fixes (see CUDA13_ARGS and the Dockerfile release stage).
B300 =
# Use the image's assembler for both Triton paths, including Blackwell (SM100+).
# CUDA-13 targets override this with their CUDA-13 assembler symlink.
TRITON_PTXAS_PATH = /opt/conda/bin/ptxas
# symm-mem / RMA image switches. Empty for the default image; set by the '-rma' targets so the
# symm_mem_vdev2d (rowwise EP) and nccl_rma_p2p (custom PP) extensions can JIT-build at runtime.
UBUNTU_VERSION = 22.04
# Release-stage base. A CUDA 'devel' base (nvcc + CUDA headers) is the default: TE >= 2.18 loads a
# system libcudart at import, and the RMA extensions (symm_mem_vdev2d, nccl_rma_p2p) JIT-compile at
# runtime. Derived from CUDA_VERSION so the release base always matches the build stage's CUDA (a
# caller overriding only CUDA_VERSION -- e.g. the docker.yml matrix -- gets a matching base, not a
# stale one). Override BASE_IMAGE explicitly only for a non-standard base.
BASE_IMAGE = nvidia/cuda:$(CUDA_VERSION)-cudnn-devel-ubuntu$(UBUNTU_VERSION)
# NCCL exposing the RMA one-sided window signal API (ncclPutSignal / ncclWaitSignal) for nccl_rma_p2p.
NCCL_RMA_VERSION = 2.29.7
# NCCL / NVSHMEM install specs passed to the Dockerfile. Empty = torch's bundled NCCL, no NVSHMEM.
NCCL_PIP_SPEC =
NVSHMEM_PIP_SPEC =
#--------------#
# Build naming #
#--------------#
VERSION = $(shell python src/olmo_core/version.py)
VERSION_SHORT = $(shell python src/olmo_core/version.py short)
IMAGE_SUFFIX = $(shell date "+%Y-%m-%d")
# Build-variant marker ('-sm80', ...) set by the specialized image targets; combined with the FA4/RMA
# matrix suffixes below.
IMAGE_VARIANT =
# '-fa4' marker in the tag when flash-attn 4 is baked in (empty otherwise; see FLASH_ATTN_4_VERSION).
FA4_TAG = $(if $(FLASH_ATTN_4_VERSION),-fa4,)
# '-rma' marker when the symm-mem/RMA stack (NVSHMEM + RMA-capable NCCL on a devel base) is baked in.
RMA_TAG = $(if $(NVSHMEM_PIP_SPEC),-rma,)
# Image tag omits the GPU generation: a CUDA-13 image is built for sm_90/100/103, so one image
# serves H100 + B200 + B300 (naming stays consistent with the older CUDA-12 images).
IMAGE_TAG = tch$(TORCH_VERSION_SHORT)$(CUDA_VERSION_PATH)$(IMAGE_VARIANT)$(FA4_TAG)$(RMA_TAG)-$(IMAGE_SUFFIX)
# Imports the built image is smoke-tested against. The CUDA-13 targets override this to drop
# flash_attn_3, which isn't built on CUDA 13 (see CUDA13_ARGS).
DOCKER_VALIDATE_IMPORTS = import torch; import transformer_engine.pytorch; import flash_attn; import flash_attn_3.flash_attn_interface
.PHONY : docker-image
docker-image :
docker build -f src/Dockerfile \
--platform=linux/amd64 \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg CUDA_VERSION=$(CUDA_VERSION) \
--build-arg CUDA_VERSION_PATH=$(CUDA_VERSION_PATH) \
--build-arg CUDA_NVCC_VERSION=$(CUDA_NVCC_VERSION) \
--build-arg PYTHON_VERSION=$(PYTHON_VERSION) \
--build-arg UBUNTU_VERSION=$(UBUNTU_VERSION) \
--build-arg BASE_IMAGE=$(BASE_IMAGE) \
--build-arg NCCL_PIP_SPEC="$(NCCL_PIP_SPEC)" \
--build-arg NVSHMEM_PIP_SPEC="$(NVSHMEM_PIP_SPEC)" \
--build-arg TORCH_VERSION=$(TORCH_VERSION) \
--build-arg TORCH_CUDA_ARCH_LIST="$(TORCH_CUDA_ARCH_LIST)" \
--build-arg INSTALL_CHANNEL=$(INSTALL_CHANNEL) \
--build-arg DION_SHA=$(DION_SHA) \
--build-arg GROUPED_GEMM_SHA=$(GROUPED_GEMM_SHA) \
--build-arg FLASH_ATTN_VERSION=$(FLASH_ATTN_VERSION) \
--build-arg FLASH_ATTN_CUDA_ARCHS="$(FLASH_ATTN_CUDA_ARCHS)" \
--build-arg FLASH_ATTN_3_SHA=$(FLASH_ATTN_3_SHA) \
--build-arg FA3_MAX_JOBS=$(FA3_MAX_JOBS) \
--build-arg FLASH_ATTN_4_VERSION=$(FLASH_ATTN_4_VERSION) \
--build-arg FLASH_ATTN_4_EXTRAS="$(FLASH_ATTN_4_EXTRAS)" \
--build-arg FLASH_ATTN_4_CUTLASS_DSL_VERSION=$(FLASH_ATTN_4_CUTLASS_DSL_VERSION) \
--build-arg TE_VERSION=$(TE_VERSION) \
--build-arg RING_FLASH_ATTN_VERSION=$(RING_FLASH_ATTN_VERSION) \
--build-arg LIGER_KERNEL_VERSION=$(LIGER_KERNEL_VERSION) \
--build-arg QUACK_VERSION=$(QUACK_VERSION) \
--build-arg B300="$(B300)" \
--build-arg TRITON_PTXAS_PATH="$(TRITON_PTXAS_PATH)" \
--target release \
-t olmo-core:$(IMAGE_TAG) .
@# --gpus all: transformer-engine (>= 2.18) dlopens libcuda at import, so the validation
@# container needs the driver exposed. Requires a GPU host + nvidia-container-toolkit.
@docker run --rm --gpus all olmo-core:$(IMAGE_TAG) python -c '$(DOCKER_VALIDATE_IMPORTS)'
@echo "✓ Image validated. Python environment:"
@echo ""
@docker run --rm olmo-core:$(IMAGE_TAG) pip list
@echo ""
@echo "✓ Build complete: olmo-core:$(IMAGE_TAG) (size=$$(docker inspect -f '{{ .Size }}' olmo-core:$(IMAGE_TAG) | numfmt --to=si))"
@echo ""
.PHONY : docker-image-sm80
docker-image-sm80 :
$(MAKE) docker-image \
TORCH_CUDA_ARCH_LIST="8.0 9.0 10.0" \
FLASH_ATTN_CUDA_ARCHS="80;90;100" \
IMAGE_VARIANT=-sm80
.PHONY : ghcr-image
ghcr-image : docker-image
docker tag olmo-core:$(IMAGE_TAG) ghcr.io/allenai/olmo-core:$(IMAGE_TAG)
docker push ghcr.io/allenai/olmo-core:$(IMAGE_TAG)
docker tag olmo-core:$(IMAGE_TAG) ghcr.io/allenai/olmo-core:latest
docker push ghcr.io/allenai/olmo-core:latest
BEAKER_WORKSPACE = ai2/OLMo-core
BEAKER_USER = $(shell beaker account whoami --format=json | jq -r '.[0].name')
.PHONY : beaker-image
beaker-image : docker-image
@./src/scripts/beaker/create_beaker_image.sh olmo-core:$(IMAGE_TAG) olmo-core-$(IMAGE_TAG) $(BEAKER_WORKSPACE)
@echo "✓ Done"
####################################################################################################
# Image build matrix
#
# Two CUDA families, both on torch 2.13, each optionally layered with flash-attn 4 (FA4) and/or the
# symm-mem/RMA stack:
# * CUDA 12.9 (torch 2.13) — the default (the build variables above) — built for sm_90/100
# (H100, B200). Runs on the current H100/B200 CI driver (unlike CUDA 13); torch 2.13 dropped the
# cu128 wheel and bundles triton 3.7.1 + nccl 2.29.7, unblocking flash-linear-attention 0.5.2.
# * CUDA 13.0 (torch 2.13) — built for sm_90/100/103, so ONE image serves H100 + B200 + B300.
# The tag carries no GPU generation (naming stays consistent with the CUDA-12 images).
#
# FA4 (`flash_attn.cute`) is CUDA-13 only: the `flash-attn-4` package ships a `cu13` extra and no
# `cu12`, so it is offered on the CUDA-13 targets only. RMA works on both families (the NVSHMEM /
# RMA-NCCL wheels exist for cu12 and cu13).
#
# Build args are layered onto the parametrized `beaker-image` target; last assignment of a variable
# wins, so an FA4 layer's DOCKER_VALIDATE_IMPORTS overrides the base one.
####################################################################################################
# CUDA-13 base (torch 2.13). Successor to the torch-2.11 cu130 base. Adds sm_103 to the arch lists,
# registers torch's bundled nvrtc so transformer-engine imports on CUDA 13, points Triton at a
# CUDA-13 ptxas, and skips the flash-attn 3 build (FA3 has no sm_103 kernels and doesn't build on
# CUDA 13 — dropped from the smoke test too). The devel base derives from CUDA_VERSION (see
# BASE_IMAGE); inherits torch 2.13 + TE 2.18 from the defaults. If flash-attn / transformer-engine /
# grouped-gemm fail to build, bump them to CUDA-13-compatible releases.
CUDA13_ARGS = \
CUDA_VERSION=13.0.1 \
TORCH_CUDA_ARCH_LIST="9.0 10.0 10.3" \
FLASH_ATTN_CUDA_ARCHS="90;100;103" \
B300=1 \
TRITON_PTXAS_PATH=/usr/local/bin/triton-ptxas \
DOCKER_VALIDATE_IMPORTS="import torch; import transformer_engine.pytorch; import flash_attn"
# FA4 layer (CUDA-13 only): installs the flash_attn.cute wheel (AttentionBackendName.flash_4) and
# appends it to the smoke test; adds the '-fa4' tag suffix (see FA4_TAG). The cutlass-dsl pin avoids
# 4.6.x, which dropped symbols 4.0.0b16 needs (ThrMma).
FA4_ARGS = \
FLASH_ATTN_4_VERSION=4.0.0b16 \
FLASH_ATTN_4_EXTRAS="[cu13]" \
FLASH_ATTN_4_CUTLASS_DSL_VERSION=4.5.3 \
DOCKER_VALIDATE_IMPORTS="import torch; import transformer_engine.pytorch; import flash_attn; import flash_attn.cute"
# symm-mem / RMA layer: NVSHMEM plus (on CUDA 13) an RMA-capable NCCL, so the symm_mem_vdev2d
# (rowwise EP) and nccl_rma_p2p (custom PP) extensions can JIT-build at runtime. Required for EP>1 /
# rowwise runs; EP=1 runs don't need it. Adds the '-rma' tag suffix (see RMA_TAG). The devel base is
# already the default (see BASE_IMAGE). One bundle per CUDA family — the wheels are CUDA-major-specific.
RMA_CU13_ARGS = \
NVSHMEM_PIP_SPEC=nvidia-nvshmem-cu13 \
NCCL_PIP_SPEC=nvidia-nccl-cu13==$(NCCL_RMA_VERSION)
# RMA layer for the CUDA-12.9 family. torch 2.13 already bundles nccl 2.29.7 (the RMA-capable build),
# so no NCCL override is needed here — only NVSHMEM (on the default cu129 devel base).
RMA_CU129_ARGS = \
NVSHMEM_PIP_SPEC=nvidia-nvshmem-cu12
# ---- CUDA 12.9 family (H100, B200) — torch 2.13 [default] --------------------------------------
# olmo-core-tch2130cu129-<date> (the default build variables above)
.PHONY : beaker-image-cu129
beaker-image-cu129 :
$(MAKE) beaker-image
# olmo-core-tch2130cu129-rma-<date>
.PHONY : beaker-image-cu129-rma
beaker-image-cu129-rma :
$(MAKE) beaker-image $(RMA_CU129_ARGS)
# olmo-core-tch2130cu129-sm80-<date> (adds sm_80 / A100 for the general, non-MoE test coverage)
# No NVSHMEM (A100 / sm_80 can't run the symm-mem EP kernels, which need sm_90+); uses the default
# cu129 devel base.
.PHONY : beaker-image-cu129-sm80
beaker-image-cu129-sm80 :
$(MAKE) beaker-image \
TORCH_CUDA_ARCH_LIST="8.0 9.0 10.0" \
FLASH_ATTN_CUDA_ARCHS="80;90;100" \
IMAGE_VARIANT=-sm80
# ---- CUDA 13.0 family (H100, B200, B300) — torch 2.13 -----------------------------------------
# olmo-core-tch2130cu130-<date>
.PHONY : beaker-image-cu130
beaker-image-cu130 :
$(MAKE) beaker-image $(CUDA13_ARGS)
# olmo-core-tch2130cu130-fa4-<date>
.PHONY : beaker-image-cu130-fa4
beaker-image-cu130-fa4 :
$(MAKE) beaker-image $(CUDA13_ARGS) $(FA4_ARGS)
# olmo-core-tch2130cu130-rma-<date>
.PHONY : beaker-image-cu130-rma
beaker-image-cu130-rma :
$(MAKE) beaker-image $(CUDA13_ARGS) $(RMA_CU13_ARGS)
# olmo-core-tch2130cu130-fa4-rma-<date> (flash_4 attention + symm-mem/RMA rowwise EP)
.PHONY : beaker-image-cu130-fa4-rma
beaker-image-cu130-fa4-rma :
$(MAKE) beaker-image $(CUDA13_ARGS) $(FA4_ARGS) $(RMA_CU13_ARGS)
.PHONY : get-beaker-workspace
get-beaker-workspace :
@echo $(BEAKER_WORKSPACE)
.PHONY : get-full-beaker-image-name
get-full-beaker-image-name :
@./src/scripts/beaker/get_full_image_name.sh $(IMAGE_TAG) $(BEAKER_WORKSPACE)