# openai/random-network-distillation architecture

> Architecture diagram of the GitHub repository openai/random-network-distillation, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/openai/random-network-distillation
- Repository: https://github.com/openai/random-network-distillation

## Overview

1. This repository is an archived reinforcement-learning training codebase for Atari, centered on the OpenAI “Exploration by Random Network Distillation” experiment. The main executable is `run_atari.py`, which ties together environment setup, policy/agent construction, and the training loop.

2. The top-level architecture is a single training pipeline with a few supporting layers:
   - Atari environment wrappers and vectorized environment execution
   - Policy networks and PPO-style optimization
   - Logging/monitoring and episode recording
   - MPI-based multi-process scaling across CPUs/GPUs/machines

3. `run_atari.py` is the orchestration entrypoint. It is responsible for reading command-line configuration, creating the Atari environment stack, instantiating the policy/agent objects, and launching training. The README’s example invocation shows this script as the main user-facing interface.

4. Environment handling is split across `atari_wrappers.py`, `vec_env.py`, and `monitor.py`. `atari_wrappers.py` likely applies the standard Atari preprocessing stack. `vec_env.py` provides batched environment execution so multiple episodes can be collected in parallel. `monitor.py` adds episode tracking and runtime statistics around each environment instance.

5. The experience collection path is therefore: raw Atari environment → preprocessing wrappers → monitored/vectorized environment → rollout batches consumed by the learner. This is the main dataflow boundary between “simulation” and “optimization.”

6. Learning logic lives in `ppo_agent.py` and the `policies/` package. The policy implementations are CNN-based Atari policies, with variants such as `cnn_gru_policy_dynamics.py` and `cnn_policy_param_matched.py`, indicating multiple network architectures or configuration-matched policy definitions. `stochastic_policy.py` suggests the action-selection interface is probabilistic rather than deterministic.

7. TensorFlow support is centralized in `tf_util.py`. This file likely abstracts session, variable, and graph utilities used by the policy and agent code. The presence of dedicated TF utilities indicates the model and optimizer are built in TensorFlow rather than being embedded directly in the environment code.

8. Multi-process and multi-machine execution is handled by `mpi_util.py`, with `cmd_util.py` helping with distributed command-line configuration or process setup. The README explicitly describes using `mpiexec` to scale to many parallel environments, so MPI is a first-class architectural boundary for throughput scaling.

9. Training output and reproducibility are supported by `recorder.py`, `replayer.py`, and `load_log.py`. These modules suggest the code can record runs, replay them, and load logs for analysis after training. `console_util.py` provides user-facing status/output formatting, while `utils.py` contains shared helpers.

10. From an architecture-diagram perspective, the key subsystems are: orchestration (`run_atari.py`), environment/simulation (`atari_wrappers.py`, `vec_env.py`, `monitor.py`), learning (`ppo_agent.py`, `policies/`, `stochastic_policy.py`, `tf_util.py`), distributed execution (`mpi_util.py`), and observability/analysis (`recorder.py`, `replayer.py`, `load_log.py`, `console_util.py`). The repository is primarily an offline training system, not a serving or inference service, and its main external dependency boundary is the Atari runtime plus MPI-enabled parallel execution.

Main entry points: [`run_atari.py`](https://github.com/openai/random-network-distillation/blob/master/run_atari.py) (run_atari.py), [`ppo_agent.py`](https://github.com/openai/random-network-distillation/blob/master/ppo_agent.py) (PPO Agent), [`vec_env.py`](https://github.com/openai/random-network-distillation/blob/master/vec_env.py) (VecEnv), [`policies/__init__.py`](https://github.com/openai/random-network-distillation/blob/master/policies/__init__.py) (policies/)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Orchestration"]
  node_run_atari["run_atari.py<br/>entrypoint<br/>[run_atari.py]"]
  node_cmd_util["cmd_util.py<br/>cli setup<br/>[cmd_util.py]"]
end

subgraph group_simulation["Simulation"]
  node_atari_wrappers["Wrappers<br/>preprocess<br/>[atari_wrappers.py]"]
  node_monitor["Monitor<br/>stats wrapper<br/>[monitor.py]"]
  node_vec_env["VecEnv<br/>batched env<br/>[vec_env.py]"]
end

subgraph group_learning["Learning"]
  node_ppo_agent["PPO Agent<br/>learner<br/>[ppo_agent.py]"]
  node_stochastic_policy["Policy API<br/>action policy"]
  node_policies_pkg["policies/<br/>policy package<br/>[__init__.py]"]
  node_cnn_gru_policy["CNN-GRU<br/>policy impl"]
  node_cnn_param_policy["CNN Matched<br/>policy impl"]
  node_tf_util["TF Utils<br/>tensorflow support<br/>[tf_util.py]"]
end

subgraph group_distributed["Distributed"]
  node_mpi_util["MPI Utils<br/>distributed runtime<br/>[mpi_util.py]"]
end

subgraph group_observability["Observability"]
  node_console_util["Console<br/>status output<br/>[console_util.py]"]
  node_recorder["Recorder<br/>run capture<br/>[recorder.py]"]
  node_replayer["Replayer<br/>run playback<br/>[replayer.py]"]
  node_load_log["Log Loader<br/>analysis<br/>[load_log.py]"]
end

node_utils["Utils<br/>shared helpers<br/>[utils.py]"]

node_run_atari -->|"configures"| node_cmd_util
node_run_atari -->|"builds env"| node_atari_wrappers
node_run_atari -->|"wraps"| node_monitor
node_run_atari -->|"vectorizes"| node_vec_env
node_run_atari -->|"launches"| node_ppo_agent
node_run_atari -->|"scales via"| node_mpi_util
node_run_atari -->|"reports"| node_console_util
node_vec_env -->|"contains"| node_atari_wrappers
node_atari_wrappers -->|"layers with"| node_monitor
node_vec_env -->|"feeds rollouts"| node_ppo_agent
node_ppo_agent -->|"uses"| node_stochastic_policy
node_ppo_agent -->|"selects"| node_policies_pkg
node_policies_pkg -->|"variant"| node_cnn_gru_policy
node_policies_pkg -->|"variant"| node_cnn_param_policy
node_ppo_agent -->|"runs on"| node_tf_util
node_ppo_agent -->|"coordinates"| node_mpi_util
node_recorder -->|"enables"| node_replayer
node_load_log -->|"formats"| node_console_util
node_ppo_agent -->|"logs to"| node_recorder
node_run_atari -->|"can record"| node_recorder
node_run_atari -->|"analyzes with"| node_load_log

click node_run_atari "https://github.com/openai/random-network-distillation/blob/master/run_atari.py"
click node_cmd_util "https://github.com/openai/random-network-distillation/blob/master/cmd_util.py"
click node_atari_wrappers "https://github.com/openai/random-network-distillation/blob/master/atari_wrappers.py"
click node_monitor "https://github.com/openai/random-network-distillation/blob/master/monitor.py"
click node_vec_env "https://github.com/openai/random-network-distillation/blob/master/vec_env.py"
click node_ppo_agent "https://github.com/openai/random-network-distillation/blob/master/ppo_agent.py"
click node_stochastic_policy "https://github.com/openai/random-network-distillation/blob/master/stochastic_policy.py"
click node_policies_pkg "https://github.com/openai/random-network-distillation/blob/master/policies/__init__.py"
click node_cnn_gru_policy "https://github.com/openai/random-network-distillation/blob/master/policies/cnn_gru_policy_dynamics.py"
click node_cnn_param_policy "https://github.com/openai/random-network-distillation/blob/master/policies/cnn_policy_param_matched.py"
click node_tf_util "https://github.com/openai/random-network-distillation/blob/master/tf_util.py"
click node_mpi_util "https://github.com/openai/random-network-distillation/blob/master/mpi_util.py"
click node_console_util "https://github.com/openai/random-network-distillation/blob/master/console_util.py"
click node_recorder "https://github.com/openai/random-network-distillation/blob/master/recorder.py"
click node_replayer "https://github.com/openai/random-network-distillation/blob/master/replayer.py"
click node_load_log "https://github.com/openai/random-network-distillation/blob/master/load_log.py"
click node_utils "https://github.com/openai/random-network-distillation/blob/master/utils.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_run_atari,node_cmd_util toneBlue
class node_atari_wrappers,node_monitor,node_vec_env toneAmber
class node_ppo_agent,node_stochastic_policy,node_policies_pkg,node_cnn_gru_policy,node_cnn_param_policy,node_tf_util toneMint
class node_mpi_util toneRose
class node_console_util,node_recorder,node_replayer,node_load_log toneIndigo
class node_utils toneNeutral
```

## Components

### Orchestration

Entry point and runtime configuration for Atari training.

- [run_atari.py](https://github.com/openai/random-network-distillation/blob/master/run_atari.py): entrypoint · Main training executable that wires configuration, environment setup, policy construction, and learning. · `run_atari.py`
- [cmd_util.py](https://github.com/openai/random-network-distillation/blob/master/cmd_util.py): cli setup · Command-line and process-setup helpers used to configure runs. · `cmd_util.py`

### Simulation

Atari environment construction, preprocessing, and batched rollout execution.

- [Wrappers](https://github.com/openai/random-network-distillation/blob/master/atari_wrappers.py): preprocess · Atari preprocessing and environment wrapper stack. · `atari_wrappers.py`
- [Monitor](https://github.com/openai/random-network-distillation/blob/master/monitor.py): stats wrapper · Tracks episode statistics and runtime monitoring around environments. · `monitor.py`
- [VecEnv](https://github.com/openai/random-network-distillation/blob/master/vec_env.py): batched env · Vectorized environment execution for parallel rollout collection. · `vec_env.py`

### Learning

Policy, agent, and TensorFlow-based optimization components.

- [PPO Agent](https://github.com/openai/random-network-distillation/blob/master/ppo_agent.py): learner · Training logic that consumes rollouts and updates the policy. · `ppo_agent.py`
- [Policy API](https://github.com/openai/random-network-distillation/blob/master/stochastic_policy.py): action policy · Probabilistic action-selection interface shared by policy implementations. · `stochastic_policy.py`
- [policies/](https://github.com/openai/random-network-distillation/blob/master/policies/__init__.py): policy package · CNN-based Atari policy implementations and variants. · `policies/__init__.py`
- [CNN-GRU](https://github.com/openai/random-network-distillation/blob/master/policies/cnn_gru_policy_dynamics.py): policy impl · Policy variant with recurrent dynamics. · `policies/cnn_gru_policy_dynamics.py`
- [CNN Matched](https://github.com/openai/random-network-distillation/blob/master/policies/cnn_policy_param_matched.py): policy impl · CNN policy variant aligned to a parameter-matched configuration. · `policies/cnn_policy_param_matched.py`
- [TF Utils](https://github.com/openai/random-network-distillation/blob/master/tf_util.py): tensorflow support · TensorFlow session, graph, and variable utilities used by learning code. · `tf_util.py`

### Distributed

MPI-oriented scaling and process setup.

- [MPI Utils](https://github.com/openai/random-network-distillation/blob/master/mpi_util.py): distributed runtime · MPI helpers for multi-process scaling across machines or CPUs/GPUs. · `mpi_util.py`

### Observability

Logging, recording, replay, and human-facing status output.

- [Console](https://github.com/openai/random-network-distillation/blob/master/console_util.py): status output · Human-facing progress and status formatting utilities. · `console_util.py`
- [Recorder](https://github.com/openai/random-network-distillation/blob/master/recorder.py): run capture · Records training runs and environment traces for later inspection. · `recorder.py`
- [Replayer](https://github.com/openai/random-network-distillation/blob/master/replayer.py): run playback · Replays recorded runs for analysis or debugging. · `replayer.py`
- [Log Loader](https://github.com/openai/random-network-distillation/blob/master/load_log.py): analysis · Loads and parses training logs for post-run inspection. · `load_log.py`

### Other components

- [Utils](https://github.com/openai/random-network-distillation/blob/master/utils.py): shared helpers · General-purpose helpers shared across the codebase. · `utils.py`

## Connections

- run_atari.py → cmd_util.py: configures · Uses CLI/process helpers to build the training run.
- run_atari.py → Wrappers: builds env · Creates the Atari preprocessing stack.
- run_atari.py → Monitor: wraps · Adds episode monitoring around environments.
- run_atari.py → VecEnv: vectorizes · Runs environments in batched parallel execution.
- run_atari.py → PPO Agent: launches · Instantiates the learner and starts optimization.
- run_atari.py → MPI Utils: scales via · Uses MPI helpers for distributed execution.
- run_atari.py → Console: reports · Prints training progress and status output.
- VecEnv → Wrappers: contains · Vectorized execution wraps preprocessed Atari environments.
- Wrappers → Monitor: layers with · Monitoring is applied around environment instances.
- VecEnv → PPO Agent: feeds rollouts · Produces batches of experience consumed by the learner.
- PPO Agent → Policy API: uses · Learner depends on the probabilistic action interface.
- PPO Agent → policies/: selects · Builds a concrete policy implementation.
- policies/ → CNN-GRU: variant · Recurrent policy variant.
- policies/ → CNN Matched: variant · Parameter-matched CNN policy variant.
- PPO Agent → TF Utils: runs on · Uses TensorFlow utilities for graph/session management.
- PPO Agent → MPI Utils: coordinates · Supports multi-process optimization and synchronization.
- Recorder → Replayer: enables · Recorded runs can be replayed for analysis.
- Log Loader → Console: formats · Leverages shared formatting for readable analysis output.
- PPO Agent → Recorder: logs to · Captures run artifacts and traces during training.
- run_atari.py → Recorder: can record · Entry point can enable recording during execution.
- run_atari.py → Log Loader: analyzes with · Supports loading logs for post-run inspection.
