HWM
INFO
Esta página aún no está traducida. Leer en inglés
Zhang et al., Hierarchical Planning with Latent World Models, 2026. Paper · Code · Notebook
HWM plans over long horizons with two action-conditioned world models that share one latent space. The low level predicts the next latent from a primitive action. The high level predicts the latent stride steps later, the next waypoint, from a latent macro-action LeWM, so the encoder learns from pixels with SIGReg. The high level reads the low level's latents through a stop-gradient, as HWM trains it on a frozen encoder. Each level has HWM's ℓ1 teacher-forcing loss. The low level also has the ℓ1 multi-step rollout loss
Planning is top-down, and the plan is redone after every executed step:
- The high level searches macro-actions
that minimize . - Its first predicted waypoint
becomes the subgoal. - The low level searches the next
strideactions that minimize.
Usage
from torch_world.models import HWM, LeWM
from torch_world.nn import CLSEncoder
from torch_world.planning import CEM, HierarchicalPlanner
low = LeWM(CLSEncoder(img_size=64, patch_size=8, embed_dim=128, depth=4, num_heads=4), action_dim=2, embed_dim=128,
history=3, depth=4, num_heads=4, head_dim=32, mlp_dim=512, proj_dim=512, lamb=0.05)
model = HWM(low, action_dim=2, stride=4, macro_dim=8, embed_dim=128, history=3, depth=4, num_heads=4, head_dim=32,
mlp_dim=512)
out = model(pixels, actions) # (B, 3 * 4 + 1, C, H, W), (B, 3 * 4 + 1, A): 4 waypoints
# out: {"loss", "low_loss", "rollout_loss", "sigreg_loss", "high_loss"}
planner = HierarchicalPlanner(
CEM(horizon=5, action_dim=8, bounds=(-2, 2)), # macro-actions toward the goal
CEM(horizon=4, action_dim=2, bounds=(-1, 1)), # primitive actions toward the first waypoint
)
plan = planner(model, model.encode(obs[:, None]), model.encode(goal_images[:, None])[:, 0]) # (B, 4, 2)The macro-action encoder ends with a BatchNorm without affine parameters, so training macro-actions are standardized. The high-level planner can then sample them from shrink_every, HierarchicalPlanner shortens the high horizon as the episode runs, as the paper does.
The high level is trained with teacher forcing by default, as in the paper's Franka and Push-T setups. On Diverse Maze, where the paper measures its largest gain over flat planning, the high level is instead trained on its own autoregressive rollouts (gamma_tf_high=0.0, gamma_roll_high=1.0 for the maze recipe; setting gamma_tf_high=0.0 skips the teacher-forcing forward pass, so training windows can span more macro steps than high.history:
model = HWM(low, action_dim=2, stride=4, macro_dim=8, gamma_tf_high=0.0, gamma_roll_high=1.0, ...)
# out has "high_rollout_loss" instead of "high_loss"At small training budgets on a jointly trained SIGReg encoder, keeping both terms (gamma_tf_high=1.0, gamma_roll_high=1.0) can outperform pure rollout (45% against 27% on Two-Rooms opposite room; see benchmark results).
The paper also shortens the high horizon by one every stride low-level steps, down to 3 on Diverse Maze: HierarchicalPlanner(high, low, shrink_every=4, min_horizon=3) when replanning after every step.
The paper differs from this implementation in a few ways:
- Encoder: frozen pre-trained encoders (V-JEPA 2, DINOv2) or PLDM's, where here a LeWM encoder learns from pixels.
- Waypoints: variable spacing with a transformer macro-action encoder on Franka and Push-T. The fixed stride and MLP encoder used here are the paper's maze setup.
- Planner: MPPI in the maze, where this implementation runs CEM at both levels. The maze's low-level cost averages the last three predicted latents against the subgoal, where
HierarchicalPlannerscores the last one; for the final 15 steps the paper drops the high level and plans flat toward the goal with a horizon of 50.
Call recompute_batchnorm before planning, as for LeWM.
Reference
Arguments and methods: HWM and HierarchicalPlanner in the API reference.
