# facebookresearch/truthrl architecture

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

- Interactive diagram: https://gitdiagram.com/facebookresearch/truthrl
- Repository: https://github.com/facebookresearch/truthrl

## Overview

TruthRL is a research codebase for training and evaluating LLMs to answer accurately while abstaining rather than hallucinating. Its principal workflow is to train with reinforcement-learning rewards that distinguish correct answers, hallucinations, and abstentions, then evaluate model responses with an LLM verifier. The tree also contains question-retrieval utilities and the broader verl and open-r1 training frameworks. Evidence is limited to the README, the source index, and the supplied excerpts; uncertain links are omitted or marked unverified.

Main entry points: [`training/verl/verl/workers/fsdp_workers.py`](https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/workers/fsdp_workers.py) (FSDP Workers), [`training/verl/verl/trainer/ppo/ray_trainer.py`](https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/trainer/ppo/ray_trainer.py) (PPO Trainer), [`evaluation/evaluate.py`](https://github.com/facebookresearch/truthrl/blob/main/evaluation/evaluate.py) (Evaluation Runner), [`training/open-r1/src/open_r1/rewards.py`](https://github.com/facebookresearch/truthrl/blob/main/training/open-r1/src/open_r1/rewards.py) (Reward Functions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_data["Question Data"]
  node_questions["Question Retrieval<br/>[retrieval.py]"]
  node_ook["OOK Questions"]
end

subgraph group_training["RL Training"]
  node_openr1_rewards["Reward Functions<br/>[rewards.py]"]
  node_code_providers["Code Providers<br/>[code_providers.py]"]
end

subgraph group_runtime["Training Runtime"]
  node_verl_entry["PPO Entry<br/>[main_ppo.py]"]
  node_ppo_trainer["PPO Trainer<br/>[ray_trainer.py]"]
  node_fsdp_workers["FSDP Workers<br/>[fsdp_workers.py]"]
  node_fsdp_engine["FSDP Engine<br/>[engine_impl.py]"]
  node_data_proto["Batch Protocol<br/>[protocol.py]"]
  node_dispatch["Distributed Dispatch<br/>[decorator.py]"]
  node_checkpoint["FSDP Checkpoints"]
  node_device["Device Selection<br/>[device.py]"]
end

subgraph group_evaluation["Evaluation"]
  node_eval_entry["Evaluation Runner<br/>[evaluate.py]"]
  node_eval_model["Model Inference<br/>[model.py]"]
  node_eval_prompts["Evaluation Prompts<br/>[prompts.py]"]
end

node_researcher(("Researcher"))
node_verifier{{"LLM Verifier"}}
node_trained_model["Trained Model"]

node_researcher -.->|"finds questions"| node_questions
node_researcher -.->|"starts training"| node_verl_entry
node_verl_entry -.->|"runs trainer"| node_ppo_trainer
node_ppo_trainer -.->|"dispatches work"| node_fsdp_workers
node_fsdp_workers -.->|"uses engine"| node_fsdp_engine
node_fsdp_workers -->|"saves state"| node_checkpoint
node_fsdp_workers -->|"selects device"| node_device
node_fsdp_engine -->|"selects device"| node_device
node_fsdp_workers -.->|"processes batches"| node_data_proto
node_dispatch -->|"distributes batches"| node_data_proto
node_openr1_rewards -->|"uses providers"| node_code_providers
node_ppo_trainer -.->|"computes rewards"| node_openr1_rewards
node_ppo_trainer -.->|"requests judgments"| node_verifier
node_researcher -->|"starts evaluation"| node_eval_entry
node_eval_entry -->|"runs inference"| node_eval_model
node_eval_entry -->|"uses prompts"| node_eval_prompts
node_eval_model -.->|"requests judgments"| node_verifier
node_eval_entry -->|"evaluates model"| node_trained_model

click node_questions "https://github.com/facebookresearch/truthrl/blob/main/data_utils/retrieval.py"
click node_ook "https://github.com/facebookresearch/truthrl/blob/main/data_utils/find_OOK_questions.py"
click node_openr1_rewards "https://github.com/facebookresearch/truthrl/blob/main/training/open-r1/src/open_r1/rewards.py"
click node_code_providers "https://github.com/facebookresearch/truthrl/blob/main/training/open-r1/src/open_r1/utils/code_providers.py"
click node_verl_entry "https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/trainer/main_ppo.py"
click node_ppo_trainer "https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/trainer/ppo/ray_trainer.py"
click node_fsdp_workers "https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/workers/fsdp_workers.py"
click node_fsdp_engine "https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/workers/engine/fsdp/engine_impl.py"
click node_data_proto "https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/protocol.py"
click node_dispatch "https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/single_controller/base/decorator.py"
click node_checkpoint "https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/utils/checkpoint/fsdp_checkpoint_manager.py"
click node_device "https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/utils/device.py"
click node_eval_entry "https://github.com/facebookresearch/truthrl/blob/main/evaluation/evaluate.py"
click node_eval_model "https://github.com/facebookresearch/truthrl/blob/main/evaluation/model.py"
click node_eval_prompts "https://github.com/facebookresearch/truthrl/blob/main/evaluation/prompts.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_questions,node_ook toneBlue
class node_openr1_rewards,node_code_providers toneAmber
class node_verl_entry,node_ppo_trainer,node_fsdp_workers,node_fsdp_engine,node_data_proto,node_dispatch,node_checkpoint,node_device toneMint
class node_eval_entry,node_eval_model,node_eval_prompts toneRose
class node_researcher,node_verifier,node_trained_model toneIndigo
```

## Components

### Question Data

- [Question Retrieval](https://github.com/facebookresearch/truthrl/blob/main/data_utils/retrieval.py): `data_utils/retrieval.py`
- [OOK Questions](https://github.com/facebookresearch/truthrl/blob/main/data_utils/find_OOK_questions.py): `data_utils/find_OOK_questions.py`

### RL Training

- [Reward Functions](https://github.com/facebookresearch/truthrl/blob/main/training/open-r1/src/open_r1/rewards.py): `training/open-r1/src/open_r1/rewards.py`
- [Code Providers](https://github.com/facebookresearch/truthrl/blob/main/training/open-r1/src/open_r1/utils/code_providers.py): `training/open-r1/src/open_r1/utils/code_providers.py`

### Training Runtime

- [PPO Entry](https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/trainer/main_ppo.py): `training/verl/verl/trainer/main_ppo.py`
- [PPO Trainer](https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/trainer/ppo/ray_trainer.py): `training/verl/verl/trainer/ppo/ray_trainer.py`
- [FSDP Workers](https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/workers/fsdp_workers.py): `training/verl/verl/workers/fsdp_workers.py`
- [FSDP Engine](https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/workers/engine/fsdp/engine_impl.py): `training/verl/verl/workers/engine/fsdp/engine_impl.py`
- [Batch Protocol](https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/protocol.py): `training/verl/verl/protocol.py`
- [Distributed Dispatch](https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/single_controller/base/decorator.py): `training/verl/verl/single_controller/base/decorator.py`
- [FSDP Checkpoints](https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/utils/checkpoint/fsdp_checkpoint_manager.py): `training/verl/verl/utils/checkpoint/fsdp_checkpoint_manager.py`
- [Device Selection](https://github.com/facebookresearch/truthrl/blob/main/training/verl/verl/utils/device.py): `training/verl/verl/utils/device.py`

### Evaluation

- [Evaluation Runner](https://github.com/facebookresearch/truthrl/blob/main/evaluation/evaluate.py): `evaluation/evaluate.py`
- [Model Inference](https://github.com/facebookresearch/truthrl/blob/main/evaluation/model.py): `evaluation/model.py`
- [Evaluation Prompts](https://github.com/facebookresearch/truthrl/blob/main/evaluation/prompts.py): `evaluation/prompts.py`

### Other components

- **Researcher**
- **LLM Verifier**
- **Trained Model**

## Connections

- Researcher → Question Retrieval: finds questions
- Researcher → PPO Entry: starts training
- PPO Entry → PPO Trainer: runs trainer
- PPO Trainer → FSDP Workers: dispatches work
- FSDP Workers → FSDP Engine: uses engine
- FSDP Workers → FSDP Checkpoints: saves state (evidence: `training/verl/verl/workers/fsdp_workers.py`)
- FSDP Workers → Device Selection: selects device (evidence: `training/verl/verl/workers/fsdp_workers.py`)
- FSDP Engine → Device Selection: selects device (evidence: `training/verl/verl/workers/engine/fsdp/engine_impl.py`)
- FSDP Workers → Batch Protocol: processes batches
- Distributed Dispatch → Batch Protocol: distributes batches (evidence: `training/verl/verl/single_controller/base/decorator.py`)
- Reward Functions → Code Providers: uses providers (evidence: `training/open-r1/src/open_r1/rewards.py`)
- PPO Trainer → Reward Functions: computes rewards
- PPO Trainer → LLM Verifier: requests judgments
- Researcher → Evaluation Runner: starts evaluation
- Evaluation Runner → Model Inference: runs inference (evidence: `evaluation/evaluate.py`)
- Evaluation Runner → Evaluation Prompts: uses prompts (evidence: `evaluation/evaluate.py`)
- Model Inference → LLM Verifier: requests judgments
- Evaluation Runner → Trained Model: evaluates model
