Implementation:Facebookresearch Audiocraft AudioCraftEnvironment
Overview
AudioCraftEnvironment is the singleton class that encapsulates all cluster-level and team-level configuration for the AudioCraft training infrastructure. It resolves filesystem paths for Dora experiment tracking, reference files, and dataset path mappings across different compute environments.
Source Location
| Property | Value |
|---|---|
| Source file | audiocraft/environment.py lines 25-177
|
| Import | from audiocraft.environment import AudioCraftEnvironment
|
| Module | audiocraft.environment
|
API
Singleton Access
AudioCraftEnvironment.instance() -> AudioCraftEnvironment
Returns the singleton instance. Creates it on first call by:
- Reading
AUDIOCRAFT_TEAMenv var (default:"default") - Auto-detecting cluster type via
_guess_cluster_type() - Loading team YAML config from
config/teams/{team}.yaml(or path fromAUDIOCRAFT_CONFIG) - Compiling dataset mapper regex rules from the cluster config
Classmethods
AudioCraftEnvironment.get_team() -> str
AudioCraftEnvironment.get_cluster() -> str
AudioCraftEnvironment.get_dora_dir() -> Path
AudioCraftEnvironment.get_reference_dir() -> Path
AudioCraftEnvironment.get_slurm_exclude() -> Optional[str]
AudioCraftEnvironment.get_slurm_partitions(partition_types: Optional[List[str]] = None) -> str
AudioCraftEnvironment.resolve_reference_path(path: Union[str, Path]) -> Path
AudioCraftEnvironment.apply_dataset_mappers(path: str) -> str
AudioCraftEnvironment.reset() -> None
Environment Variables
| Variable | Purpose | Default |
|---|---|---|
AUDIOCRAFT_TEAM |
Selects the team configuration | "default"
|
AUDIOCRAFT_CLUSTER |
Overrides auto-detected cluster type | Auto-detected |
AUDIOCRAFT_CONFIG |
Path to custom team YAML config | config/teams/{team}.yaml
|
AUDIOCRAFT_DORA_DIR |
Overrides Dora experiment directory | From team YAML config |
AUDIOCRAFT_REFERENCE_DIR |
Overrides reference file directory | From team YAML config |
Configuration Files
config/teams/default.yaml
default:
dora_dir: /tmp/audiocraft_${oc.env:USER}
partitions:
global: debug
team: debug
reference_dir: /tmp
darwin:
dora_dir: /tmp/audiocraft_${oc.env:USER}
partitions:
global: debug
team: debug
reference_dir: /tmp
Team-specific configs (e.g., config/teams/labs.yaml) may define additional cluster entries with custom paths, partition names, and dataset mappers.
Inputs and Outputs
Inputs:
- Environment variables (
AUDIOCRAFT_TEAM,AUDIOCRAFT_DORA_DIR,AUDIOCRAFT_REFERENCE_DIR,AUDIOCRAFT_CLUSTER,AUDIOCRAFT_CONFIG) - Team YAML configuration files (e.g.,
config/teams/default.yaml) - Runtime cluster detection from
audiocraft.utils.cluster._guess_cluster_type()
Outputs:
- Singleton instance providing:
dora_dir-- resolvedPathfor Dora experiment storagereference_dir-- resolvedPathfor shared reference filescluster-- string identifier for the detected clusterteam-- string identifier for the configured team- Dataset path mapping via regex substitution rules
Usage in Training Pipeline
The environment is initialized very early in the training pipeline. In audiocraft/train.py:
from .environment import AudioCraftEnvironment
# ... later at module level:
main.dora.dir = AudioCraftEnvironment.get_dora_dir()
The resolve_reference_path method is used throughout the codebase to resolve //reference prefixed paths:
# In audiocraft/metrics/fad.py
self.model_path = AudioCraftEnvironment.resolve_reference_path(model_path)
# In audiocraft/utils/checkpoint.py
path = AudioCraftEnvironment.resolve_reference_path(path)
Dependencies
omegaconf-- for loading and parsing YAML configurationaudiocraft.utils.cluster._guess_cluster_type-- for automatic cluster detection