noether.modeling.diffusion¶
Diffusion / flow-matching schedules.
Tensor-only flow-matching implementation behind a common
DiffusionSchedule ABC. Pair with the configs in
noether.core.schemas.diffusion.
Use build_schedule() to instantiate the right schedule from a config
that came out of the AnyDiffusionScheduleConfig
discriminated union.
Example:
import torch
from noether.core.schemas.diffusion import FlowMatchingConfig
from noether.modeling.diffusion import build_schedule
schedule = build_schedule(FlowMatchingConfig()).to("cpu")
x0 = torch.randn(4, 16)
def model_fn(xt, t, condition):
return torch.zeros_like(xt)
loss = schedule.training_losses(x0, model_fn)
Submodules¶
Attributes¶
Discriminated union of all built-in diffusion schedule configurations. |
Classes¶
Abstract base for diffusion paradigms. |
|
Rectified flow matching with optional minibatch optimal transport. |
|
Rectified flow matching with optional minibatch optimal transport. |
Functions¶
|
Instantiate the right |
Package Contents¶
- class noether.modeling.diffusion.DiffusionSchedule¶
Bases:
abc.ABCAbstract base for diffusion paradigms.
All schedule state (alphas, sigmas, etc.) is stored as plain tensors. Call
to()before use to move the buffers to the target device.- device: torch.device¶
- to(device)¶
Move every
Tensorattribute todevicein place.Returns
selffor chainability.- Parameters:
device (torch.device | str)
- Return type:
Self
- abstractmethod training_losses(x0, model_fn, condition=None)¶
Compute scalar training loss given clean samples
x0.- Parameters:
x0 (torch.Tensor) – Clean training samples.
model_fn (collections.abc.Callable[[torch.Tensor, torch.Tensor, torch.Tensor | None], torch.Tensor]) – Callable with signature
(noisy_input, timestep_or_sigma, condition) -> prediction.condition (torch.Tensor | None) – Optional conditioning tensor passed through to
model_fn.
- Returns:
Scalar training loss.
- Return type:
- abstractmethod sample(shape, model_fn, condition=None, steps=50)¶
Generate samples from noise.
- Parameters:
model_fn (collections.abc.Callable[[torch.Tensor, torch.Tensor, torch.Tensor | None], torch.Tensor]) – Callable with signature
(noisy_input, timestep_or_sigma, condition) -> prediction.condition (torch.Tensor | None) – Optional conditioning tensor.
steps (int) – Number of solver steps.
- Returns:
Clean samples
x0of shapeshape.- Return type:
- noether.modeling.diffusion.AnyDiffusionScheduleConfig¶
Discriminated union of all built-in diffusion schedule configurations.
Pydantic resolves the right variant by inspecting the
kindfield. Pair withbuild_schedule()to materialize the schedule object.
- noether.modeling.diffusion.build_schedule(config)¶
Instantiate the right
DiffusionScheduleforconfig.- Parameters:
config (AnyDiffusionScheduleConfig) – Any variant of
AnyDiffusionScheduleConfig.- Returns:
A
DiffusionSchedulematching the variant’skind.- Raises:
ValueError – If
configis not a recognised schedule config.- Return type:
- class noether.modeling.diffusion.FlowMatchingConfig(/, **data)¶
Bases:
pydantic.BaseModelRectified flow matching with optional minibatch optimal transport.
Discriminator:
kind = "flow_matching". Linear interpolation pathxt = t * x1 + (1-t) * x0; the network predicts the velocityv = x1 - x0.Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- kind: Literal['flow_matching'] = 'flow_matching'¶
- class noether.modeling.diffusion.FlowMatchingSchedule(config)¶
Bases:
noether.modeling.diffusion.base.DiffusionScheduleRectified flow matching with optional minibatch optimal transport.
Linear interpolation path
xt = t * x1 + (1-t) * x0; the network predicts the velocityv = x1 - x0. Logit-normal time sampling for training whencontinuous_time=True.- Parameters:
config (FlowMatchingConfig)
- config¶
- noise_pair(x1, t)¶
Noise clean data
x1at timet.- Returns:
Tuple
(xt, target_velocity).- Parameters:
x1 (torch.Tensor)
t (torch.Tensor)
- Return type:
- training_losses(x0, model_fn, condition=None)¶
Compute scalar training loss given clean samples
x0.- Parameters:
x0 – Clean training samples.
model_fn – Callable with signature
(noisy_input, timestep_or_sigma, condition) -> prediction.condition – Optional conditioning tensor passed through to
model_fn.
- Returns:
Scalar training loss.
- sample(shape, model_fn, condition=None, steps=10)¶
Generate samples from noise.
- Parameters:
shape – Output tensor shape.
model_fn – Callable with signature
(noisy_input, timestep_or_sigma, condition) -> prediction.condition – Optional conditioning tensor.
steps – Number of solver steps.
- Returns:
Clean samples
x0of shapeshape.
- training_losses_joint(x0_list, model_fn, condition=None)¶
Joint flow-matching loss over multiple clean tensors sharing batch dim.
All tensors are noised to the SAME
tper example.model_fnreceives(xt_list, t, condition)and must return a list of velocity predictions aligned withx0_list. Returns mean MSE across tensors.
- sample_joint(shapes, model_fn, condition=None, steps=10)¶
Joint Euler sampling over multiple tensors sharing batch dim.
model_fnreceives(xt_list, t, condition)and must return a list of velocities aligned withshapes. Returns the list of clean samples.