dew.objectives.jepa
| Name | Summary |
|---|---|
FactorizedTokenStack | Spatial then temporal blocks over [B, T, N, F], as in VideoDiT. |
JepaEncoder | ViT over an image, optionally restricted to a subset of its patches. |
JepaObjective | Joint-embedding prediction over images (B,H,W,C) or video (B,T,H,W,C). |
JepaPredictor | Narrow transformer from context embeddings to target embeddings. |
JepaVideoEncoder | Factorized spatial-temporal encoder over (B, T, H, W, C). |
KnnProbe | Report cosine k-NN accuracy over each validation batch’s representations. |
LinearProbe | Report linear probe accuracy over each validation batch’s representations. |
MultiBlockMask | Hold one patch grid’s static mask geometry, and sample masks over it. |
TokenStack | A stack of unmodulated blocks over a token sequence. |
knn_probe | |
knn_probe_accuracy | Score cosine k-NN accuracy, fitting on half the batch and scoring the rest. |
linear_probe | |
linear_probe_accuracy | Fit a logistic regression on half the batch and score its accuracy on the rest. |
multi_block_mask | Resolve the I-JEPA mask geometry for a patch grid. |
normalize_targets | Feature-wise layer norm with no learned affine. |
representation_health | Report collapse telemetry for pooled embeddings [B, D]. |
FactorizedTokenStack
Section titled “FactorizedTokenStack”class FactorizedTokenStack( mlp_ratio: int = 4, ssm_attention_ratio: str = 'all-attn', block_pattern: Sequence[str] | None = None, ssm_state_dim: int = 64, bidirectional_ssm: bool = True, dropout_rate: float = 0.0, dtype: Dtype | None = None, precision: PrecisionLike = None, force_fp32_for_softmax: bool = True, norm_epsilon: float = 1e-05, qk_norm: bool = False, attention_impl: str = 'auto',)Spatial then temporal blocks over [B, T, N, F], as in VideoDiT.
Time is a real 1D axis that masking never touches, so the temporal half is rotated by frame index while the spatial half runs unrotated.
FactorizedTokenStack.setup
Section titled “FactorizedTokenStack.setup”def setup()JepaEncoder
Section titled “JepaEncoder”class JepaEncoder( patch_size: int = 16, emb_features: int = 384, num_layers: int = 12, num_heads: int = 6, mlp_ratio: int = 4, ssm_attention_ratio: str = 'all-attn', ssm_state_dim: int = 64, bidirectional_ssm: bool = True, dropout_rate: float = 0.0, dtype: Dtype | None = None, precision: PrecisionLike = None, force_fp32_for_softmax: bool = True, norm_epsilon: float = 1e-05, qk_norm: bool = False, attention_impl: str = 'auto', scan_order: Literal['raster', 'hilbert', 'zigzag'] = 'raster',)ViT over an image, optionally restricted to a subset of its patches.
JepaEncoder.setup
Section titled “JepaEncoder.setup”def setup()JepaObjective
Section titled “JepaObjective”class JepaObjective( encoder: nn.Module, predictor: nn.Module, mask: MultiBlockMask, sample: Field, momentum: tuple[float, float] = (0.996, 1.0), momentum_steps: int = 100000, label_key: str = LABEL_KEY,)Joint-embedding prediction over images (B,H,W,C) or video (B,T,H,W,C).
Evaluation returns the pooled target-encoder embeddings of a batch with its labels, which the probe metrics score.
JepaObjective.init
Section titled “JepaObjective.init”def init(key, variables: Variables | None = None)JepaObjective.encode
Section titled “JepaObjective.encode”def encode(encoder_params, samples, token_idx=None, train=False, rngs=None) -> jax.ArrayJepaObjective.loss
Section titled “JepaObjective.loss”def loss(params, batch, step: Step)JepaObjective.evaluate
Section titled “JepaObjective.evaluate”def evaluate(params, batch, step: Step)The frozen target encoder’s pooled embeddings, with the batch labels.
JepaPredictor
Section titled “JepaPredictor”class JepaPredictor( grid: tuple[int, int] = (14, 14), emb_features: int = 384, predictor_features: int = 192, num_layers: int = 6, num_heads: int = 6, mlp_ratio: int = 4, ssm_attention_ratio: str = 'all-attn', ssm_state_dim: int = 64, bidirectional_ssm: bool = True, dropout_rate: float = 0.0, dtype: Dtype | None = None, precision: PrecisionLike = None, force_fp32_for_softmax: bool = True, norm_epsilon: float = 1e-05, qk_norm: bool = False, attention_impl: str = 'auto', scan_order: str = 'raster', factorized: bool = False,)Narrow transformer from context embeddings to target embeddings.
Context tokens are projected down, mask tokens stand in for the targets, and both carry the sincos signal for the grid position they belong to.
JepaPredictor.setup
Section titled “JepaPredictor.setup”def setup()JepaVideoEncoder
Section titled “JepaVideoEncoder”class JepaVideoEncoder( patch_size: int = 16, emb_features: int = 384, num_layers: int = 12, num_heads: int = 6, mlp_ratio: int = 4, ssm_attention_ratio: str = 'all-attn', ssm_state_dim: int = 64, bidirectional_ssm: bool = True, dropout_rate: float = 0.0, dtype: Dtype | None = None, precision: PrecisionLike = None, force_fp32_for_softmax: bool = True, norm_epsilon: float = 1e-05, qk_norm: bool = False, attention_impl: str = 'auto', scan_order: Literal['raster', 'hilbert', 'zigzag'] = 'raster',)Factorized spatial-temporal encoder over (B, T, H, W, C).
token_idx selects a tubelet: the same patch positions in every frame, so the factorized layout survives masking untouched.
JepaVideoEncoder.setup
Section titled “JepaVideoEncoder.setup”def setup()KnnProbe
Section titled “KnnProbe”class KnnProbe(num_classes: int, k: int = 20)Report cosine k-NN accuracy over each validation batch’s representations.
KnnProbe.merge
Section titled “KnnProbe.merge”def merge( accumulated: tuple[float, float], contribution: tuple[float, float],) -> tuple[float, float]KnnProbe.finalize
Section titled “KnnProbe.finalize”def finalize(accumulated: tuple[float, float]) -> floatLinearProbe
Section titled “LinearProbe”class LinearProbe( num_classes: int, steps: int = 100, learning_rate: float = 0.01, weight_decay: float = 0.0001,)Report linear probe accuracy over each validation batch’s representations.
LinearProbe.merge
Section titled “LinearProbe.merge”def merge( accumulated: tuple[float, float], contribution: tuple[float, float],) -> tuple[float, float]LinearProbe.finalize
Section titled “LinearProbe.finalize”def finalize(accumulated: tuple[float, float]) -> floatMultiBlockMask
Section titled “MultiBlockMask”class MultiBlockMask( grid: tuple[int, int], num_targets: int, block_shapes: tuple[tuple[int, int], ...], num_context: int,)Hold one patch grid’s static mask geometry, and sample masks over it.
MultiBlockMask.sample
Section titled “MultiBlockMask.sample”def sample(rng: jax.Array, batch_size: int)Draw one batch of context and target token indices.
Returns the context indices, [B, num_context], and the target
indices, [B, num_targets, block_area].
TokenStack
Section titled “TokenStack”class TokenStack( mlp_ratio: int = 4, ssm_attention_ratio: str = 'all-attn', block_pattern: Sequence[str] | None = None, ssm_state_dim: int = 64, bidirectional_ssm: bool = True, dropout_rate: float = 0.0, dtype: Dtype | None = None, precision: PrecisionLike = None, force_fp32_for_softmax: bool = True, norm_epsilon: float = 1e-05, qk_norm: bool = False, attention_impl: str = 'auto',)A stack of unmodulated blocks over a token sequence.
TokenStack.setup
Section titled “TokenStack.setup”def setup()knn_probe
Section titled “knn_probe”def knn_probe(num_classes: int, k: int = 20) -> KnnProbeknn_probe_accuracy
Section titled “knn_probe_accuracy”def knn_probe_accuracy(embeddings, labels, num_classes: int, k: int = 20)Score cosine k-NN accuracy, fitting on half the batch and scoring the rest.
linear_probe
Section titled “linear_probe”def linear_probe( num_classes: int, steps: int = 100, learning_rate: float = 0.01, weight_decay: float = 0.0001,) -> LinearProbelinear_probe_accuracy
Section titled “linear_probe_accuracy”def linear_probe_accuracy( embeddings, labels, num_classes: int, steps: int = 100, learning_rate: float = 0.01, weight_decay: float = 0.0001,)Fit a logistic regression on half the batch and score its accuracy on the rest.
multi_block_mask
Section titled “multi_block_mask”def multi_block_mask( grid: tuple[int, int], num_targets: int = 4, scale: tuple[float, float] = (0.15, 0.2), aspect: tuple[float, float] = (0.75, 1.5),) -> MultiBlockMaskResolve the I-JEPA mask geometry for a patch grid.
normalize_targets
Section titled “normalize_targets”def normalize_targets(x, epsilon: float = 1e-06)Feature-wise layer norm with no learned affine.
Applied to the target encoder’s output so the prediction problem keeps a fixed scale as the encoder drifts. Shrinking the representation then does not lower the loss.
representation_health
Section titled “representation_health”def representation_health(z) -> dict[str, jax.Array]Report collapse telemetry for pooled embeddings [B, D].
repr_std is the per-dimension standard deviation across the batch. It goes to zero exactly when the encoder stops distinguishing inputs. repr_cov_offdiag is the RMS magnitude of the off-diagonal covariance, which rises when the dimensions become redundant (dimensional collapse) while repr_std holds.
Both are computed in fp32. A run’s compute dtype then does not set the noise floor of the drift, and bf16 and fp32 runs read off the same curves.