How nabin2004/dhant works
1. Repository purpose
- dhant is a lightweight Python package for learning post-training workflows. It is not a full production trainer stack yet; most components are educational placeholders that simulate training behavior while preserving a clean architecture.
2. Core subsystems
- The package is split into three main runtime areas: trainer/ for training orchestration, rewards/ for reusable reward functions, and cli/ for command-line entrypoints. scripts/ contains runnable examples and quickstart flows.
3. Trainer layer as the main orchestration boundary
- src/dhant/trainer/ is the central subsystem. It contains a shared base.py, per-task config modules, and trainer implementations for:
- SFT (sft_trainer.py, sft_config.py)
- DPO (dpo_trainer.py, dpo_config.py)
- GRPO (grpo_trainer.py, grpo_config.py)
- Reward model training (reward_trainer.py, reward_config.py)
- This layer is the primary place where datasets, models, reward functions, logging, and run outputs are coordinated.
4. Task-specific training flows
- The trainers represent separate post-training pipelines:
- SFT consumes a model and training dataset.
- DPO is intended for preference-pair optimization.
- GRPO connects model generation with reward scoring and aggregation.
- Reward training is the dedicated path for fitting reward models.
- The README indicates the current implementation is simulated, so these flows are architectural templates rather than fully connected ML pipelines.
5. Reward subsystem
- src/dhant/rewards/ defines a small reward-function boundary:
- base_reward.py establishes the interface
- accuracy_reward.py, format_reward.py, and reasoning_reward.py provide concrete reusable reward functions
- These rewards are especially relevant to GRPO-style training, where trainer logic consumes one or more reward functions to score outputs.
6. Adapters and parameter-efficient tuning
- trainer/adapters.py contains boilerplate configs for memory- and parameter-efficient fine-tuning, including quantization, LoRA, and QLoRA.
- These are exposed both through Python APIs and CLI flags, making them a cross-cutting concern that affects trainer setup before any loop begins.
7. CLI as the user-facing entry boundary
- src/dhant/cli/main.py is the operational entrypoint for end users.
- The CLI maps subcommands to trainer workflows: sft, dpo, grpo, and reward.
- It also carries run metadata and logging flags, so the CLI is the boundary where user intent becomes a configured training run.
8. Run management, logging, and monitoring
- The project writes each run into an isolated experiment folder under outputs/experiments/....
- Each run contains logs, TensorBoard data, checkpoints, and artifacts such as run_summary.json.
- This means the architecture includes a persistent run-recording layer, not just in-memory training output.
- TensorBoard is an optional monitoring integration, enabled via the package’s monitoring extras.
9. Error handling and execution semantics
- Training failures are wrapped in TrainingExecutionError.
- The architecture explicitly separates user-facing failure reporting from detailed traceback capture: concise errors go to the CLI, while full diagnostics are stored per run in log files.
- This suggests the trainer layer owns execution robustness, while the CLI owns exit status and user feedback.
10. Supporting scripts and learning path
- src/dhant/scripts/quickstart.py is a lightweight runnable example that demonstrates the intended package usage outside the CLI.
- The README’s learning path shows the project is designed for incremental replacement: start with simulated trainers, then add real loops, dataset adapters, preference handling, generation/reward aggregation, and evaluation.
11. Validation and test coverage
- Tests focus on the architectural seams: tests/test_adapters.py and tests/test_template_trainers.py.
- That indicates the repository is testing configuration and template behavior more than heavy model execution, which matches its template-oriented design.
12. Important architecture diagram boundaries
- A good diagram should show:
- external user input through CLI or Python API
- trainer selection by task
- optional adapter/config preprocessing
- reward function injection into GRPO/reward workflows
- run outputs flowing to experiment directories, logs, checkpoints, and TensorBoard
- The major boundary is between orchestration/template code in this repo and the real ML backend that a future implementation would plug in.
Main entry points: grpo_trainer.py GRPO Trainer · base.py Trainer Base · main.py CLI · reward_trainer.py Reward Trainer
Components 19
Interface
User-facing entrypoints and example flow
- User · Invokes the package through the CLI or Python API
- CLI · Maps subcommands into trainer workflows and run metadata
src/dhant/cli/main.py - Quickstart · Runnable learning example outside the CLI
src/dhant/scripts/quickstart.py
Training
Core orchestration and task-specific trainer templates
- Trainer Base · Shared training boundary for execution, coordination, and errors
src/dhant/trainer/base.py - Adapters · Quantization, LoRA, and QLoRA setup helpers
src/dhant/trainer/adapters.py - SFT Trainer · Supervised fine-tuning orchestration template
src/dhant/trainer/sft_trainer.py - SFT Config · Configuration for SFT runs
src/dhant/trainer/sft_config.py - DPO Trainer · Preference optimization orchestration template
src/dhant/trainer/dpo_trainer.py - DPO Config · Configuration for DPO runs
src/dhant/trainer/dpo_config.py - GRPO Trainer · Generation, reward scoring, and aggregation template
src/dhant/trainer/grpo_trainer.py - GRPO Config · Configuration for GRPO runs
src/dhant/trainer/grpo_config.py - Reward Trainer · Dedicated reward model training template
src/dhant/trainer/reward_trainer.py - Reward Config · Configuration for reward model runs
src/dhant/trainer/reward_config.py
Rewards
Reusable reward function boundary
- Reward Base · Common reward-function contract
src/dhant/rewards/base_reward.py - Accuracy Reward · Reusable accuracy-oriented scoring
src/dhant/rewards/accuracy_reward.py - Format Reward · Reusable formatting and structure scoring
src/dhant/rewards/format_reward.py - Reasoning Reward · Reusable reasoning-quality scoring
src/dhant/rewards/reasoning_reward.py
Runtime
Run outputs and monitoring artifacts
- Run Outputs · Per-run experiment folders with checkpoints, logs, and summaries
- TensorBoard · Optional experiment monitoring channel
Connections 26
- User → CLI: runs · User launches task-specific workflows through the CLI
- User → Quickstart: uses · User can also explore the package through the example script
- CLI → SFT Trainer: selects · CLI subcommand routes to the SFT workflow
- CLI → DPO Trainer: selects · CLI subcommand routes to the DPO workflow
- CLI → GRPO Trainer: selects · CLI subcommand routes to the GRPO workflow
- CLI → Reward Trainer: selects · CLI subcommand routes to the reward-model workflow
- Quickstart → Trainer Base: demonstrates · Example flow exercises the shared orchestration boundary
- SFT Trainer → Trainer Base: extends · SFT is built on the shared trainer boundary
- DPO Trainer → Trainer Base: extends · DPO is built on the shared trainer boundary
- GRPO Trainer → Trainer Base: extends · GRPO is built on the shared trainer boundary
- Reward Trainer → Trainer Base: extends · Reward training is built on the shared trainer boundary
- SFT Trainer → SFT Config: uses · SFT flow is parameterized by its config
- DPO Trainer → DPO Config: uses · DPO flow is parameterized by its config
- GRPO Trainer → GRPO Config: uses · GRPO flow is parameterized by its config
- Reward Trainer → Reward Config: uses · Reward training flow is parameterized by its config
- Trainer Base → Adapters: prepares · Shared setup applies tuning and memory-efficiency options before execution
- GRPO Trainer → Reward Base: scores with · GRPO consumes reward functions for output scoring
- GRPO Trainer → Accuracy Reward: can use · GRPO may include accuracy scoring
- GRPO Trainer → Format Reward: can use · GRPO may include format scoring
- GRPO Trainer → Reasoning Reward: can use · GRPO may include reasoning scoring
- Reward Trainer → Reward Base: trains against · Reward-model workflow aligns to the reward-function contract
- SFT Trainer → Run Outputs: writes · SFT run artifacts are recorded per experiment
- DPO Trainer → Run Outputs: writes · DPO run artifacts are recorded per experiment
- GRPO Trainer → Run Outputs: writes · GRPO run artifacts are recorded per experiment
- Reward Trainer → Run Outputs: writes · Reward-training run artifacts are recorded per experiment
- Run Outputs → TensorBoard: feeds · Stored metrics can be surfaced in TensorBoard