Skip to content

Repository files navigation

BrainForge

CIpythonlicensecode style

Turn real-world data into verified training datasets with multi-teacher LLM pipelines, then train small local models on them.

BrainForge builds security and coding datasets from real material (vulnerable code, CVEs, patches, git history, documentation), verifies every example through independent LLM teachers and a judge, and fine-tunes a 7-9B student locally with QLoRA on a single RTX 3080 10GB. The engine is domain-agnostic: specializations plug in as domain packs (security and coding ship today).

Quickstart

git clone git@github.com:log0u7/brainforge.git &&cd brainforge
mise install && uv sync

Validate the shipped configuration, then generate a dataset at zero cost with the mock provider:

uv run brainforge config validate
uv run brainforge pipeline run security_dataset --input examples/cases --provider mock
security_dataset: 3 accepted, 0 rejected (3 cases) -> datasets/security_dataset.jsonl

Inspect what was produced, then export training splits:

uv run brainforge dataset inspect datasets/security_dataset.jsonl
uv run brainforge train prepare datasets/security_dataset.jsonl

Point the teachers at real providers by exporting OPENROUTER_API_KEY and ZENCODE_API_KEY and dropping --provider mock. Full walkthrough: build your first dataset.

How it works

 ┌──────────────────┐
│ LOCAL DATA │
│ CVE / Git / Code │
│ Docs / Markdown │
└────────┬─────────┘
▼
┌──────────────────┐
│ LOCAL RAG │
└────────┬─────────┘
▼
┌──────────────────┐
│ CASE BUILDER │
└────────┬─────────┘
┌─────────────────┼─────────────────┐
▼ ▼ ▼
┌───────────┐ ┌───────────┐ ┌───────────┐
│ OpenRouter│ │ OpenCode │ │ MLGW │
│ security │ │ Zen │ │ general │
│ teacher │ │ coding │ │ critic │
└─────┬─────┘ └─────┬─────┘ └─────┬─────┘
└─────────────────┼─────────────────┘
▼
┌──────────────────┐
│ JUDGE (distinct │
│ provider/family) │
└────────┬─────────┘
QUALITY GATE
▼
┌──────────────────┐
│ dataset.jsonl │
│ + provenance │
└────────┬─────────┘
QLoRA SFT
▼
┌──────────────────┐
│ STUDENT 7-9B │
│ local GPU │
└──────────────────┘

What you get

CapabilityDetail
Provider layerOpenRouter, OpenCode Zen, MLGW, local servers, deterministic mock; sqlite cache, retries, usage logs with cost estimates
Multi-teacher ensemblesIndependent teachers, adversarial judge, cost modes (cheap / standard / maximum), teacher ablation by config
Judge independenceEnforced at config load: distinct provider and model family from every teacher
Contamination controlsPer-teacher knowledge_cutoff, source dates, recitation_risk tagging, post-cutoff holdout as the primary benchmark
Local RAGfastembed (ONNX, CPU) or hashing embeddings, sqlite + numpy store, full chunk provenance
Quality gatesPer-domain rules (evidence, CWE format, confidence), rejected-case quarantine, exact + near-duplicate detection
DatasetsJSONL with chat messages + separated provenance metadata, source-grouped splits, TRL-ready export
Training prepValidate / split / export; QLoRA 4-bit scaffolding for phase 2 on one RTX 3080 10GB
Toolingbrainforge CLI (typer + rich), Makefile, 112 tests, GitHub Actions CI and a manual GPU smoke job

Principles

  1. Separation of concerns: provider ≠ model ≠ role ≠ pipeline; the pipeline never knows a vendor exists.
  2. Independent verification: the judge shares neither provider nor model family with any teacher, because erroneous agreement is the dangerous failure mode.
  3. Contamination awareness: the student is benchmarked on cases the teachers cannot have memorized; gains must mean analysis, not recitation.
  4. Provenance everywhere: teachers, judge, RAG chunks and gate results travel with every record.
  5. Quality over volume: verified, deduplicated, source-grouped data beats mass-produced synthetic examples.

Providers

ProviderTypeRole in the default config
OpenRouteropenroutersecurity + coding teachers
OpenCode Zenzenjudge
MLGW (local gateway)mlgwgeneral critic
Mockmockzero-cost demos and tests

Documentation

SectionContent
Tutorialfirst dataset in 10 minutes, no keys
How-to guidesproviders, RAG, generation, dataset management, domain packs, ADRs
Referenceconfiguration, providers, CLI, dataset format, quality gates, RAG, training, CI
Explanationarchitecture, contamination, judge correlation
Decision records10 MADR ADRs behind the design

Development

make install # uv sync
make test# pytest (unit)
make lint # ruff check + format check
make config # config validate + schema check
make docs-serve # local documentation

Contributions welcome: see CONTRIBUTING.md and the ROADMAP (phase 2: QLoRA training and the golden dataset).

License

Apache-2.0.

About

Agentic tooling for building security & coding datasets and training small local language models.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages