Skip to content

TD-JEPA ​

INFO

Esta página aún no está traducida. Leer en inglés

Bagatella, Pirotta, Touati, Lazaric and Tirinzoni, TD-JEPA: Latent-predictive Representations for Zero-Shot Reinforcement Learning, ICLR 2026. Paper · Code: not released · Notebook

TD-JEPA learns, from reward-free transitions, a state encoder ϕ, a task encoder ψ and a family of policies πz, one for every task embedding z. Its predictor is not a one-step dynamics model. Tϕ(ϕ(s),a,z) predicts the discounted sum of future ψ embeddings when πz acts from (s,a): the successor features of ψ. That sum has a Bellman equation, so the predictor is trained by temporal-difference latent prediction against EMA target networks. A second predictor Tψ does the same with the roles of ϕ and ψ swapped:

LTD(ϕ,Tϕ,ψ)=12‖Tϕ(ϕ(s),a,z)−ψ¯(s′)−γT¯ϕ(ϕ¯(s′),a′,z)‖2,a′∼π(ϕ¯(s′),z)L=LTD(ϕ,Tϕ,ψ)+LTD(ψ,Tψ,ϕ)+λ(Lreg(ϕ)+Lreg(ψ))−Tϕ(ϕ(s),a^,z)⊤z,a^∼π(ϕ(s),z)

Bars are target networks. Lreg(x)=12B(B−1)∑i≠j(xi⊤xj)2−1B∑ixi⊤xi pushes E[xx⊤] toward the identity. Since Tϕ(ϕ(s),a,z)⊤z is the Q-value of πz for the reward r(s)=ψ(s)⊤z, the last term trains each policy to be greedy for its own task. At test time nothing is trained. Given rewarded samples, zr=E[ψψ⊤]−1E[ψr] is a linear regression. Given a goal observation g, zg=ψ(g), optionally whitened by E[ψψ⊤]−1 (the regression of a reward that is one at g). Then πz acts.

Usage ​

python
from torch_world.models import TDJEPA
from torch_world.models.jepa import drq_encoder

model = TDJEPA(drq_encoder(256), drq_encoder(50, hidden_layers=2), action_dim=2, discount=0.98)
opt = torch.optim.Adam(model.param_groups(1e-4))

out = model(pixels, actions)              # transitions (B, 2, C, H, W), (B, 2, A); actions[:, 0] is taken at s
# out: {"loss", "td_phi_loss", "td_psi_loss", "ortho_loss", "actor_loss"}
model.update_target(0.995)                # after each optimizer step

z_goal = model.goal_task(goal_images)     # (B, task_dim), no training
z_reward = model.infer_task(frames, r)    # (task_dim,) from rewards r (N,) at frames (N, C, H, W)
policy = model.controller(z_goal)         # observation (B, C, H, W) -> action (B, A)
action = model.policy(model.encode(obs[:, None])[:, 0], z_goal)
q = model.value(z, action, z_goal)        # T_phi(z, a, task) . task

TDJEPA subclasses JEPA, not WorldModel: its predictor forecasts discounted future embeddings under a policy, not the next latent, so there is nothing for CEM or MPPI to unroll. It acts with its own task-conditioned policy instead. forward returns the encoder, predictor and actor losses together. Their gradients reach disjoint parameters: the actor sees detached ϕ and a predictor whose parameters it cannot update, and ψ¯, ϕ¯ are targets. One backward pass therefore matches Algorithm 1's three updates.

The defaults follow the paper's DMC-from-pixels column (Table 4): dϕ=256, dψ=50, predictor width 1024, γ=0.98, λ=1, learning rate 10−4 with Adam, pgoal=0.5 and a Gaussian actor with fixed std 0.2. Training tasks z are uniform on the sphere of radius dψ, or with probability pgoal are ψ of random dataset states (here the batch's next observations, shuffled). Targets and values use the mean of twin predictor heads. The pixel encoders, drq_encoder, are DrQ-v2's convolutions with random shifts of up to 2 pixels, a linear head for ϕ and a two-layer MLP for ψ.

The notebook trains on Two-Rooms random-action pixels for 15k steps, with no rewards. It then reaches goal images in the other room 98% of the time (random actions: 3%) and solves three unseen rewards, each inferred by one linear regression, in 89% to 100% of episodes.

Choices the paper leaves open, and deviations:

  • No released code. Network layouts follow Touati et al. (2023), which the paper cites for its architectures. Predictors embed [x,a] and [x,z] each with Linear, LayerNorm and Tanh, then Linear and ReLU to half width, and twin ReLU heads share these embeddings. The actor embeds [x,z] and x the same way. Its noise is clipped at 0.3, as in Touati et al.'s code.
  • Normalization. The paper says encoder outputs are L2-normalized. Here they are projected to radius d, the scale of the task sphere, as in Touati et al.'s code. Inferred tasks are projected onto the same sphere.
  • Actor loss. The paper's pseudocode adds +(Tϕ⋅z) to the loss, which contradicts Algorithm 1's −. This implementation follows Algorithm 1. It also stops the actor loss from updating Tϕ, as Algorithm 1's separate updates imply.
  • Twins. Each twin head is regressed onto the shared target and the losses are averaged over heads.
  • Goals. The paper evaluates goal-reaching by regressing a goal reward. goal_task uses ψ(g), or the whitened E[ψψ⊤]−1ψ(g) of its Appendix D.5 when reference observations are passed. On Two-Rooms, plain ψ(g) worked far better: in a tuning run at 20k steps it reached 98% of goals in the other room, against 41% for the version whitened on 1,024 dataset frames.
  • Not included: the FlowQ-style behavior-cloning regularizer the paper adds on OGBench's narrow datasets, frame stacking (Two-Rooms images are Markov), and the TD3 fine-tuning of Section 5.4.
  • Scale. The paper trains for 1 to 2M steps. The notebook trains for far fewer.

Reference ​

Arguments and methods: TDJEPA in the API reference.