Principle:Axolotl ai cloud Axolotl Package Build Configuration
| Knowledge Sources | |
|---|---|
| Domains | Build_System, Packaging, Software_Engineering |
| Last Updated | 2026-02-07 00:00 GMT |
Overview
Build and packaging strategy that uses PEP 621 project metadata with dynamic dependency resolution to handle complex PyTorch version compatibility across platforms.
Description
Package Build Configuration addresses the unique challenge of packaging an ML training framework that depends on platform-specific and version-specific CUDA libraries. Standard static dependency declarations cannot express constraints like "if torch 2.8 is installed, use xformers 0.0.31; if torch 2.7, use xformers 0.0.30; on macOS, skip xformers entirely." The solution uses a three-layer approach: (1) pyproject.toml declares the package metadata, entry points, and build system following PEP 621, with dependencies marked as dynamic, (2) setup.py provides the runtime dependency resolution logic that detects the installed PyTorch version and selects compatible dependency pins, and (3) a custom BuildPyCommand registered via [tool.setuptools.cmdclass] hooks into the build process to inject resolved dependencies. The system also manages optional dependency groups (flash-attn, deepspeed, vllm, etc.) with version-specific resolution per group.
Usage
Apply this principle when packaging ML projects with complex CUDA/PyTorch version dependencies that cannot be expressed in static metadata. The pattern is especially valuable for projects supporting multiple PyTorch major/minor/patch versions with different compatible library versions.
Theoretical Basis
# Abstract dynamic dependency resolution
def resolve_dependencies(requirements_file, platform, installed_torch_version):
base_deps = parse_requirements(requirements_file)
if platform == "darwin":
base_deps = remove_cuda_packages(base_deps)
return base_deps
torch_major, torch_minor, torch_patch = parse_version(installed_torch_version)
# Version matrix resolution
compatibility_map = {
(2, 9): {"xformers": "0.0.31", "vllm": "0.13.0"},
(2, 8): {"xformers": "0.0.31", "vllm": "0.11.0"},
(2, 7): {"xformers": "0.0.30", "vllm": "0.10.1"},
# ...
}
pins = compatibility_map.get((torch_major, torch_minor), {})
base_deps = apply_version_pins(base_deps, pins)
return base_deps