Skip to content

Commit 8d5b43b

Browse files
committed
Fix macOS installation by dynamically skipping legacy MaxText directory
1 parent c9ffb30 commit 8d5b43b

6 files changed

Lines changed: 52 additions & 30 deletions

File tree

build_hooks.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""Custom build hooks for PyPI."""
1616

1717
import os
18+
import sys
1819
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
1920

2021
TPU_REQUIREMENTS_PATH = "src/dependencies/requirements/generated_requirements/tpu-requirements.txt"
@@ -33,9 +34,27 @@ def get_tpu_dependencies():
3334

3435

3536
class CustomBuildHook(BuildHookInterface):
36-
"""A custom hook to inject TPU dependencies into the core wheel dependencies."""
37+
"""A custom hook to handle platform-specific package configuration for MaxText."""
3738

3839
def initialize(self, version, build_data): # pylint: disable=unused-argument
39-
tpu_deps = get_tpu_dependencies()
40-
build_data["dependencies"] = tpu_deps
41-
print(f"Successfully injected {len(tpu_deps)} TPU dependencies into the wheel's core requirements.")
40+
"""Adjusts the build_data dictionary to customize the wheel's package structure."""
41+
# The following TPU dependency injection is disabled because TPU-specific requirements
42+
# are now managed via optional dependencies (extras) in pyproject.toml
43+
# (e.g., pip install maxtext[tpu]).
44+
# tpu_deps = get_tpu_dependencies()
45+
# build_data["dependencies"] = tpu_deps
46+
# print(f"Successfully injected {len(tpu_deps)} TPU dependencies into the wheel's core requirements.")
47+
48+
# macOS specific logic to avoid case-sensitivity issues with MaxText and maxtext directories
49+
build_data["force_include"] = build_data.get("force_include", {})
50+
if sys.platform == "darwin":
51+
print("macOS detected. Skipping legacy MaxText shims to avoid case-sensitivity conflicts.")
52+
# Always include the __init__.py in the lowercase 'maxtext' package on macOS.
53+
# This ensures that 'import maxtext' (and thus 'import MaxText' on macOS)
54+
# has the proper version and metadata.
55+
build_data["force_include"]["src/MaxText/__init__.py"] = "maxtext/__init__.py"
56+
else:
57+
# On other platforms, include 'src/MaxText' as its own top-level package for legacy support.
58+
# We do NOT add __init__.py to 'maxtext' here to maintain exact parity with previous builds.
59+
print("Included src/MaxText as a top-level package for non-macOS platforms.")
60+
build_data["force_include"]["src/MaxText"] = "MaxText"

docs/install_maxtext.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ MaxText offers following installation modes:
2424
3. maxtext[tpu-post-train]. Used for post-training on TPUs. Currently, this option should also be used for running vllm_decode on TPUs.
2525
4. maxtext[runner]. Used for building MaxText's Docker images and scheduling workloads through XPK.
2626

27-
## From PyPI (Recommended)
27+
## From PyPI (Recommended on Linux)
2828

2929
This is the easiest way to get started with the latest stable version.
3030

@@ -61,6 +61,10 @@ uv pip install maxtext[runner] --resolution=lowest
6161
6262
> **Note:** The maxtext package contains a comprehensive list of all direct and transitive dependencies, with lower bounds, generated by [seed-env](https://github.com/google-ml-infra/actions/tree/main/python_seed_env). We highly recommend the `--resolution=lowest` flag. It instructs `uv` to install the specific, tested versions of dependencies defined by MaxText, rather than the latest available ones. This ensures a consistent and reproducible environment, which is critical for stable performance and for running benchmarks.
6363
64+
## macOS Installation
65+
66+
Due to macOS's case-insensitive filesystem we only support installing MaxText from source using the `.[runner]` configuration option listed below.
67+
6468
## From Source
6569

6670
If you plan to contribute to MaxText or need the latest unreleased features, install from source.

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@ Repository = "https://github.com/AI-Hypercomputer/maxtext.git"
4040
allow-direct-references = true
4141

4242
[tool.hatch.build.targets.wheel]
43-
packages = ["src/MaxText", "src/maxtext", "src/dependencies"]
43+
packages = ["src/maxtext", "src/dependencies"]
4444

45-
# TODO: Add this hook back when it handles device-type parsing
46-
# [tool.hatch.build.targets.wheel.hooks.custom]
47-
# path = "build_hooks.py"
45+
[tool.hatch.build.targets.wheel.hooks.custom]
46+
path = "build_hooks.py"
4847

4948
[project.scripts]
5049
install_maxtext_tpu_github_deps = "dependencies.github_deps.install_pre_train_deps:main"

src/dependencies/requirements/generated_requirements/cuda12-requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,9 @@ toml>=0.10.2
233233
tomlkit>=0.13.3
234234
toolz>=1.1.0
235235
tqdm>=4.67.1
236-
transformer-engine-cu12>=2.9.0
237-
transformer-engine-jax>=2.9.0
238-
transformer-engine>=2.9.0
236+
transformer-engine-cu12>=2.9.0 ; sys_platform == 'linux'
237+
transformer-engine-jax>=2.9.0 ; sys_platform == 'linux'
238+
transformer-engine>=2.9.0 ; sys_platform == 'linux'
239239
transformers>=4.57.3
240240
treescope>=0.1.10
241241
typeguard>=2.13.3

src/dependencies/requirements/generated_requirements/runner-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ mpmath>=1.3.0
7171
namex>=0.1.0
7272
numpy-typing-compat>=20251206.2.0
7373
numpy>=2.0.2
74-
nvidia-cuda-cccl>=13.1.115
74+
nvidia-cuda-cccl>=13.1.115 ; sys_platform == 'linux'
7575
oauthlib>=3.3.1
7676
omegaconf>=2.3.0
7777
opt-einsum>=3.4.0

src/dependencies/requirements/generated_requirements/tpu-post-train-requirements.txt

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ lark>=1.2.2
164164
latex2sympy2_extended>=1.11.0
165165
libclang>=18.1.1
166166
libcst>=1.8.6
167-
libtpu>=0.0.32
167+
libtpu>=0.0.32 ; platform_machine == 'x86_64' and sys_platform == 'linux'
168168
llguidance>=1.3.0
169169
llvmlite>=0.45.1
170170
lm-format-enforcer>=0.11.3
@@ -204,21 +204,21 @@ nodeenv>=1.9.1
204204
numba>=0.62.1
205205
numpy>=2.2.6
206206
numpy-typing-compat>=20250818.2.2
207-
nvidia-cublas-cu12>=12.8.4.1
208-
nvidia-cuda-cupti-cu12>=12.8.90
209-
nvidia-cuda-nvrtc-cu12>=12.8.93
210-
nvidia-cuda-runtime-cu12>=12.8.90
211-
nvidia-cudnn-cu12>=9.10.2.21
212-
nvidia-cufft-cu12>=11.3.3.83
213-
nvidia-cufile-cu12>=1.13.1.3
214-
nvidia-curand-cu12>=10.3.9.90
215-
nvidia-cusolver-cu12>=11.7.3.90
216-
nvidia-cusparse-cu12>=12.5.8.93
217-
nvidia-cusparselt-cu12>=0.7.1
218-
nvidia-nccl-cu12>=2.27.5
219-
nvidia-nvjitlink-cu12>=12.8.93
220-
nvidia-nvshmem-cu12>=3.3.20
221-
nvidia-nvtx-cu12>=12.8.90
207+
nvidia-cublas-cu12>=12.8.4.1 ; sys_platform == 'linux'
208+
nvidia-cuda-cupti-cu12>=12.8.90 ; sys_platform == 'linux'
209+
nvidia-cuda-nvrtc-cu12>=12.8.93 ; sys_platform == 'linux'
210+
nvidia-cuda-runtime-cu12>=12.8.90 ; sys_platform == 'linux'
211+
nvidia-cudnn-cu12>=9.10.2.21 ; sys_platform == 'linux'
212+
nvidia-cufft-cu12>=11.3.3.83 ; sys_platform == 'linux'
213+
nvidia-cufile-cu12>=1.13.1.3 ; sys_platform == 'linux'
214+
nvidia-curand-cu12>=10.3.9.90 ; sys_platform == 'linux'
215+
nvidia-cusolver-cu12>=11.7.3.90 ; sys_platform == 'linux'
216+
nvidia-cusparse-cu12>=12.5.8.93 ; sys_platform == 'linux'
217+
nvidia-cusparselt-cu12>=0.7.1 ; sys_platform == 'linux'
218+
nvidia-nccl-cu12>=2.27.5 ; sys_platform == 'linux'
219+
nvidia-nvjitlink-cu12>=12.8.93 ; sys_platform == 'linux'
220+
nvidia-nvshmem-cu12>=3.3.20 ; sys_platform == 'linux'
221+
nvidia-nvtx-cu12>=12.8.90 ; sys_platform == 'linux'
222222
oauthlib>=3.3.1
223223
omegaconf>=2.3.0
224224
openai>=2.24.0
@@ -369,7 +369,7 @@ tqdm>=4.67.3
369369
traitlets>=5.14.3
370370
transformers>=4.57.1
371371
treescope>=0.1.10
372-
triton>=3.5.0
372+
triton>=3.5.0 ; sys_platform == 'linux'
373373
typeguard>=2.13.3
374374
typer>=0.24.1
375375
typing-inspect>=0.9.0

0 commit comments

Comments
 (0)