Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Facebookresearch Audiocraft AudioCraftEnvironment

From Leeroopedia

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:

  1. Reading AUDIOCRAFT_TEAM env var (default: "default")
  2. Auto-detecting cluster type via _guess_cluster_type()
  3. Loading team YAML config from config/teams/{team}.yaml (or path from AUDIOCRAFT_CONFIG)
  4. 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 -- resolved Path for Dora experiment storage
    • reference_dir -- resolved Path for shared reference files
    • cluster -- string identifier for the detected cluster
    • team -- 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 configuration
  • audiocraft.utils.cluster._guess_cluster_type -- for automatic cluster detection

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment