Repository navigation
Expand file tree
/
Copy pathpyproject.toml
More file actions
423 lines (387 loc) · 14.2 KB
/
Copy pathpyproject.toml
File metadata and controls
423 lines (387 loc) · 14.2 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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved.
[build-system]
requires = ["setuptools>=80", "pybind11", "packaging>=24.2"]
build-backend = "setuptools.build_meta"
[tool.setuptools]
include-package-data = true
[tool.setuptools.packages.find]
include = [
"megatron.core",
"megatron.core.*",
"megatron.training",
"megatron.training.*",
"megatron.bridge",
"megatron.bridge.*",
]
[tool.setuptools.package-data]
"megatron.core.allocator" = ["csrc/*.cpp"]
[tool.setuptools.dynamic]
version = { attr = "megatron.core.package_info.__version__" }
readme = { file = "README.md", content-type = "text/markdown" }
[project]
name = "megatron-core"
dynamic = ["version", "readme"]
description = "Megatron Core - a library for efficient and scalable training of transformer based models"
requires-python = ">=3.12"
license = { text = "Apache 2.0" }
dependencies = ["torch>=2.6.0", "numpy", "packaging>=24.2"]
authors = [{ name = "NVIDIA", email = "nemo-toolkit@nvidia.com" }]
maintainers = [{ name = "NVIDIA", email = "nemo-toolkit@nvidia.com" }]
keywords = [
"NLP",
"NLU",
"deep",
"gpu",
"language",
"learning",
"machine",
"nvidia",
"pytorch",
"torch",
"transformer",
]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: BSD License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Scientific/Engineering :: Image Recognition",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: Libraries",
"Topic :: Utilities",
]
[project.urls]
Download = "https://github.com/NVIDIA/Megatron-LM/releases"
Homepage = "https://github.com/NVIDIA/Megatron-LM"
[project.optional-dependencies]
bridge = [
"accelerate",
"einops",
"omegaconf>=2.3.0",
"pydantic>=2,<2.14",
"pyyaml>=6.0.2",
"rich",
"safetensors>=0.4.5",
"transformers>=5.21.1,<5.24",
]
training = [
"flask-restful",
"sentencepiece",
"tiktoken",
"wandb",
"transformers",
"accelerate",
"omegaconf",
"gigatoken>=0.11.0",
]
### 'mlm' group is deprecated. please use 'training' instead ###
mlm = [
"flask-restful",
"sentencepiece",
"tiktoken",
"wandb",
"transformers",
"accelerate",
"omegaconf",
"gigatoken>=0.11.0",
]
dev = [
"nvidia-modelopt[torch]>=0.49.0rc0; sys_platform != 'darwin'",
"nvidia-resiliency-ext==0.7.0",
"tqdm",
"einops~=0.8",
"tensorstore~=0.1,!=0.1.46,!=0.1.72",
"multi-storage-client~=1.1; sys_platform != 'win32'",
"opentelemetry-api>=1.33.1,<2",
"nemo-lens",
"megatron-energon[av_decode]~=7.0",
"av",
"Pillow>=13.0.0",
"flashinfer-python>=0.7.2,<0.8.0",
"flash-attn-4[cu13]==4.0.0b27",
"nvidia-cudnn-frontend[cutedsl]==1.33.0",
"wget",
"onnxscript",
"fastapi~=0.50", # Forcing a little bit more recent version of fastapi to be compatible with pydantic 2.0
"datasets",
"emerging_optimizers",
"hypercorn",
"quart",
"openai[aiohttp]",
"orjson",
"fast-hadamard-transform",
"zstandard",
]
inference = [
"torch-memory-saver",
"gigatoken==0.11.0",
# Dynamic text generation server and data-parallel inference coordinator.
# These are imported behind try/except, so a missing package only surfaces at runtime.
"hypercorn",
"msgpack",
"orjson",
"pyzmq",
"quart",
"flashinfer-python>=0.7.2,<0.8.0",
# flashinfer-jit-cache ships pre-compiled CUTLASS MoE kernels and must match
# flashinfer-python exactly; bump both together. The wheels are CUDA-major
# specific and only published on flashinfer.ai (cu130 to match the dev image).
# The pin must also satisfy the dev group's flashinfer-python range.
"flashinfer-python==0.7.2.post1; sys_platform == 'linux'",
"flashinfer-jit-cache==0.7.2.post1; sys_platform == 'linux'",
# flashinfer-jit-cache is split into per-arch packages that also live only on
# flashinfer.ai. uv only applies [tool.uv.sources] to direct dependencies, so
# each one is listed here (same pin) and routed to the flashinfer index below.
"flashinfer-jit-cache-sm80==0.7.2.post1; sys_platform == 'linux'",
"flashinfer-jit-cache-sm89==0.7.2.post1; sys_platform == 'linux'",
"flashinfer-jit-cache-sm90a==0.7.2.post1; sys_platform == 'linux'",
"flashinfer-jit-cache-sm100a==0.7.2.post1; sys_platform == 'linux'",
"flashinfer-jit-cache-sm103a==0.7.2.post1; sys_platform == 'linux'",
"flashinfer-jit-cache-sm110a==0.7.2.post1; sys_platform == 'linux' and platform_machine == 'aarch64'",
"flashinfer-jit-cache-sm120f==0.7.2.post1; sys_platform == 'linux'",
"flashinfer-jit-cache-sm121a==0.7.2.post1; sys_platform == 'linux' and platform_machine == 'aarch64'",
"tilelang>=0.1.12; sys_platform == 'linux'",
]
nvshmem = [
"nvshmem4py-cu13>=0.4.1; sys_platform == 'linux'",
"cupy-cuda13x>=14.2.0; sys_platform == 'linux'",
]
otel = [
"nemo-lens[sdk]",
]
### 'lts' extra is deprecated ###
### LTS Python dependencies are now pinned directly in docker/Dockerfile.ci.lts ###
### so this pyproject.toml can host meaningful module-level extras without ###
### colliding with the LTS pin set. Kept as an empty alias for one release ###
### cycle so `pip install megatron-core[lts]` does not error out. ###
lts = []
te = [
"transformer-engine[pytorch,core_cu13]",
]
ssm = [
"mamba-ssm",
"causal-conv1d~=1.5",
"flash-linear-attention==0.5.1",
]
[dependency-groups]
test = [
"coverage",
"nltk>=3.10.4",
"wrapt",
"pytest==9.1.1",
"pytest-mock",
"mock",
"pytest-cov",
"pytest-random-order",
"pytest-asyncio",
"pygithub",
"pydantic",
"tensorboard",
"pyyaml",
"nemo-run",
]
# GitHub CI installs Testmon at runtime for baseline and selective test modes.
# Testmon remains inactive unless pytest receives a --testmon option.
testmon = ["pytest-testmon==2.2.0"]
build = [
"setuptools>=80",
"packaging>=24.2",
"hatchling",
"pybind11",
"Cython>=3.0.0",
"torch",
"nvidia-cudnn-frontend>=1.31.0", # for TE
"nvidia-mathdx", # for TE
]
linting = [
"ruff~=0.9.0",
"black==26.10.1",
"isort==5.13.2",
"flake8==7.1.0",
"pylint==3.2.6",
]
ci = ["python-gitlab", "slack-sdk", "pandas"]
no_pypi_wheels = ["flash_mla", "emerging_optimizers"]
[tool.uv]
managed = true
default-groups = ["linting", "build", "test"]
# CUTLASS 4.8 moved CuTe APIs used by older Quack releases.
constraint-dependencies = ["quack-kernels>=0.6.5", "virtualenv>=21.14.9"]
no-build-isolation-package = [
"causal-conv1d",
"flash_mla",
"mamba-ssm",
"transformer-engine",
"transformer-engine-torch",
"fast-hadamard-transform",
]
link-mode = "copy"
# The Mamba revision retained from main pins an older TileLang/TVM FFI family.
# Override those transitive constraints for cuDNN Frontend and FlashAttention-4 compatibility.
# We don't define override-dependencies globally but rather locally where we need it.
# For instance, when installing into a PyTorch base image, we don't want to install torch,
# torchvision, and triton.
override-dependencies = [
"torch; sys_platform == 'never'",
"torchvision; sys_platform == 'never'",
"triton; sys_platform == 'never'",
"filelock>=4.2.1", # CVE-2026-112940; multi-storage-client 0.51 caps filelock below 4
"tilelang==0.1.13",
"apache-tvm-ffi==0.1.12",
# Match the existing dev Dockerfile runtime; PyPI Torch otherwise selects 3.4.5.
"nvidia-nvshmem-cu13==3.7.1",
# TorchX 0.7.0 caps urllib3 below 1.27; require the fix for GHSA-38jv-5279-wg99.
"urllib3>=2.6.3",
]
[[tool.uv.dependency-metadata]]
name = "flash-mla"
version = "1.0.0+9edee0c"
requires-dist = []
[[tool.uv.dependency-metadata]]
name = "transformer-engine"
version = "2.22.0+d05e4b83"
requires-dist = [
# Cap below 2.14: pydantic 2.14 breaks langchain_core's module-level
# RunnablePassthrough() instantiation, which is imported transitively in
# downstream consumers (e.g. Megatron-Bridge via nvidia-resiliency-ext).
"pydantic<2.14",
"importlib-metadata>=1.0",
"packaging",
"torch>=2.8",
"einops",
"onnxscript",
"onnx",
"nvdlfw-inspect",
"nvidia-cudnn-frontend>=1.31.0",
]
[[tool.uv.dependency-metadata]]
name = "fast-hadamard-transform"
version = "1.0.4.post1"
requires-dist = ["torch", "packaging", "ninja"]
# The aarch64 flashinfer-jit-cache wheel also requires sm110a/sm121a (aarch64-only wheels),
# but uv locks one wheel's metadata for every platform, which breaks x86_64 installs.
# Keep this in sync with the flashinfer-jit-cache pin in the inference extra.
[[tool.uv.dependency-metadata]]
name = "flashinfer-jit-cache"
version = "0.7.2.post1+cu130"
requires-dist = [
"flashinfer-jit-cache-sm80==0.7.2.post1",
"flashinfer-jit-cache-sm89==0.7.2.post1",
"flashinfer-jit-cache-sm90a==0.7.2.post1",
"flashinfer-jit-cache-sm100a==0.7.2.post1",
"flashinfer-jit-cache-sm103a==0.7.2.post1",
"flashinfer-jit-cache-sm110a==0.7.2.post1; platform_machine == 'aarch64'",
"flashinfer-jit-cache-sm120f==0.7.2.post1",
"flashinfer-jit-cache-sm121a==0.7.2.post1; platform_machine == 'aarch64'",
]
[tool.uv.sources]
flash_mla = [
{ git = "https://github.com/deepseek-ai/FlashMLA", rev = "nv_dev" },
]
transformer-engine = { git = "https://github.com/NVIDIA/TransformerEngine.git", rev = "d05e4b83f3da7035e0bfae2d635608be86829bed" }
nemo-run = { git = "https://github.com/NVIDIA-NeMo/Run.git", rev = "e3935393a290aed1822af52139b4b8ee270fed1f" }
emerging_optimizers = { git = "https://github.com/NVIDIA-NeMo/Emerging-Optimizers.git", rev = "v0.3.0" }
fast-hadamard-transform = { git = "https://github.com/Dao-AILab/fast-hadamard-transform.git", rev = "f134af63deb2df17e1171a9ec1ea4a7d8604d5ca" }
mamba-ssm = { git = "https://github.com/state-spaces/mamba.git", rev = "0048fbf2e7b2f214dcbe703ea3dec2b9647595e1" }
nemo-lens = { git = "https://github.com/NVIDIA-NeMo/Lens.git", rev = "b85578fc2b736a1804705e537001b5f45e9c715d" }
torch-memory-saver = { git = "https://github.com/fzyzcjy/torch_memory_saver.git", rev = "9bc9a442e6d108c7b7903def199896a005143aaf" }
flashinfer-jit-cache = { index = "flashinfer-cu130" }
flashinfer-jit-cache-sm80 = { index = "flashinfer-cu130" }
flashinfer-jit-cache-sm89 = { index = "flashinfer-cu130" }
flashinfer-jit-cache-sm90a = { index = "flashinfer-cu130" }
flashinfer-jit-cache-sm100a = { index = "flashinfer-cu130" }
flashinfer-jit-cache-sm103a = { index = "flashinfer-cu130" }
flashinfer-jit-cache-sm110a = { index = "flashinfer-cu130" }
flashinfer-jit-cache-sm120f = { index = "flashinfer-cu130" }
flashinfer-jit-cache-sm121a = { index = "flashinfer-cu130" }
[[tool.uv.index]]
name = "flashinfer-cu130"
url = "https://flashinfer.ai/whl/cu130"
explicit = true
[tool.isort]
profile = "black" # black-compatible
line_length = 100 # should match black parameters
py_version = 312 # python 3.12 as a target version
known_first_party = ["megatron"] # FIRSTPARTY section
known_third_party = ["transformer_engine"] # THIRDPARTY section
sections = ["FUTURE", "STDLIB", "THIRDPARTY", "FIRSTPARTY", "LOCALFOLDER"]
default_section = "THIRDPARTY"
extend_skip = ["setup.py"]
[tool.black]
line_length = 100
skip_string_normalization = true
# recognized by future versions, disallows to reformat code with incompatible versions
# Matches NeMO version so people working on both codebases don't need two different version of black installed
required_version = "26"
skip_magic_trailing_comma = true
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.venv
| build
)/
'''
[tool.pytest.ini_options]
addopts = "--durations=15 -s -rA"
testpaths = ["tests"]
python_files = "test_*.py"
markers = [
"internal: mark a test as a test to private/internal functions.",
"flaky: mark flaky tests for LTS environment",
"flaky_in_dev: mark flaky tests for DEV environment",
"launch_on_gb200: mark a unit test to be launched on GB200 hardware (4 GPUs/node)",
]
[tool.coverage.run]
concurrency = ["thread", "multiprocessing"]
omit = [
"/tmp/*",
"/opt/megatron-lm/tests/*",
"/opt/megatron-lm/tools/*",
"/usr/local/lib/python3.12/dist-packages/*",
"/opt/megatron-lm/_remote_module_non_scriptable",
# These fused paths are mostly Triton DSL kernels and PyTorch
# autograd-engine callbacks. The CUDA code is exercised by unit tests,
# but coverage.py cannot reliably trace those execution contexts.
"/opt/megatron-lm/megatron/core/fusions/*",
]
parallel = true
sigterm = false
[tool.coverage.paths]
source = [
".",
"/opt/megatron-lm/",
"/opt/megatron-lm-legacy/",
"/home/runner/work/Megatron-LM/Megatron-LM/",
]
[tool.ruff.lint]
# Enable all `pydocstyle` rules, limiting to those that adhere to the
# Google convention via `convention = "google"`, below.
# select = ["D", "F"]
select = ["S506"]
# - On top of the Google convention, disable `D417`, which requires
# documentation for every function parameter.
# - F841: local variable assigned but never used (exluced to favor readability)
# TODO: Remove D10 once we are about to release to get all the docstrings written
ignore = ["D417", "D10", "F841"]
[tool.ruff.lint.pydocstyle]
convention = "google"
# Section to exclude errors for different file types
[tool.ruff.per-file-ignores]
# Ignore all directories named `tests`.
"tests/**" = ["D"]
# Ignore all files that end in `_test.py`.
"*_test.py" = ["D"]
# Ignore F401 (import but unused) in __init__.py
"__init__.py" = ["F401"]