# google-deepmind/alphastar architecture

> Architecture diagram of the GitHub repository google-deepmind/alphastar, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google-deepmind/alphastar
- Repository: https://github.com/google-deepmind/alphastar

## Overview

##### Project type and purpose
- This is an open‐source deep reinforcement learning framework from DeepMind for training StarCraft II agents.
- It ships with general purpose neural network architectures (`alphastar/architectures/`), training/evaluation modules (`alphastar/modules/`), utilities (`alphastar/commons/`, `alphastar/collections/`), logging (`alphastar/loggers/`), and a fully offline “Unplugged” RL pipeline (`alphastar/unplugged/`).

##### File structure
- Top-level build or packaging: `WORKSPACE`, `setup.py`, Bazel (`bazel/`), `requirements.txt`.
- Core code under `alphastar/` partitioned into:
- `architectures/`: model definitions (standard, modular, dummy) and reusable components (encoders, heads, static data, utilities).
- `collections/` & `types/`: data structures and type definitions.
- `commons/`: shared utilities (logging utilities, metrics, sampling, JAX helpers).
- `modules/`: training and evaluation logic (agent, evaluator, match generator, optimizers, run loop).
- `loggers/`: episode and evaluation loggers.
- `unplugged/`: offline‐only pipeline (data ingestion, dataset generation, losses, learner module, training/evaluation scripts).

##### Inspect README for insights
- Emphasizes two main offerings: the flexible architectures and the offline “Unplugged” pipeline with Behavior Cloning.
- Describes use of PySC2 for StarCraft II environment, built via pip wheels or Bazel.
- Shows intended workflow: prepare data → run training → run evaluation.

## Diagram (Mermaid)

```mermaid
flowchart TB
  subgraph "External Environment"
    SC2["StarCraft II"]:::external
    PySC2["PySC2 Env"]:::external
  end

  subgraph "Data Layer"
    DG["Dataset Generator"]:::data
    DP["Partition Generator"]:::data
    GR["Replay Fetcher"]:::data
    DS["Data Source Abstractions"]:::data
    Store(("Dataset Store")):::data
  end

  DG -.-> Store
  DP -.-> Store
  GR -.-> Store
  DS --> Store

  subgraph "Model Layer"
    ArchFactory["Model Factory"]:::model
    ArchCore["Neural Network Architectures"]:::model
    StdArch["Standard Architectures"]:::model
    CompArch["Reusable Components"]:::model
    DummyArch["Dummy Architecture"]:::model
  end

  ArchFactory --> ArchCore
  ArchCore --> StdArch
  ArchCore --> CompArch
  ArchCore --> DummyArch

  subgraph "Training Pipeline"
    TrainScript["Training Script"]:::train
    RunLoop["Run Loop"]:::train
    Agent["Agent Logic"]:::train
    MG["Match Generator"]:::train
    Learner["Learner Module"]:::train
    Loss["Loss Computations"]:::train
    Optimizer["Optimizer"]:::train
    Commons["Shared Utilities"]:::util
    Collections["Data Structures & Types"]:::util
  end

  TrainScript --> RunLoop
  RunLoop --> Store
  RunLoop --> Agent
  RunLoop --> MG
  Agent --> ArchFactory
  Agent --> Commons
  Agent --> Collections
  RunLoop --> Learner
  Learner --> Loss
  Loss --> Optimizer
  Optimizer --> RunLoop
  RunLoop --> Commons

  subgraph "Evaluation Pipeline"
    EvalScript["Evaluation Script"]:::eval
    Evaluator["Evaluator Core"]:::eval
    EvalLogger["Eval Logger"]:::eval
  end

  EvalScript --> Evaluator
  Evaluator --> Store
  Evaluator --> Agent
  Evaluator --> Commons
  Evaluator --> Collections
  Evaluator --> EvalLogger

  subgraph "Logging & Metrics"
    EpisodeLogger["Episode Logger"]:::eval
    Metrics["Metrics Utilities"]:::util
  end

  RunLoop --> EpisodeLogger
  RunLoop --> Metrics

  subgraph "Build & Packaging"
    Bazel["Bazel Config"]:::build
    Setup["setup.py"]:::build
    Req["requirements.txt"]:::build
    Workspace["WORKSPACE"]:::build
  end

  click DG "https://github.com/google-deepmind/alphastar/blob/main/alphastar/unplugged/data/generate_dataset.py"
  click DP "https://github.com/google-deepmind/alphastar/blob/main/alphastar/unplugged/data/generate_partitions.py"
  click GR "https://github.com/google-deepmind/alphastar/blob/main/alphastar/unplugged/data/get_replays.sh"
  click DS "https://github.com/google-deepmind/alphastar/blob/main/alphastar/unplugged/data/data_source.py"
  click Store "https://github.com/google-deepmind/alphastar/tree/main/alphastar/unplugged/data"
  click Loss "https://github.com/google-deepmind/alphastar/tree/main/alphastar/unplugged/losses"
  click Learner "https://github.com/google-deepmind/alphastar/blob/main/alphastar/unplugged/modules/learner.py"
  click TrainScript "https://github.com/google-deepmind/alphastar/blob/main/alphastar/unplugged/scripts/train.py"
  click EvalScript "https://github.com/google-deepmind/alphastar/blob/main/alphastar/unplugged/scripts/evaluate.py"
  click RunLoop "https://github.com/google-deepmind/alphastar/blob/main/alphastar/modules/run_loop.py"
  click Agent "https://github.com/google-deepmind/alphastar/blob/main/alphastar/modules/agent.py"
  click MG "https://github.com/google-deepmind/alphastar/blob/main/alphastar/modules/match_generator.py"
  click Optimizer "https://github.com/google-deepmind/alphastar/blob/main/alphastar/modules/optimizers.py"
  click Evaluator "https://github.com/google-deepmind/alphastar/blob/main/alphastar/modules/evaluator.py"
  click StdArch "https://github.com/google-deepmind/alphastar/tree/main/alphastar/architectures/standard"
  click ArchCore "https://github.com/google-deepmind/alphastar/tree/main/alphastar/architectures"
  click CompArch "https://github.com/google-deepmind/alphastar/tree/main/alphastar/architectures/components"
  click DummyArch "https://github.com/google-deepmind/alphastar/blob/main/alphastar/architectures/dummy/dummy.py"
  click Commons "https://github.com/google-deepmind/alphastar/tree/main/alphastar/commons"
  click Collections "https://github.com/google-deepmind/alphastar/tree/main/alphastar/collections"
  click Setup "https://github.com/google-deepmind/alphastar/blob/main/setup.py"
  click Bazel "https://github.com/google-deepmind/alphastar/tree/main/bazel/"
  click Req "https://github.com/google-deepmind/alphastar/blob/main/requirements.txt"
  click Workspace "https://github.com/google-deepmind/alphastar/tree/main/WORKSPACE"

  classDef data fill:#AED6F1,stroke:#21618C,color:#1B2631
  classDef model fill:#A9DFBF,stroke:#196F3D,color:#145A32
  classDef train fill:#F5B041,stroke:#B9770E,color:#873600
  classDef eval fill:#D2B4DE,stroke:#6C3483,color:#4A235A
  classDef util fill:#F9E79F,stroke:#B7950B,color:#7D6608
  classDef build fill:#D5D8DC,stroke:#424949,color:#1C2833
  classDef external fill:#EBDEF0,stroke:#816D8E,color:#4A235A
```
