# st01tyy/lightscale architecture

> Architecture diagram of the GitHub repository st01tyy/lightscale, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/st01tyy/lightscale
- Repository: https://github.com/st01tyy/lightscale

## Overview

LiteScale is a Megatron-native post-training framework for GKD, GRPO, and SFT, with replaceable inference services and an asynchronous rollout stack. Its principal online-RL workflow samples prompts, generates responses, evaluates rewards, and trains the actor; GKD and SFT are distinct training paths. The graph preserves major README capabilities and selected Megatron runtime layers. Relationships among LiteScale components follow README statements; unsampled implementation details are not inferred as confirmed calls.

Main entry points: [`megatron/training/training.py`](https://github.com/st01tyy/lightscale/blob/main/megatron/training/training.py) (Megatron training), [`light_scale/async_rollout_v2/rollout_loop.py`](https://github.com/st01tyy/lightscale/blob/main/light_scale/async_rollout_v2/rollout_loop.py) (Rollout loop), [`light_scale/config.py`](https://github.com/st01tyy/lightscale/blob/main/light_scale/config.py) (Unified config), [`light_scale/async_grpo_trainer.py`](https://github.com/st01tyy/lightscale/blob/main/light_scale/async_grpo_trainer.py) (Async GRPO)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and config"]
  node_config["Unified config<br/>[config.py]"]
  node_async_entry["Async actor entry"]
  node_sft_entry["SFT entry<br/>[main_sft.py]"]
  node_gkd_entry["GKD entry<br/>[headquarters_v2.py]"]
end

subgraph group_rollout["Async rollout"]
  node_rollout_loop["Rollout loop<br/>[rollout_loop.py]"]
  node_rollout_thread["Rollout thread<br/>[rollout_thread.py]"]
  node_services["Inference services<br/>[base_service.py]"]
  node_workers["Rollout workers<br/>[base_worker.py]"]
  node_judge["LLM judging<br/>[llm_judge.py]"]
  node_sample_data["Rollout samples<br/>[data.py]"]
end

subgraph group_training["Post-training"]
  node_grpo["GRPO trainer<br/>[grpo_trainer.py]"]
  node_async_grpo["Async GRPO"]
  node_sft["SFT trainer<br/>[sft_trainer.py]"]
  node_gkd["GKD objectives<br/>[gkd_utils.py]"]
  node_logits["Logit exchange<br/>[logits_express.py]"]
end

subgraph group_megatron["Megatron runtime"]
  node_training_runtime["Megatron training<br/>[training.py]"]
  node_transformer["Transformer layers"]
  node_parallel["Parallel execution<br/>[parallel_state.py]"]
  node_inference["Inference engine<br/>[dynamic_engine.py]"]
  node_inference_types["Request and sampling"]
end

subgraph group_storage["Checkpointing"]
  node_checkpoint[("Distributed checkpointing<br/>[torch.py]")]
end

node_user(("Research engineer"))

node_user -->|"configures"| node_config
node_config -->|"selects entry"| node_async_entry
node_config -->|"selects entry"| node_sft_entry
node_config -->|"selects entry"| node_gkd_entry
node_async_entry -.->|"runs training"| node_async_grpo
node_async_grpo -->|"coordinates rollouts"| node_rollout_loop
node_rollout_loop -->|"uses services"| node_services
node_rollout_loop -->|"dispatches workers"| node_workers
node_rollout_thread -.->|"runs loop"| node_rollout_loop
node_workers -.->|"requests judgments"| node_judge
node_workers -->|"processes samples"| node_sample_data
node_rollout_loop -.->|"produces samples"| node_sample_data
node_async_grpo -.->|"uses GRPO"| node_grpo
node_async_grpo -->|"accumulates gradients"| node_training_runtime
node_sft_entry -.->|"runs SFT"| node_sft
node_gkd_entry -->|"computes objectives"| node_gkd
node_gkd -->|"uses logit exchange"| node_logits
node_gkd_entry -->|"trains distributed"| node_training_runtime
node_grpo -.->|"trains actor"| node_training_runtime
node_sft -.->|"trains model"| node_training_runtime
node_training_runtime -.->|"executes layers"| node_transformer
node_transformer -->|"uses parallel groups"| node_parallel
node_inference -->|"handles requests"| node_inference_types
node_training_runtime -.->|"saves state"| node_checkpoint

click node_config "https://github.com/st01tyy/lightscale/blob/main/light_scale/config.py"
click node_async_entry "https://github.com/st01tyy/lightscale/blob/main/main_async_actor.py"
click node_sft_entry "https://github.com/st01tyy/lightscale/blob/main/main_sft.py"
click node_gkd_entry "https://github.com/st01tyy/lightscale/blob/main/headquarters_v2.py"
click node_rollout_loop "https://github.com/st01tyy/lightscale/blob/main/light_scale/async_rollout_v2/rollout_loop.py"
click node_rollout_thread "https://github.com/st01tyy/lightscale/blob/main/light_scale/async_rollout_v2/rollout_thread.py"
click node_services "https://github.com/st01tyy/lightscale/blob/main/light_scale/async_rollout_v2/services/base_service.py"
click node_workers "https://github.com/st01tyy/lightscale/blob/main/light_scale/async_rollout_v2/workers/base_worker.py"
click node_judge "https://github.com/st01tyy/lightscale/blob/main/light_scale/async_rollout_v2/utils/llm_judge.py"
click node_sample_data "https://github.com/st01tyy/lightscale/blob/main/light_scale/data.py"
click node_grpo "https://github.com/st01tyy/lightscale/blob/main/light_scale/grpo_trainer.py"
click node_async_grpo "https://github.com/st01tyy/lightscale/blob/main/light_scale/async_grpo_trainer.py"
click node_sft "https://github.com/st01tyy/lightscale/blob/main/light_scale/sft_trainer.py"
click node_gkd "https://github.com/st01tyy/lightscale/blob/main/light_scale/gkd_utils.py"
click node_logits "https://github.com/st01tyy/lightscale/blob/main/light_scale/logits_express.py"
click node_training_runtime "https://github.com/st01tyy/lightscale/blob/main/megatron/training/training.py"
click node_transformer "https://github.com/st01tyy/lightscale/blob/main/megatron/core/extensions/transformer_engine.py"
click node_parallel "https://github.com/st01tyy/lightscale/blob/main/megatron/core/parallel_state.py"
click node_inference "https://github.com/st01tyy/lightscale/blob/main/megatron/core/inference/engines/dynamic_engine.py"
click node_inference_types "https://github.com/st01tyy/lightscale/blob/main/megatron/core/inference/inference_request.py"
click node_checkpoint "https://github.com/st01tyy/lightscale/blob/main/megatron/core/dist_checkpointing/strategies/torch.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_config,node_async_entry,node_sft_entry,node_gkd_entry toneBlue
class node_rollout_loop,node_rollout_thread,node_services,node_workers,node_judge,node_sample_data toneAmber
class node_grpo,node_async_grpo,node_sft,node_gkd,node_logits toneMint
class node_training_runtime,node_transformer,node_parallel,node_inference,node_inference_types toneRose
class node_checkpoint,node_user toneIndigo
```

## Components

### Entry and config

- [Unified config](https://github.com/st01tyy/lightscale/blob/main/light_scale/config.py): `light_scale/config.py`
- [Async actor entry](https://github.com/st01tyy/lightscale/blob/main/main_async_actor.py): `main_async_actor.py`
- [SFT entry](https://github.com/st01tyy/lightscale/blob/main/main_sft.py): `main_sft.py`
- [GKD entry](https://github.com/st01tyy/lightscale/blob/main/headquarters_v2.py): `headquarters_v2.py`

### Async rollout

- [Rollout loop](https://github.com/st01tyy/lightscale/blob/main/light_scale/async_rollout_v2/rollout_loop.py): `light_scale/async_rollout_v2/rollout_loop.py`
- [Rollout thread](https://github.com/st01tyy/lightscale/blob/main/light_scale/async_rollout_v2/rollout_thread.py): `light_scale/async_rollout_v2/rollout_thread.py`
- [Inference services](https://github.com/st01tyy/lightscale/blob/main/light_scale/async_rollout_v2/services/base_service.py): `light_scale/async_rollout_v2/services/base_service.py`
- [Rollout workers](https://github.com/st01tyy/lightscale/blob/main/light_scale/async_rollout_v2/workers/base_worker.py): `light_scale/async_rollout_v2/workers/base_worker.py`
- [LLM judging](https://github.com/st01tyy/lightscale/blob/main/light_scale/async_rollout_v2/utils/llm_judge.py): `light_scale/async_rollout_v2/utils/llm_judge.py`
- [Rollout samples](https://github.com/st01tyy/lightscale/blob/main/light_scale/data.py): `light_scale/data.py`

### Post-training

- [GRPO trainer](https://github.com/st01tyy/lightscale/blob/main/light_scale/grpo_trainer.py): `light_scale/grpo_trainer.py`
- [Async GRPO](https://github.com/st01tyy/lightscale/blob/main/light_scale/async_grpo_trainer.py): `light_scale/async_grpo_trainer.py`
- [SFT trainer](https://github.com/st01tyy/lightscale/blob/main/light_scale/sft_trainer.py): `light_scale/sft_trainer.py`
- [GKD objectives](https://github.com/st01tyy/lightscale/blob/main/light_scale/gkd_utils.py): `light_scale/gkd_utils.py`
- [Logit exchange](https://github.com/st01tyy/lightscale/blob/main/light_scale/logits_express.py): `light_scale/logits_express.py`

### Megatron runtime

- [Megatron training](https://github.com/st01tyy/lightscale/blob/main/megatron/training/training.py): `megatron/training/training.py`
- [Transformer layers](https://github.com/st01tyy/lightscale/blob/main/megatron/core/extensions/transformer_engine.py): `megatron/core/extensions/transformer_engine.py`
- [Parallel execution](https://github.com/st01tyy/lightscale/blob/main/megatron/core/parallel_state.py): `megatron/core/parallel_state.py`
- [Inference engine](https://github.com/st01tyy/lightscale/blob/main/megatron/core/inference/engines/dynamic_engine.py): `megatron/core/inference/engines/dynamic_engine.py`
- [Request and sampling](https://github.com/st01tyy/lightscale/blob/main/megatron/core/inference/inference_request.py): `megatron/core/inference/inference_request.py`

### Checkpointing

- [Distributed checkpointing](https://github.com/st01tyy/lightscale/blob/main/megatron/core/dist_checkpointing/strategies/torch.py): `megatron/core/dist_checkpointing/strategies/torch.py`

### Other components

- **Research engineer**

## Connections

- Research engineer → Unified config: configures
- Unified config → Async actor entry: selects entry
- Unified config → SFT entry: selects entry
- Unified config → GKD entry: selects entry
- Async actor entry → Async GRPO: runs training
- Async GRPO → Rollout loop: coordinates rollouts
- Rollout loop → Inference services: uses services
- Rollout loop → Rollout workers: dispatches workers
- Rollout thread → Rollout loop: runs loop
- Rollout workers → LLM judging: requests judgments
- Rollout workers → Rollout samples: processes samples (evidence: `light_scale/async_rollout_v2/workers/llm_judge_worker.py`)
- Rollout loop → Rollout samples: produces samples
- Async GRPO → GRPO trainer: uses GRPO
- Async GRPO → Megatron training: accumulates gradients
- SFT entry → SFT trainer: runs SFT
- GKD entry → GKD objectives: computes objectives
- GKD objectives → Logit exchange: uses logit exchange
- GKD entry → Megatron training: trains distributed
- GRPO trainer → Megatron training: trains actor
- SFT trainer → Megatron training: trains model
- Megatron training → Transformer layers: executes layers
- Transformer layers → Parallel execution: uses parallel groups (evidence: `megatron/core/extensions/transformer_engine.py`)
- Inference engine → Request and sampling: handles requests (evidence: `megatron/core/inference/engines/dynamic_engine.py`)
- Megatron training → Distributed checkpointing: saves state
