Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Facebookresearch Audiocraft SampleManager

From Leeroopedia
Revision as of 12:33, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Facebookresearch_Audiocraft_SampleManager.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Training, Audio_Generation
Last Updated 2026-02-14 01:00 GMT

Overview

Concrete tool for storing, retrieving, and comparing generated audio samples across training epochs provided by the AudioCraft library.

Description

SampleManager provides an API for managing audio sample outputs during training. It stores generated audio samples alongside ground truth references, organizes them by epoch, and supports XP-based path resolution via Dora. The manager handles distributed training by only writing on rank zero, generates unique sample IDs, and maintains a mapping from reference to sample IDs for comparison across epochs.

Usage

Import this class in solver code when you need to save generated audio samples during the generate() stage of training. It is used by all AudioCraft solvers (MusicGenSolver, CompressionSolver, DiffusionSolver, WatermarkSolver) to store evaluation samples.

Code Reference

Source Location

Signature

class SampleManager:
    def __init__(self, xp: dora.XP, map_reference_to_sample_id: bool = False):
        """
        Args:
            xp: Dora experiment object for path resolution.
            map_reference_to_sample_id: If True, map reference filenames to sample IDs.
        """

    def add_samples(self, samples: torch.Tensor, epoch: int,
                    ground_truth_wavs: tp.Optional[torch.Tensor] = None,
                    conditioning: tp.Optional[tp.List] = None) -> None:
        """Save generated samples and optional ground truth for the given epoch."""

    def get_samples(self, epoch: int) -> tp.List[Sample]:
        """Retrieve stored samples for the given epoch."""

Import

from audiocraft.utils.samples.manager import SampleManager

I/O Contract

Inputs

Name Type Required Description
samples torch.Tensor Yes Generated audio samples [B, C, T]
epoch int Yes Current training epoch
ground_truth_wavs torch.Tensor No Reference audio for comparison
conditioning list No Conditioning attributes for each sample

Outputs

Name Type Description
Sample files WAV files Saved to XP directory organized by epoch
Sample objects List[Sample] Retrieved sample metadata and paths

Usage Examples

from audiocraft.utils.samples.manager import SampleManager

# Used inside a solver's generate() method:
sample_manager = SampleManager(self.xp, map_reference_to_sample_id=True)
sample_manager.add_samples(
    generated_wav.cpu(),
    epoch=self.epoch,
    ground_truth_wavs=reference.cpu(),
)

Related Pages

Page Connections

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