nemo_automodel.components.flow_matching.adapters.base
nemo_automodel.components.flow_matching.adapters.base
Base classes and data structures for model adapters.
This module defines the abstract ModelAdapter class and the FlowMatchingContext dataclass used to pass data between the pipeline and adapters.
Module Contents
Classes
API
Context object passed to model adapters containing all necessary data.
This provides a clean interface for adapters to access the data they need without coupling to the batch dictionary structure.
Backward compatibility alias for ‘latents’ field.
Abstract base class for model-specific forward pass logic.
Implement this class to add support for new model architectures without modifying the FlowMatchingPipeline.
The adapter pattern decouples the flow matching logic from model-specific details like input preparation and forward pass conventions.
Return additional named scalar losses computed from adapter-stashed state.
Called by FlowMatchingPipeline.step() after the primary loss is
computed. Override for models that train extra prediction streams
(e.g. a second modality) alongside the primary latents: stash the
needed tensors in the inputs dict during prepare_inputs() /
forward() and compute the losses here.
Parameters:
The dict returned by prepare_inputs(), after
forward() has run (adapters may stash prediction tensors
in it during forward()).
Returns: Dict[str, torch.Tensor] | None
Mapping of metric name to scalar loss tensor (each connected to
Compute the unreduced flow-matching loss.
Parameters:
Tensor of shape [batch, …], with arbitrary trailing latent dimensions.
Tensor of shape [batch, …] matching model_pred, containing the flow velocity target.
Returns: torch.Tensor
Float32 tensor of shape [batch, …] matching model_pred, containing the per-element loss.
Execute the model forward pass.
Parameters:
The model to call
Dictionary of inputs from prepare_inputs()
Returns: torch.Tensor
Model prediction tensor
Post-process model prediction if needed.
Override this for models that return extra outputs or need transformation.
Parameters:
Raw model output
Returns: torch.Tensor
Processed prediction tensor
Prepare model-specific inputs from the context.
Parameters:
FlowMatchingContext containing all necessary data
Returns: Dict[str, Any]
Dictionary of inputs to pass to the model’s forward method