# pablo389/deepbork architecture

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

- Interactive diagram: https://gitdiagram.com/pablo389/deepbork
- Repository: https://github.com/pablo389/deepbork

## Overview

1. **What this repo is**
   - `deepbork` is a TritonBench-T generation and evaluation pipeline, centered on generating Triton Python candidates, sending them through the TritonBench-T harness, and optionally repairing failures in a local loop.
   - The architectural boundary is between **local orchestration** and **remote benchmark execution** on Modal.

2. **Primary data contract**
   - `predictions.jsonl` is the key interchange format.
   - Each record contains an `instruction` and a generated `predict` string.
   - Generation produces this file; evaluation consumes it; the agentic loop regenerates it per attempt.

3. **Prompt and benchmark inputs**
   - The repo reads TritonBench-T Alpaca prompt files from `data/`:
     - `TritonBench_T_simp_alpac_v1.json`
     - `TritonBench_T_comp_alpac_v1.json`
   - `TritonBench_T_v1.jsonl` is the metadata index used to map prompt instructions back to benchmark operator files and tests.
   - The benchmark’s golden reference files are not owned here; they are pulled from the upstream TritonBench repo during remote evaluation.

4. **Batch generation subsystem**
   - `main.py` is the generator entrypoint.
   - It builds prompt messages, calls an LLM endpoint via the OpenAI-compatible client, cleans generated code fences, and writes `outputs/predictions.jsonl` by default.
   - It supports multiple providers, including a local/remote Modal vLLM endpoint and the public OpenAI API.

5. **Batch evaluation wrapper**
   - `evaluate.py` is a thin local CLI/Python launcher for Modal-based evaluation.
   - Its job is orchestration only: select a mode (`phase1`, `phase2`, `phase3`, or `all`), pass the local JSONL or a Modal Volume path, and invoke the remote app.
   - It preserves the separation between local artifact preparation and remote benchmark execution.

6. **Remote execution on Modal**
   - `modal_eval_app.py` is the execution boundary for TritonBench-T.
   - It defines the Modal image, GPU runtime, and Modal Volume storage used for evaluation artifacts.
   - The remote app clones/patches the TritonBench harness inside the container, runs Phase 1/2/3, and stores outputs under phase-specific directories in the Modal Volume.

7. **Phase-based evaluation pipeline**
   - The benchmark is intentionally split into independent stages:
     - Phase 1: call accuracy
     - Phase 2: additional semantic / execution filtering
     - Phase 3: performance-oriented benchmarking
   - The phases can run together or independently, which is important for both batch workflows and repair loops.

8. **Metadata matching helper**
   - `tritonbench_helpers.py` provides the crosswalk between prompt rows, benchmark metadata, and operator filenames.
   - This is the glue that lets the evaluator recover the correct TritonBench test target from an `instruction` in `predictions.jsonl`.
   - It is packaged into the Modal container so local and remote matching logic stays consistent.

9. **Agentic repair subsystem**
   - `agentic_eval.py` implements a one-operator generate/evaluate/repair loop.
   - It selects a single benchmark op, generates a candidate, writes per-attempt artifacts, runs evaluation up to a target stage, and if needed asks the model to repair using failures from stdout/stderr.
   - The loop always re-enters evaluation from Phase 1 after a repair, because the source code may have changed and earlier results are no longer valid.

10. **Curated repair knowledge**
    - `repair_rules/` contains JSON rule sets for Phase 1, Phase 2, and Phase 3 failures.
    - These are data-driven prompts, not code: the agentic loop injects only the rules relevant to the stage that failed.
    - This creates a feedback boundary between deterministic failure signals and LLM-driven repair.

11. **Artifact layout and persistence**
    - Local generation/evaluation artifacts live under `outputs/`.
    - Agentic attempts are separated by op and attempt number, with per-attempt predictions, generated code, summaries, and repair prompts.
    - Remote Modal artifacts are also staged by phase and attempt, making the system traceable across local and cloud execution.

12. **Key end-to-end flows**
    - **Batch flow:** `main.py` → `outputs/predictions.jsonl` → `evaluate.py` → `modal_eval_app.py` → Modal Volume results.
    - **Agentic flow:** `agentic_eval.py` → generate one candidate → remote evaluation → accept or repair → repeat until the target stage passes or attempts are exhausted.
    - The repo’s architecture is built around keeping these flows composable while sharing the same prompt, metadata, and benchmark contracts.

Main entry points: [`agentic_eval.py`](https://github.com/pablo389/deepbork/blob/main/agentic_eval.py) (Agentic loop), [`modal_eval_app.py`](https://github.com/pablo389/deepbork/blob/main/modal_eval_app.py) (Modal runner), [`evaluate.py`](https://github.com/pablo389/deepbork/blob/main/evaluate.py) (Eval launcher), [`main.py`](https://github.com/pablo389/deepbork/blob/main/main.py) (Generator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_local["Local orchestration"]
  node_main_py["Generator<br/>CLI entrypoint<br/>[main.py]"]
  node_evaluate_py["Eval launcher<br/>CLI wrapper<br/>[evaluate.py]"]
  node_agentic_eval_py["Agentic loop<br/>repair loop<br/>[agentic_eval.py]"]
  node_tritonbench_helpers_py["Metadata crosswalk<br/>mapping helper"]
end

subgraph group_remote["Remote benchmark"]
  node_modal_eval_app_py["Modal runner<br/>remote executor<br/>[modal_eval_app.py]"]
  node_modal_volume[("Modal volume<br/>artifact store")]
  node_phase1(("Phase 1<br/>call accuracy"))
  node_phase2(("Phase 2<br/>semantic filter"))
  node_phase3(("Phase 3<br/>performance bench"))
end

subgraph group_data["Benchmark data"]
  node_predictions_jsonl["Predictions<br/>interchange file"]
  node_simp_prompts["Simple prompts<br/>prompt data"]
  node_comp_prompts["Complex prompts<br/>prompt data"]
  node_benchmark_index["Benchmark index<br/>metadata index"]
end

subgraph group_repair["Repair rules"]
  node_rules1["Phase 1 rules<br/>repair rules"]
  node_rules2["Phase 2 rules<br/>repair rules"]
  node_rules3["Phase 3 rules<br/>repair rules"]
end

node_simp_prompts -->|"prompt input"| node_main_py
node_comp_prompts -->|"prompt input"| node_main_py
node_main_py -->|"writes"| node_predictions_jsonl
node_predictions_jsonl -->|"consumes"| node_evaluate_py
node_evaluate_py -->|"invokes"| node_modal_eval_app_py
node_modal_eval_app_py -->|"resolves targets"| node_tritonbench_helpers_py
node_benchmark_index -->|"lookup data"| node_tritonbench_helpers_py
node_predictions_jsonl -->|"input"| node_modal_eval_app_py
node_modal_eval_app_py -->|"runs"| node_phase1
node_phase1 -->|"continues"| node_phase2
node_phase2 -->|"continues"| node_phase3
node_phase1 -->|"stores results"| node_modal_volume
node_phase2 -->|"stores results"| node_modal_volume
node_phase3 -->|"stores results"| node_modal_volume
node_agentic_eval_py -->|"writes attempts"| node_predictions_jsonl
node_agentic_eval_py -->|"reuses"| node_evaluate_py
node_agentic_eval_py -->|"uses"| node_rules1
node_agentic_eval_py -->|"uses"| node_rules2
node_agentic_eval_py -->|"uses"| node_rules3
node_agentic_eval_py -->|"persists"| node_modal_volume
node_modal_volume -->|"returns artifacts"| node_evaluate_py

click node_main_py "https://github.com/pablo389/deepbork/blob/main/main.py"
click node_evaluate_py "https://github.com/pablo389/deepbork/blob/main/evaluate.py"
click node_agentic_eval_py "https://github.com/pablo389/deepbork/blob/main/agentic_eval.py"
click node_tritonbench_helpers_py "https://github.com/pablo389/deepbork/blob/main/tritonbench_helpers.py"
click node_modal_eval_app_py "https://github.com/pablo389/deepbork/blob/main/modal_eval_app.py"
click node_simp_prompts "https://github.com/pablo389/deepbork/blob/main/data/TritonBench_T_simp_alpac_v1.json"
click node_comp_prompts "https://github.com/pablo389/deepbork/blob/main/data/TritonBench_T_comp_alpac_v1.json"
click node_benchmark_index "https://github.com/pablo389/deepbork/blob/main/data/TritonBench_T_v1.jsonl"
click node_rules1 "https://github.com/pablo389/deepbork/blob/main/repair_rules/triton_phase1_rules.json"
click node_rules2 "https://github.com/pablo389/deepbork/blob/main/repair_rules/triton_phase2_rules.json"
click node_rules3 "https://github.com/pablo389/deepbork/blob/main/repair_rules/triton_phase3_rules.json"

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_main_py,node_evaluate_py,node_agentic_eval_py,node_tritonbench_helpers_py toneBlue
class node_modal_eval_app_py,node_modal_volume,node_phase1,node_phase2,node_phase3 toneAmber
class node_predictions_jsonl,node_simp_prompts,node_comp_prompts,node_benchmark_index toneMint
class node_rules1,node_rules2,node_rules3 toneRose
```

## Components

### Local orchestration

CLI entrypoints and local repair loop.

- [Generator](https://github.com/pablo389/deepbork/blob/main/main.py): CLI entrypoint · Batch generation entrypoint that builds prompts, calls an LLM, and writes predictions. · `main.py`
- [Eval launcher](https://github.com/pablo389/deepbork/blob/main/evaluate.py): CLI wrapper · Local wrapper that selects evaluation mode and invokes the remote Modal app. · `evaluate.py`
- [Agentic loop](https://github.com/pablo389/deepbork/blob/main/agentic_eval.py): repair loop · Single-operator generate/evaluate/repair workflow with per-attempt artifacts. · `agentic_eval.py`
- [Metadata crosswalk](https://github.com/pablo389/deepbork/blob/main/tritonbench_helpers.py): mapping helper · Resolves instructions to TritonBench operator files and tests. · `tritonbench_helpers.py`

### Remote benchmark

Modal-based execution boundary and remote artifact store.

- [Modal runner](https://github.com/pablo389/deepbork/blob/main/modal_eval_app.py): remote executor · Defines the Modal image, GPU runtime, harness setup, and phase execution on Modal. · `modal_eval_app.py`
- **Modal volume**: artifact store · Remote phase outputs persisted across Modal evaluation runs.
- **Phase 1**: call accuracy · Initial correctness and call-accuracy filtering stage.
- **Phase 2**: semantic filter · Additional semantic and execution filtering stage.
- **Phase 3**: performance bench · Performance-oriented evaluation stage.

### Benchmark data

Prompt inputs, metadata index, and shared prediction contract.

- **Predictions**: interchange file · Primary contract containing instruction and predict fields for generation and evaluation.
- [Simple prompts](https://github.com/pablo389/deepbork/blob/main/data/TritonBench_T_simp_alpac_v1.json): prompt data · Alpaca-formatted simple TritonBench-T prompts. · `data/TritonBench_T_simp_alpac_v1.json`
- [Complex prompts](https://github.com/pablo389/deepbork/blob/main/data/TritonBench_T_comp_alpac_v1.json): prompt data · Alpaca-formatted complex TritonBench-T prompts. · `data/TritonBench_T_comp_alpac_v1.json`
- [Benchmark index](https://github.com/pablo389/deepbork/blob/main/data/TritonBench_T_v1.jsonl): metadata index · Maps prompt instructions back to operator files and tests. · `data/TritonBench_T_v1.jsonl`

### Repair rules

Stage-specific failure guidance for the agentic loop.

- [Phase 1 rules](https://github.com/pablo389/deepbork/blob/main/repair_rules/triton_phase1_rules.json): repair rules · JSON guidance for failures detected in Phase 1. · `repair_rules/triton_phase1_rules.json`
- [Phase 2 rules](https://github.com/pablo389/deepbork/blob/main/repair_rules/triton_phase2_rules.json): repair rules · JSON guidance for failures detected in Phase 2. · `repair_rules/triton_phase2_rules.json`
- [Phase 3 rules](https://github.com/pablo389/deepbork/blob/main/repair_rules/triton_phase3_rules.json): repair rules · JSON guidance for failures detected in Phase 3. · `repair_rules/triton_phase3_rules.json`

## Connections

- Simple prompts → Generator: prompt input · Generator reads simple benchmark prompts.
- Complex prompts → Generator: prompt input · Generator reads complex benchmark prompts.
- Generator → Predictions: writes · Batch generation emits the shared predictions contract.
- Predictions → Eval launcher: consumes · Local evaluation launcher passes predictions to remote execution.
- Eval launcher → Modal runner: invokes · Launches the Modal evaluation boundary.
- Modal runner → Metadata crosswalk: resolves targets · Remote app maps instructions to benchmark operators and tests.
- Benchmark index → Metadata crosswalk: lookup data · Metadata index feeds instruction-to-target resolution.
- Predictions → Modal runner: input · Remote evaluation consumes generated predictions.
- Modal runner → Phase 1: runs · Phase 1 is the first evaluation stage.
- Phase 1 → Phase 2: continues · Successful or selected outputs proceed to Phase 2.
- Phase 2 → Phase 3: continues · Phase 3 follows the semantic filter stage.
- Phase 1 → Modal volume: stores results · Phase outputs are persisted in the Modal Volume.
- Phase 2 → Modal volume: stores results · Phase outputs are persisted in the Modal Volume.
- Phase 3 → Modal volume: stores results · Phase outputs are persisted in the Modal Volume.
- Agentic loop → Predictions: writes attempts · Each repair attempt regenerates predictions and related artifacts.
- Agentic loop → Eval launcher: reuses · The repair loop calls the same evaluation launcher.
- Agentic loop → Phase 1 rules: uses · Phase 1 failure guidance is injected on demand.
- Agentic loop → Phase 2 rules: uses · Phase 2 failure guidance is injected on demand.
- Agentic loop → Phase 3 rules: uses · Phase 3 failure guidance is injected on demand.
- Agentic loop → Modal volume: persists · Per-op and per-attempt artifacts are stored remotely when needed.
- Modal volume → Eval launcher: returns artifacts · Remote results are surfaced back to the local orchestration layer.
