# willccbb/verifiers architecture

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

- Interactive diagram: https://gitdiagram.com/willccbb/verifiers
- Repository: https://github.com/willccbb/verifiers

## Overview

##### Project type and purpose
- This is an open-source Python library/toolkit (“verifiers”) for training and evaluating large language models with reinforcement learning in verifiable environments.
- It provides abstractions for Environments, Parsers, Rubrics, Trainers (GRPOTrainer), and Inference clients (vLLM/OpenAI API) to build custom multi-turn RL tasks.

##### High-level architecture layers
A. User layer
- Training or evaluation scripts (e.g. examples/, train.py)
- CLI entry points (vf-vllm server, accelerate launch)
B. Core library (verifiers package)
1. Environments (verifiers/envs)
– Abstract classes: Environment, MultiTurnEnv, SingleTurnEnv, ToolEnv, etc.
– Concrete envs: CodeMathEnv, SmolaToolEnv, ReasoningGymEnv, etc.
2. Parsers (verifiers/parsers)
– Standardize prompt formats and extract fields (XMLParser, ThinkParser, etc.)
3. Rubrics (verifiers/rubrics)
– Define reward functions and grouping logic
4. Tools (verifiers/tools)
– Python helper functions for tool-augmented rollouts (calculator, search, ask)
5. Inference (verifiers/inference)
– vLLM client & server code for async model serving
6. Trainers (verifiers/trainers)
– GRPOTrainer on top of transformers.Trainer + accelerate
7. Utilities & types
– Data utilities, logging, model utils, shared type definitions
C. External dependencies
- Transformers + accelerate
- vLLM server (custom microservice)
- OpenAI-compatible API endpoints
- Hugging Face datasets & model hub
- Optional: reasoning-gym, smolagents

##### Components and interactions
- User script invokes vf-vllm to launch inference server and then uses accelerate to start GRPO training.
- GRPOTrainer orchestrates the main loop:
1. Sample prompts from a Dataset
2. Call Environment.rollout(), which:
a. Sends messages to the Inference client (vLLM server or OpenAI API)
b. Receives responses, parses them via Parser
c. Invokes Tools as needed for tool-use environments
d. Applies Rubric(s) to compute rewards
3. Collects rollouts (prompt, completions, rewards)
4. Feeds data to transformers.Trainer for gradient updates (off-policy, async overlap)
- GRPOTrainer handles state syncing of reference models, gradient accumulation, and periodic exp to WandB/HF.

##### Key architectural patterns and design principles
- Modular abstractions (Environment, Parser, Rubric) promote reuse and custom extensions
- Separation of concerns: rollouts decoupled from training logic
- Async overlap of inference ←→ training
- Plugin-style integration with external model servers and APIs
- Configurable via YAML (configs/zero3.yaml) and modular entrypoints

##### Detailed component list
- User Scripts & CLI (examples/, train.py, vf-vllm CLI)
- verifiers.envs (Environment abstractions + concrete envs)
- verifiers.parsers (Parser classes)
- verifiers.rubrics (Rubric classes)
- verifiers.tools (Tool functions)
- verifiers.inference (vllm_client, vllm_server)
- verifiers.trainers (GRPOTrainer, async loaders)
- transformers.Trainer + accelerate backend
- External: vLLM Server, OpenAI API, HF datasets, WandB/HF Hub

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Layer
    subgraph "User Layer"
        US["User Scripts & CLI"] 
        US -->|"launch vLLM server"| vLLMService
        US -->|"launch training"| GRPOProcess
        CFG["Config YAML"] 
        CFG -->|"configures"| GRPOProcess
        click US "https://github.com/willccbb/verifiers/tree/main/verifiers/examples/"
        click CFG "https://github.com/willccbb/verifiers/blob/main/configs/zero3.yaml"
    end

    %% Processes
    vLLMService["vLLM Inference Service"]:::external
    GRPOProcess["GRPOTrainer Process"]:::trainer

    %% Core Library
    subgraph "Core Library (verifiers)"
        direction TB
        EnvPkg["verifiers/envs"]:::env
        ParsersPkg["verifiers/parsers"]:::parser
        RubricsPkg["verifiers/rubrics"]:::rubric
        ToolsPkg["verifiers/tools"]:::tools
        InferencePkg["verifiers/inference"]:::inference
        TrainersPkg["verifiers/trainers"]:::trainer
        UtilsPkg["verifiers/utils & types"]:::utils

        click EnvPkg "https://github.com/willccbb/verifiers/tree/main/verifiers/envs/"
        click ParsersPkg "https://github.com/willccbb/verifiers/tree/main/verifiers/parsers/"
        click RubricsPkg "https://github.com/willccbb/verifiers/tree/main/verifiers/rubrics/"
        click ToolsPkg "https://github.com/willccbb/verifiers/tree/main/verifiers/tools/"
        click InferencePkg "https://github.com/willccbb/verifiers/tree/main/verifiers/inference/"
        click TrainersPkg "https://github.com/willccbb/verifiers/tree/main/verifiers/trainers/"
        click UtilsPkg "https://github.com/willccbb/verifiers/blob/main/verifiers/utils/data_utils.py"
    end

    %% External Dependencies
    subgraph "External Dependencies"
        direction TB
        TA["Transformers + accelerate"]:::external
        OpenAI["OpenAI API"]:::external
        HFDatasets["HF Datasets & Hub"]:::external
        LoggingHub["WandB / HF Hub"]:::external
    end

    %% Data Stores
    ModelStore[(Model Weights)]:::external
    RefModelStore[(Reference Model)]:::external

    %% Flows
    GRPOProcess -->|"uses trainer module"| TrainersPkg
    TrainersPkg -->|"calls rollout()"| EnvPkg
    EnvPkg -->|"calls inference client"| InferencePkg
    InferencePkg -->|"messages"| vLLMService
    InferencePkg -->|"messages"| OpenAI
    vLLMService -->|"responses"| InferencePkg
    OpenAI -->|"responses"| InferencePkg
    InferencePkg -->|"responses"| EnvPkg
    EnvPkg -->|"parses output"| ParsersPkg
    EnvPkg -->|"invokes tools"| ToolsPkg
    EnvPkg -->|"computes reward"| RubricsPkg
    RubricsPkg -->|"rewards"| GRPOProcess
    GRPOProcess -->|"gradient update"| TA
    GRPOProcess -->|"sync reference"| RefModelStore
    GRPOProcess -->|"loads/saves data"| HFDatasets
    GRPOProcess -->|"logs metrics"| LoggingHub

    %% Styles
    classDef env fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef parser fill:#ffffcc,stroke:#333,stroke-width:1px
    classDef rubric fill:#ffdd99,stroke:#333,stroke-width:1px
    classDef tools fill:#ccffff,stroke:#333,stroke-width:1px
    classDef inference fill:#e0ccff,stroke:#333,stroke-width:1px
    classDef trainer fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef utils fill:#eeeeee,stroke:#333,stroke-width:1px
    classDef external fill:#f2f2f2,stroke:#333,stroke-width:1px
```
