xwm.objectives¶
Losses: latent prediction, SIGReg, VICReg, InfoNCE, and the distributional statistics SIGReg is built from. See Collapse.
Training objectives for predictive world models.
Two independent choices make up a JEPA objective:
- What to predict, and how to score it --
prediction_loss, always computed in latent space. - How to prevent collapse --
sigreg(LeJEPA: constrain the embedding distribution),vicreg(constrain its first two moments),info_nce(contrast against negatives), or an EMA teacher (architectural, seexwm.core.ema).
Mixing and matching those two axes is what the model classes in
xwm.image, xwm.video and xwm.action expose.
Modules:
| Name | Description |
|---|---|
prediction |
Latent prediction losses -- the primary signal in every JEPA. |
regularizers |
Variance/covariance regularizers (VICReg) and the InfoNCE contrastive loss. |
sigreg |
SIGReg -- Sketched Isotropic Gaussian Regularization (the LeJEPA objective). |
Functions:
| Name | Description |
|---|---|
layer_normalize |
Parameter-free LayerNorm over the last axis. |
prediction_loss |
Distance between predicted and target embeddings, averaged over everything. |
covariance_loss |
Penalise off-diagonal covariance, decorrelating the dimensions. |
info_nce |
Symmetric InfoNCE over in-batch negatives. |
variance_loss |
Hinge each dimension's standard deviation up to |
vicreg |
Variance-Invariance-Covariance regularization on two views. |
cramer_von_mises |
CDF distance from |
epps_pulley |
Characteristic-function distance from |
random_directions |
|
layer_normalize
¶
Parameter-free LayerNorm over the last axis.
Applied to prediction targets it removes the scale degree of freedom that a teacher/student pair can otherwise exploit to shrink the loss without improving prediction. V-JEPA normalises targets this way.
Source code in xwm/objectives/prediction.py
prediction_loss
¶
prediction_loss(pred: Array, target: Array, *, kind: LossKind = 'l1', beta: float = 1.0, normalize_target: bool = False) -> Array
Distance between predicted and target embeddings, averaged over everything.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pred
|
Array
|
predicted embeddings, any shape ending in |
required |
target
|
Array
|
same shape as |
required |
kind
|
LossKind
|
|
'l1'
|
beta
|
float
|
transition point of the smooth-L1 / Huber loss. |
1.0
|
normalize_target
|
bool
|
LayerNorm the target (and, for symmetry, the prediction) before comparing. |
False
|
Returns:
| Type | Description |
|---|---|
Array
|
A scalar. |
Source code in xwm/objectives/prediction.py
covariance_loss
¶
Penalise off-diagonal covariance, decorrelating the dimensions.
z is (..., D); see variance_loss on leading axes.
Source code in xwm/objectives/regularizers.py
info_nce
¶
Symmetric InfoNCE over in-batch negatives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z_a, z_b
|
|
required |
Source code in xwm/objectives/regularizers.py
variance_loss
¶
Hinge each dimension's standard deviation up to gamma.
z is (..., D); leading axes are all treated as samples, matching
xwm.objectives.sigreg, so a token sequence (B, N, D) contributes
B * N samples rather than erroring.
Source code in xwm/objectives/regularizers.py
vicreg
¶
vicreg(z_a: Array, z_b: Array, *, sim_coeff: float = 25.0, var_coeff: float = 25.0, cov_coeff: float = 1.0, gamma: float = 1.0) -> tuple[Array, dict[str, Array]]
Variance-Invariance-Covariance regularization on two views.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z_a, z_b
|
|
required |
Returns:
| Type | Description |
|---|---|
tuple[Array, dict[str, Array]]
|
|
Source code in xwm/objectives/regularizers.py
cramer_von_mises
¶
CDF distance from u to N(0, 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Array
|
|
required |
Returns:
| Type | Description |
|---|---|
Array
|
|
Array
|
independent of |
Source code in xwm/objectives/sigreg.py
epps_pulley
¶
Characteristic-function distance from u to N(0, 1).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Array
|
|
required |
n_nodes
|
int
|
quadrature nodes; 32 is ample for so smooth an integrand. |
32
|
sigma
|
float
|
width of the quadrature weight, i.e. which frequencies the test emphasises. Larger values probe finer structure in the tails. |
1.0
|
Returns:
| Type | Description |
|---|---|
Array
|
|
Array
|
function matches |
The quadrature is a jax.lax.scan rather than one batched einsum:
the dense form would allocate n * P * n_nodes floats, which at a real
batch size (n in the tens of thousands once tokens are counted) reaches
hundreds of megabytes for a term that is only a scalar penalty. Scanning
keeps the footprint at n * P.
Source code in xwm/objectives/sigreg.py
random_directions
¶
(dim, n_proj) directions drawn uniformly from the unit sphere.
sigreg¶
Note
xwm.objectives.sigreg is both a submodule and the function it exports. The
function is documented here under its canonical path; xwm.objectives.sigreg(...)
is the way to call it.
Sketched isotropic-Gaussian regularizer for a batch of embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
Array
|
|
required |
key
|
PRNGKey
|
RNG for the projection directions. Redraw it each step -- fresh
directions are what make the sketch cover all of |
required |
n_proj
|
int
|
number of random directions. |
512
|
statistic
|
Statistic
|
which goodness-of-fit test to use. |
'epps_pulley'
|
n_nodes, sigma
|
quadrature settings for |
required | |
center
|
bool
|
subtract the batch mean before testing. Off by default, because driving the mean to zero is part of the job. |
False
|
Returns:
| Type | Description |
|---|---|
Array
|
A scalar, minimised when the embeddings look isotropic Gaussian. |