N Neurarch Architectures Models Checks Data Docs Open the app

Architectures / Reinforcement Learning

🌍 DreamerV3 World Model (RSSM)

Hafner 2023 - the agent learns a model of the environment and plans inside it. A deterministic recurrent path runs beside a categorical stochastic latent.

From Hafner et al. (2023). Mastering Diverse Domains through World Models. This page is the graph, not the PDF: open it, edit it, verify it, export it.

Layers
21
Parameters
13.71M
Input
3 × 64 × 64
Output
3 × 64 × 64
Verifier
1 advisory

Every number on this page is computed from the graph by the same functions the app runs, not written by hand.

Open DreamerV3 World Model (RSSM) on the canvas Free, no account needed

When to pick it

Pick when environment steps are expensive and imagined rollouts are cheaper than real ones. The state width is deterDim + stochDim x stochClasses, not deterDim.

Structure

21 layers. Output shapes are propagated from the input shape, batch dimension excluded.

LayerTypeParametersOutput shape
1Observation (64x64 RGB)Inputshape=[3, 64, 64]3 × 64 × 64
2Encoder Conv 32Conv2DoutChannels=32, inChannels=3, kernelSize=432 × 32 × 32
3SiLUSwish32 × 32 × 32
4Encoder Conv 64Conv2DoutChannels=64, inChannels=32, kernelSize=464 × 16 × 16
5SiLUSwish64 × 16 × 16
6Encoder Conv 128Conv2DoutChannels=128, inChannels=64, kernelSize=4128 × 8 × 8
7SiLUSwish128 × 8 × 8
8Encoder Conv 256Conv2DoutChannels=256, inChannels=128, kernelSize=4256 × 4 × 4
9SiLUSwish256 × 4 × 4
10flattenFlatten4096
11RSSM (deter 512 + 32x32 stoch)RSSM (Dreamer)1536
12Decoder ProjectionLinearoutFeatures=4096, inFeatures=15364096
13to [256, 4, 4]Reshapeshape=[256, 4, 4]256 × 4 × 4
14Decoder Deconv 128TransposeConv2DoutChannels=128, kernelSize=4, stride=2128 × 8 × 8
15SiLUSwish128 × 8 × 8
16Decoder Deconv 64TransposeConv2DoutChannels=64, kernelSize=4, stride=264 × 16 × 16
17SiLUSwish64 × 16 × 16
18Decoder Deconv 32TransposeConv2DoutChannels=32, kernelSize=4, stride=232 × 32 × 32
19SiLUSwish32 × 32 × 32
20Decoder Deconv 3TransposeConv2DoutChannels=3, kernelSize=4, stride=23 × 64 × 64
21reconstructed frameOutput3 × 64 × 64

What the verifier says

The same 43 structural checks that run on every edit in the app, on this graph.

warn9 conv/linear layers detected but no residual (Add/Skip) layers. Networks deeper than 8 layers are highly prone to vanishing gradients without skip connections. Fix: Add Residual or Add layers every 2-4 layers (ResNet-style). For transformers, use the built-in TransformerBlock which includes residuals.
deep-no-residual
info19 layers with no BatchNorm, LayerNorm, or GroupNorm. Without normalization, activations can explode or vanish across layers, causing slow or unstable training. Fix: Add BatchNorm after Conv2d (CV tasks), LayerNorm after attention/FFN (NLP/LLM), or GroupNorm for small batch sizes.
deep-no-norm

The PyTorch it exports

Generated from the graph above. First 46 lines; the app exports the whole file, plus the training loop, the data contract and a deploy bundle.

# Architecture designed with Neurarch: https://neurarch.com
# PyTorch: compatible with Python 3.8+ and torch>=1.12
# Colab: pip install torch torchvision  (usually pre-installed)

import torch
import torch.nn as nn
import torch.nn.functional as F
from typing import Tuple

class RSSM(nn.Module):
    """Dreamer's recurrent state-space model: a deterministic recurrent path
    beside a categorical stochastic latent. Everything downstream reads their
    CONCATENATION, so the state width is deter_dim + stoch_dim * stoch_classes,
    which is the number a plain GRU would get wrong."""

    def __init__(self, embed_dim: int, deter_dim: int = 512, stoch_dim: int = 32,
                 stoch_classes: int = 32, hidden_dim: int = 512):
        super().__init__()
        self.deter_dim, self.stoch_dim, self.stoch_classes = deter_dim, stoch_dim, stoch_classes
        flat = stoch_dim * stoch_classes
        self.cell = nn.GRUCell(flat, deter_dim)
        self.prior = nn.Sequential(
            nn.Linear(deter_dim, hidden_dim), nn.SiLU(), nn.Linear(hidden_dim, flat))
        self.post = nn.Sequential(
            nn.Linear(deter_dim + embed_dim, hidden_dim), nn.SiLU(), nn.Linear(hidden_dim, flat))

    def forward(self, embed: torch.Tensor, state=None) -> torch.Tensor:
        b = embed.size(0)
        flat = self.stoch_dim * self.stoch_classes
        if state is None:
            deter = embed.new_zeros(b, self.deter_dim)
            stoch = embed.new_zeros(b, flat)
        else:
            deter, stoch = state
        deter = self.cell(stoch, deter)
        # self.prior(deter) is the imagination branch: it predicts the same
        # latent WITHOUT an observation, and the KL between the two is the
        # world model's training signal. Observed steps use the posterior.
        logits = self.post(torch.cat([deter, embed], dim=-1))
        stoch = logits.view(b, self.stoch_dim, self.stoch_classes).softmax(-1).reshape(b, flat)
        return torch.cat([deter, stoch], dim=-1)


class DreamerV3WorldModelRSSM(nn.Module):
    def __init__(self):
        super().__init__()

For agents

This architecture is machine-readable end to end. An agent can list the set, fetch this graph, edit it, and have the edit verified before any GPU time is spent.