# lexsi-labs/aligntune architecture

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

- Interactive diagram: https://gitdiagram.com/lexsi-labs/aligntune
- Repository: https://github.com/lexsi-labs/aligntune

## Overview

AlignTune is a toolkit for LLM post-training: users configure training through its Python API or CLI, select an algorithm and backend, and train/evaluate models. Its major branches include SFT/RL and other training methods, reward functions, data preparation, model adaptation, evaluation/auditing, and model export/merging. The README documents capabilities and the training entry points; sampled source confirms the CLI-to-factory call. Other internal links are omitted where the excerpts do not establish ownership.

Main entry points: [`src/aligntune/core/backend_factory.py`](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/backend_factory.py) (Backend factory), [`src/aligntune/cli/unified.py`](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/cli/unified.py) (Training CLI), [`src/aligntune/main.py`](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/main.py) (Training entry point), [`src/aligntune/core/rl/trainer_factory.py`](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/rl/trainer_factory.py) (RL trainers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User Entry"]
  node_cli["Training CLI<br/>[unified.py]"]
  node_main["Training entry point<br/>[main.py]"]
  node_advisor["Utility advisor<br/>[advisor.py]"]
  node_composition["Stage compositions<br/>[runner.py]"]
end

subgraph group_training["Training Runtime"]
  node_factory["Backend factory<br/>[backend_factory.py]"]
  node_sft["SFT trainers<br/>[trainer_factory.py]"]
  node_rl["RL trainers<br/>[trainer_factory.py]"]
  node_backendfamilies["TRL, Unsloth, ES"]
  node_distill["Distillation<br/>[trainer_factory.py]"]
  node_raft["RAFT training<br/>[raft_trainer.py]"]
end

subgraph group_data["Data and Models"]
  node_data_manager["Dataset manager<br/>[manager.py]"]
  node_model_loader["Model loading<br/>[model_loader.py]"]
end

subgraph group_alignment["Rewards and Evaluation"]
  node_reward["Reward functions<br/>[core.py]"]
  node_verifiable["Verifiable rewards<br/>[verifiable.py]"]
  node_reward_handler["RL reward handling<br/>[reward_handler.py]"]
  node_evaluation["Model evaluation<br/>[runner.py]"]
  node_audit["Alignment audit"]
end

subgraph group_extensions["Model Extensions"]
  node_adapters["PEFT and adapters"]
  node_longcontext["Long-context support"]
  node_tokenization["Indic tokenization"]
  node_merge["Model merging"]
  node_export["Model export"]
end

node_user(("Engineer"))

node_user -->|"runs commands"| node_cli
node_user -->|"creates trainer"| node_factory
node_cli -.->|"runs training"| node_main
node_main -->|"creates trainer"| node_factory
node_user -->|"estimates resources"| node_advisor
node_user -->|"orchestrates stages"| node_composition
node_factory -->|"routes training"| node_backendfamilies
node_factory -->|"creates SFT trainer"| node_sft
node_factory -->|"creates RL trainer"| node_rl
node_factory -->|"creates trainer"| node_distill
node_factory -->|"creates trainer"| node_raft
node_data_manager -.->|"supplies datasets"| node_factory
node_model_loader -.->|"supplies models"| node_factory
node_rl -.->|"computes rewards"| node_reward_handler
node_reward_handler -->|"uses reward functions"| node_reward
node_reward -->|"includes functions"| node_verifiable
node_user -->|"evaluates model"| node_evaluation
node_user -->|"audits alignment"| node_audit
node_user -->|"configures adapters"| node_adapters
node_user -->|"configures context"| node_longcontext
node_user -->|"extends vocabulary"| node_tokenization
node_user -->|"merges models"| node_merge
node_user -->|"exports model"| node_export

click node_cli "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/cli/unified.py"
click node_main "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/main.py"
click node_advisor "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/advisor.py"
click node_composition "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/composition/runner.py"
click node_factory "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/backend_factory.py"
click node_sft "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/sft/trainer_factory.py"
click node_rl "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/rl/trainer_factory.py"
click node_backendfamilies "https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/backends"
click node_distill "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/distill/trainer_factory.py"
click node_raft "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/backends/trl/raft/raft_trainer.py"
click node_data_manager "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/data/manager.py"
click node_model_loader "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/model_loader.py"
click node_reward "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/rewards/core.py"
click node_verifiable "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/rewards/verifiable.py"
click node_reward_handler "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/rl/reward_handler.py"
click node_evaluation "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/eval/runner.py"
click node_audit "https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/eval/alignment_auditor.py"
click node_adapters "https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/core/adapters"
click node_longcontext "https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/core/long_context"
click node_tokenization "https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/core/tokenization"
click node_merge "https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/core/merge"
click node_export "https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/core/export"

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_cli,node_main,node_advisor,node_composition toneBlue
class node_factory,node_sft,node_rl,node_backendfamilies,node_distill,node_raft toneAmber
class node_data_manager,node_model_loader toneMint
class node_reward,node_verifiable,node_reward_handler,node_evaluation,node_audit toneRose
class node_adapters,node_longcontext,node_tokenization,node_merge,node_export,node_user toneIndigo
```

## Components

### User Entry

- [Training CLI](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/cli/unified.py): `src/aligntune/cli/unified.py`
- [Training entry point](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/main.py): `src/aligntune/main.py`
- [Utility advisor](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/advisor.py): `src/aligntune/core/advisor.py`
- [Stage compositions](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/composition/runner.py): `src/aligntune/core/composition/runner.py`

### Training Runtime

- [Backend factory](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/backend_factory.py): `src/aligntune/core/backend_factory.py`
- [SFT trainers](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/sft/trainer_factory.py): `src/aligntune/core/sft/trainer_factory.py`
- [RL trainers](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/rl/trainer_factory.py): `src/aligntune/core/rl/trainer_factory.py`
- [TRL, Unsloth, ES](https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/backends): `src/aligntune/backends`
- [Distillation](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/distill/trainer_factory.py): `src/aligntune/core/distill/trainer_factory.py`
- [RAFT training](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/backends/trl/raft/raft_trainer.py): `src/aligntune/backends/trl/raft/raft_trainer.py`

### Data and Models

- [Dataset manager](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/data/manager.py): `src/aligntune/data/manager.py`
- [Model loading](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/model_loader.py): `src/aligntune/core/model_loader.py`

### Rewards and Evaluation

- [Reward functions](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/rewards/core.py): `src/aligntune/rewards/core.py`
- [Verifiable rewards](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/rewards/verifiable.py): `src/aligntune/rewards/verifiable.py`
- [RL reward handling](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/core/rl/reward_handler.py): `src/aligntune/core/rl/reward_handler.py`
- [Model evaluation](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/eval/runner.py): `src/aligntune/eval/runner.py`
- [Alignment audit](https://github.com/lexsi-labs/aligntune/blob/main/src/aligntune/eval/alignment_auditor.py): `src/aligntune/eval/alignment_auditor.py`

### Model Extensions

- [PEFT and adapters](https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/core/adapters): `src/aligntune/core/adapters`
- [Long-context support](https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/core/long_context): `src/aligntune/core/long_context`
- [Indic tokenization](https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/core/tokenization): `src/aligntune/core/tokenization`
- [Model merging](https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/core/merge): `src/aligntune/core/merge`
- [Model export](https://github.com/lexsi-labs/aligntune/tree/main/src/aligntune/core/export): `src/aligntune/core/export`

### Other components

- **Engineer**

## Connections

- Engineer → Training CLI: runs commands (evidence: `README.md`)
- Engineer → Backend factory: creates trainer (evidence: `README.md`)
- Training CLI → Training entry point: runs training
- Training entry point → Backend factory: creates trainer (evidence: `src/aligntune/main.py`)
- Engineer → Utility advisor: estimates resources (evidence: `README.md`)
- Engineer → Stage compositions: orchestrates stages (evidence: `README.md`)
- Backend factory → TRL, Unsloth, ES: routes training (evidence: `README.md`)
- Backend factory → SFT trainers: creates SFT trainer (evidence: `README.md`)
- Backend factory → RL trainers: creates RL trainer (evidence: `README.md`)
- Backend factory → Distillation: creates trainer (evidence: `README.md`)
- Backend factory → RAFT training: creates trainer (evidence: `README.md`)
- Dataset manager → Backend factory: supplies datasets
- Model loading → Backend factory: supplies models
- RL trainers → RL reward handling: computes rewards
- RL reward handling → Reward functions: uses reward functions (evidence: `src/aligntune/core/rl/reward_handler.py`)
- Reward functions → Verifiable rewards: includes functions (evidence: `src/aligntune/rewards/core.py`)
- Engineer → Model evaluation: evaluates model (evidence: `README.md`)
- Engineer → Alignment audit: audits alignment (evidence: `README.md`)
- Engineer → PEFT and adapters: configures adapters (evidence: `README.md`)
- Engineer → Long-context support: configures context (evidence: `README.md`)
- Engineer → Indic tokenization: extends vocabulary (evidence: `README.md`)
- Engineer → Model merging: merges models (evidence: `README.md`)
- Engineer → Model export: exports model (evidence: `README.md`)
