Implementation:Facebookresearch Audiocraft Resolve checkpoint path
Overview
Resolve_checkpoint_path resolves a Dora experiment signature or direct filesystem path to a concrete checkpoint file path. This is the entry point for any model export workflow, converting human-friendly experiment identifiers into loadable checkpoint locations.
Implements
Principle:Facebookresearch_Audiocraft_Training_Checkpoint_Resolution
API Signature
def resolve_checkpoint_path(
sig_or_path: Union[Path, str],
name: Optional[str] = None,
use_fsdp: bool = False
) -> Optional[Path]
Source: audiocraft/utils/checkpoint.py, lines 56-84
Import:
from audiocraft.utils.checkpoint import resolve_checkpoint_path
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
sig_or_path |
Union[Path, str] |
required | Dora experiment signature (with //sig/ prefix) or direct filesystem path to a checkpoint file or directory
|
name |
Optional[str] |
None |
Checkpoint name suffix (e.g., "best" for checkpoint_best.th). When None, resolves to the latest checkpoint (checkpoint.th)
|
use_fsdp |
bool |
False |
Whether to append FSDP rank suffix to the checkpoint filename for distributed training checkpoints |
Return Value
Returns an Optional[Path]: the resolved checkpoint path if the file exists, or None if no checkpoint was found at the resolved location.
Dependencies
audiocraft.train-- accessed to retrieve the Dora experiment root directory viatrain.main.dora.diraudiocraft.environment.AudioCraftEnvironment-- used for reference path resolution when given a direct pathflashy-- used indirectly throughcheckpoint_name()for distributed rank detection
How It Works
from audiocraft.utils.checkpoint import resolve_checkpoint_path
# Resolve from a Dora experiment signature
path = resolve_checkpoint_path('//sig/abc123de', name='best')
# Resolves to: <dora_dir>/xps/abc123de/checkpoint_best.th
# Resolve from a direct filesystem path
path = resolve_checkpoint_path('/path/to/my/training/run', name='best')
# Resolves to: /path/to/my/training/run/checkpoint_best.th
# For FSDP checkpoint on rank 1
path = resolve_checkpoint_path('//sig/abc123de', name='best', use_fsdp=True)
# Resolves to: <dora_dir>/xps/abc123de/checkpoint_best.th.1 (on rank 1)
The implementation logic:
def resolve_checkpoint_path(sig_or_path, name=None, use_fsdp=False):
from audiocraft import train
xps_root = train.main.dora.dir / 'xps'
sig_or_path = str(sig_or_path)
if sig_or_path.startswith('//sig/'):
sig = sig_or_path[len('//sig/'):]
path = xps_root / sig
else:
path = Path(sig_or_path)
path = AudioCraftEnvironment.resolve_reference_path(path)
if path.is_dir():
path = path / checkpoint_name(name, use_fsdp=use_fsdp)
if path.exists():
return path
else:
return None
Supporting Function: get_solver_from_sig
For loading a full solver (with model, optimizer, etc.) from a signature:
def get_solver_from_sig(sig: str, *args, **kwargs):
"""Return Solver object from Dora signature."""
xp = main.get_xp_from_sig(sig)
return get_solver_from_xp(xp, *args, **kwargs)
Source: audiocraft/train.py, lines 97-102