Implementation:Axolotl ai cloud Axolotl Dynamic Dependencies
| Knowledge Sources | |
|---|---|
| Domains | Build_System, Packaging |
| Last Updated | 2026-02-07 00:00 GMT |
Overview
Setuptools build command extension that resolves Axolotl dependencies dynamically at build time based on the installed PyTorch version and platform.
Description
The setuptools_axolotl_dynamic_dependencies.py module provides the BuildPyCommand class, a custom setuptools build_py command registered in pyproject.toml via the [tool.setuptools.cmdclass] section. When triggered during pip install, the finalize_options method calls parse_requirements to read requirements.txt, detect the installed torch version (falling back to 2.5.1 if not found), and select the correct xformers and torchao version pins for torch versions ranging from 2.2 through 2.5+. On macOS, it removes xformers entirely. Unlike the setup.py variant, this module handles dependencies during the PEP 517 build-time phase, enabling the modern pyproject.toml build flow to use dynamic dependency resolution.
Usage
This module is activated automatically during package installation via the build system configuration in pyproject.toml. It should not be imported or used directly. Maintain it when new PyTorch versions require updated xformers/torchao compatibility pins.
Code Reference
Source Location
- Repository: Axolotl
- File: src/setuptools_axolotl_dynamic_dependencies.py
- Lines: 1-102
Signature
def parse_requirements() -> tuple[list[str], list[str]]:
"""Parse requirements.txt and resolve torch-version-specific pins.
Returns:
Tuple of (install_requires, dependency_links).
"""
class BuildPyCommand(_build_py):
"""Custom build_py command to parse dynamic requirements."""
def finalize_options(self):
"""Override to inject resolved dependencies into distribution."""
super().finalize_options()
install_requires, _ = parse_requirements()
self.distribution.install_requires = install_requires
Import
# Registered via pyproject.toml, not imported directly:
# [tool.setuptools.cmdclass]
# build_py = "setuptools_axolotl_dynamic_dependencies.BuildPyCommand"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| requirements.txt | File | Yes | Base package requirements with xformers/torchao entries |
| Installed torch version | Runtime detection | No | Auto-detected; falls back to 2.5.1 |
| Platform | Runtime detection | No | macOS detection to skip xformers |
Outputs
| Name | Type | Description |
|---|---|---|
| install_requires | list[str] | Resolved dependency list injected into setuptools distribution |
| dependency_links | list[str] | Extra index URLs for custom package sources |
Usage Examples
Automatic Activation
# BuildPyCommand runs automatically during pip install
pip install -e .
# The dynamic resolution happens transparently:
# 1. pip reads pyproject.toml
# 2. setuptools invokes BuildPyCommand.finalize_options()
# 3. parse_requirements() detects torch version and resolves pins
# 4. Resolved dependencies are installed