# zhuchichi56/asft architecture

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

- Interactive diagram: https://gitdiagram.com/zhuchichi56/asft
- Repository: https://github.com/zhuchichi56/asft

## Overview

#### Purpose and entry points
ASFT is a Python post-training repository for Anchored Supervised Fine-Tuning: supervised/DFT-style optimization augmented with KL anchoring to limit distributional drift. The primary executable is `train_v2.py`; shell invocation defaults are captured in `train_v2.sh`. Development/debug training is separate in `dev/train_debug.py` and `dev/train_debug.sh`.

#### Training orchestration
`train_v2.py` is the central control plane: it accepts model, dataset, mode (including ASFT), optimization, precision, LoRA, and distributed-training arguments, then runs model fine-tuning. The repository is designed for local or multi-GPU execution rather than a persistent service. DeepSpeed launch is supported through JSON stage/precision configurations:
- `train_v2.py`
- `scripts/ds_zero2_bf16.json`
- `scripts/ds_zero3_bf16.json`

#### ASFT data and model boundary
Training consumes a user-supplied JSONL dataset and a model path/repository; large training data is intentionally external. `download_data.py` provides the data acquisition boundary, targeting the Hugging Face `chichi56/ASFT` dataset. Model weights and tokenizer/runtime behavior are supplied by the installed ML stack rather than stored in this repository.
- `download_data.py`
- `requirements.txt`
- `asft.pdf`

#### Distributed and adapter execution
The training path supports native PyTorch-style execution, DeepSpeed Zero-2/Zero-3, mixed bf16/fp16 precision, and LoRA adapters. DeepSpeed is an optional distributed runtime boundary; its configuration controls memory partitioning and precision, while LoRA allows parameter-efficient updates. CUDA-compatible PyTorch and optional FlashAttention are material runtime dependencies described by the project.
- `train_v2.py`
- `scripts/ds_zero2_fp16.json`
- `scripts/ds_zero3_bf16.json`

#### Evaluation portfolio
Evaluation is a set of independent batch workflows over trained checkpoints rather than one unified service. Alpaca-style instruction evaluation enters through `eval/alpaca_eval_test.py` and vendors the AlpacaEval Python package under `eval/alpacaeval/`. Mathematical evaluation has its own inference, parsing, execution, grading, and aggregation pipeline; medical evaluation provides VLLM-based and runner-based entry points.
- `eval/alpaca_eval_test.py`
- `eval/math_evaluation/evaluate.py`
- `eval/medeval/vllm_medical_test.py`

#### AlpacaEval subsystem
The vendored AlpacaEval package is a configurable model-generation and pairwise-judging system. Its main module coordinates evaluation; decoder adapters isolate external provider/local inference APIs; pairwise evaluators turn completions into preferences; metric modules calculate win-rate variants, including length-controlled/weighted scoring. Model and evaluator configuration directories are the declarative boundary for prompts, providers, and judge settings.
- `eval/alpacaeval/src/alpaca_eval/main.py`
- `eval/alpacaeval/src/alpaca_eval/decoders/openai.py`
- `eval/alpacaeval/src/alpaca_eval/annotators/pairwise_evaluator.py`

#### Math and medical evaluation flow
Math evaluation reads benchmark JSON/JSONL, produces model outputs, parses candidate answers, optionally executes Python, grades results, and aggregates tables. Its datasets are repository-contained across many benchmarks. Medical evaluation reads three included test sets and runs benchmark-specific inference/evaluation. These paths may require GPU-serving infrastructure such as vLLM and model access.
- `eval/math_evaluation/inference.py`
- `eval/math_evaluation/grader.py`
- `eval/medeval/run_med_eval.py`

Main entry points: [`train_v2.py`](https://github.com/zhuchichi56/asft/blob/main/train_v2.py) (Training control plane), [`eval/alpacaeval/src/alpaca_eval/main.py`](https://github.com/zhuchichi56/asft/blob/main/eval/alpacaeval/src/alpaca_eval/main.py) (Evaluation coordinator), [`eval/math_evaluation/evaluate.py`](https://github.com/zhuchichi56/asft/blob/main/eval/math_evaluation/evaluate.py) (Math evaluation), [`eval/alpaca_eval_test.py`](https://github.com/zhuchichi56/asft/blob/main/eval/alpaca_eval_test.py) (AlpacaEval workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_training["Training"]
  node_train["Training control plane<br/>Python CLI<br/>[train_v2.py]"]
  node_train_shell["Training launcher<br/>shell script<br/>[train_v2.sh]"]
  node_debug_train["Debug training<br/>Python CLI<br/>[train_debug.py]"]
  node_dataset[("User JSONL dataset<br/>external data")]
  node_asft["ASFT optimization<br/>training mode<br/>[train_v2.py]"]
  node_lora["LoRA adapters<br/>adapter mode<br/>[train_v2.py]"]
  node_download["Dataset acquisition<br/>Python CLI<br/>[download_data.py]"]
end

subgraph group_runtime["Runtime"]
  node_model{{"Model and tokenizer<br/>external model"}}
  node_deepspeed{{"DeepSpeed runtime<br/>distributed runtime"}}
  node_zero2["ZeRO-2 bf16 config<br/>DeepSpeed config<br/>[ds_zero2_bf16.json]"]
  node_zero3["ZeRO-3 bf16 config<br/>DeepSpeed config<br/>[ds_zero3_bf16.json]"]
  node_ml_stack["ML dependencies<br/>Python dependencies<br/>[requirements.txt]"]
end

subgraph group_alpaca["AlpacaEval"]
  node_alpaca_entry["AlpacaEval workflow<br/>Python CLI"]
  node_alpaca_main["Evaluation coordinator<br/>Python module<br/>[main.py]"]
  node_decoder["Decoder adapters<br/>inference adapter<br/>[openai.py]"]
  node_pairwise["Pairwise judging<br/>evaluator"]
end

subgraph group_benchmarks["Benchmark Evaluation"]
  node_math_eval["Math evaluation<br/>Python CLI<br/>[evaluate.py]"]
  node_math_inference["Math inference<br/>inference stage<br/>[inference.py]"]
  node_math_grader["Math grading<br/>grading stage<br/>[grader.py]"]
  node_medical_vllm["Medical vLLM evaluation<br/>Python CLI"]
  node_medical_runner["Medical evaluation runner<br/>Python CLI<br/>[run_med_eval.py]"]
end

node_train_shell -->|"launches"| node_train
node_debug_train -.->|"development alternative"| node_train
node_download -->|"acquires"| node_dataset
node_dataset -->|"training input"| node_train
node_model -->|"base model"| node_train
node_ml_stack -->|"provides runtime"| node_train
node_train -->|"selects mode"| node_asft
node_train -.->|"optionally enables"| node_lora
node_train -.->|"optionally launches with"| node_deepspeed
node_zero2 -->|"configures"| node_deepspeed
node_zero3 -->|"configures"| node_deepspeed
node_train -.->|"trained checkpoint"| node_alpaca_entry
node_alpaca_entry -->|"runs"| node_alpaca_main
node_alpaca_main -->|"generates completions"| node_decoder
node_decoder -->|"completions"| node_pairwise
node_pairwise -->|"preferences and metrics"| node_alpaca_main
node_train -.->|"trained checkpoint"| node_math_eval
node_math_eval -->|"runs"| node_math_inference
node_math_inference -->|"candidate answers"| node_math_grader
node_math_grader -->|"grades and aggregates"| node_math_eval
node_train -.->|"trained checkpoint"| node_medical_vllm
node_medical_runner -.->|"alternative workflow"| node_medical_vllm

click node_train "https://github.com/zhuchichi56/asft/blob/main/train_v2.py"
click node_train_shell "https://github.com/zhuchichi56/asft/blob/main/train_v2.sh"
click node_debug_train "https://github.com/zhuchichi56/asft/blob/main/dev/train_debug.py"
click node_asft "https://github.com/zhuchichi56/asft/blob/main/train_v2.py"
click node_lora "https://github.com/zhuchichi56/asft/blob/main/train_v2.py"
click node_zero2 "https://github.com/zhuchichi56/asft/blob/main/scripts/ds_zero2_bf16.json"
click node_zero3 "https://github.com/zhuchichi56/asft/blob/main/scripts/ds_zero3_bf16.json"
click node_ml_stack "https://github.com/zhuchichi56/asft/blob/main/requirements.txt"
click node_download "https://github.com/zhuchichi56/asft/blob/main/download_data.py"
click node_alpaca_entry "https://github.com/zhuchichi56/asft/blob/main/eval/alpaca_eval_test.py"
click node_alpaca_main "https://github.com/zhuchichi56/asft/blob/main/eval/alpacaeval/src/alpaca_eval/main.py"
click node_decoder "https://github.com/zhuchichi56/asft/blob/main/eval/alpacaeval/src/alpaca_eval/decoders/openai.py"
click node_pairwise "https://github.com/zhuchichi56/asft/blob/main/eval/alpacaeval/src/alpaca_eval/annotators/pairwise_evaluator.py"
click node_math_eval "https://github.com/zhuchichi56/asft/blob/main/eval/math_evaluation/evaluate.py"
click node_math_inference "https://github.com/zhuchichi56/asft/blob/main/eval/math_evaluation/inference.py"
click node_math_grader "https://github.com/zhuchichi56/asft/blob/main/eval/math_evaluation/grader.py"
click node_medical_vllm "https://github.com/zhuchichi56/asft/blob/main/eval/medeval/vllm_medical_test.py"
click node_medical_runner "https://github.com/zhuchichi56/asft/blob/main/eval/medeval/run_med_eval.py"

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_train,node_train_shell,node_debug_train,node_dataset,node_asft,node_lora,node_download toneBlue
class node_model,node_deepspeed,node_zero2,node_zero3,node_ml_stack toneAmber
class node_alpaca_entry,node_alpaca_main,node_decoder,node_pairwise toneMint
class node_math_eval,node_math_inference,node_math_grader,node_medical_vllm,node_medical_runner toneRose
```

## Components

### Training

Local or multi-GPU ASFT fine-tuning.

- [Training control plane](https://github.com/zhuchichi56/asft/blob/main/train_v2.py): Python CLI · Parses training modes and runs fine-tuning. · `train_v2.py`
- [Training launcher](https://github.com/zhuchichi56/asft/blob/main/train_v2.sh): shell script · Provides default shell invocation. · `train_v2.sh`
- [Debug training](https://github.com/zhuchichi56/asft/blob/main/dev/train_debug.py): Python CLI · Separate development training entry point. · `dev/train_debug.py`
- **User JSONL dataset**: external data · Training data is supplied outside the repository.
- [ASFT optimization](https://github.com/zhuchichi56/asft/blob/main/train_v2.py): training mode · Anchors supervised optimization with KL drift control. · `train_v2.py`
- [LoRA adapters](https://github.com/zhuchichi56/asft/blob/main/train_v2.py): adapter mode · Enables parameter-efficient updates. · `train_v2.py`
- [Dataset acquisition](https://github.com/zhuchichi56/asft/blob/main/download_data.py): Python CLI · Downloads the Hugging Face ASFT dataset. · `download_data.py`

### Runtime

Distributed and ML dependency boundary.

- **Model and tokenizer**: external model · Weights and runtime behavior come from the ML stack.
- **DeepSpeed runtime**: distributed runtime · Optional ZeRO distributed execution boundary.
- [ZeRO-2 bf16 config](https://github.com/zhuchichi56/asft/blob/main/scripts/ds_zero2_bf16.json): DeepSpeed config · `scripts/ds_zero2_bf16.json`
- [ZeRO-3 bf16 config](https://github.com/zhuchichi56/asft/blob/main/scripts/ds_zero3_bf16.json): DeepSpeed config · `scripts/ds_zero3_bf16.json`
- [ML dependencies](https://github.com/zhuchichi56/asft/blob/main/requirements.txt): Python dependencies · CUDA PyTorch and optional FlashAttention support training. · `requirements.txt`

### AlpacaEval

Vendored generation and pairwise-judging subsystem.

- [AlpacaEval workflow](https://github.com/zhuchichi56/asft/blob/main/eval/alpaca_eval_test.py): Python CLI · Runs instruction evaluation over trained checkpoints. · `eval/alpaca_eval_test.py`
- [Evaluation coordinator](https://github.com/zhuchichi56/asft/blob/main/eval/alpacaeval/src/alpaca_eval/main.py): Python module · Coordinates generation, judging, and metrics. · `eval/alpacaeval/src/alpaca_eval/main.py`
- [Decoder adapters](https://github.com/zhuchichi56/asft/blob/main/eval/alpacaeval/src/alpaca_eval/decoders/openai.py): inference adapter · Isolates provider and local inference APIs. · `eval/alpacaeval/src/alpaca_eval/decoders/openai.py`
- [Pairwise judging](https://github.com/zhuchichi56/asft/blob/main/eval/alpacaeval/src/alpaca_eval/annotators/pairwise_evaluator.py): evaluator · Converts completions into preferences. · `eval/alpacaeval/src/alpaca_eval/annotators/pairwise_evaluator.py`

### Benchmark Evaluation

Independent math and medical batch workflows.

- [Math evaluation](https://github.com/zhuchichi56/asft/blob/main/eval/math_evaluation/evaluate.py): Python CLI · Coordinates benchmark evaluation and aggregation. · `eval/math_evaluation/evaluate.py`
- [Math inference](https://github.com/zhuchichi56/asft/blob/main/eval/math_evaluation/inference.py): inference stage · Produces model outputs from benchmark inputs. · `eval/math_evaluation/inference.py`
- [Math grading](https://github.com/zhuchichi56/asft/blob/main/eval/math_evaluation/grader.py): grading stage · Parses, optionally executes, and grades answers. · `eval/math_evaluation/grader.py`
- [Medical vLLM evaluation](https://github.com/zhuchichi56/asft/blob/main/eval/medeval/vllm_medical_test.py): Python CLI · GPU-serving medical benchmark entry point. · `eval/medeval/vllm_medical_test.py`
- [Medical evaluation runner](https://github.com/zhuchichi56/asft/blob/main/eval/medeval/run_med_eval.py): Python CLI · Runs benchmark-specific medical evaluation. · `eval/medeval/run_med_eval.py`

## Connections

- Training launcher → Training control plane: launches
- Debug training → Training control plane: development alternative
- Dataset acquisition → User JSONL dataset: acquires
- User JSONL dataset → Training control plane: training input
- Model and tokenizer → Training control plane: base model
- ML dependencies → Training control plane: provides runtime
- Training control plane → ASFT optimization: selects mode
- Training control plane → LoRA adapters: optionally enables
- Training control plane → DeepSpeed runtime: optionally launches with
- ZeRO-2 bf16 config → DeepSpeed runtime: configures
- ZeRO-3 bf16 config → DeepSpeed runtime: configures
- Training control plane → AlpacaEval workflow: trained checkpoint
- AlpacaEval workflow → Evaluation coordinator: runs
- Evaluation coordinator → Decoder adapters: generates completions
- Decoder adapters → Pairwise judging: completions
- Pairwise judging → Evaluation coordinator: preferences and metrics
- Training control plane → Math evaluation: trained checkpoint
- Math evaluation → Math inference: runs
- Math inference → Math grading: candidate answers
- Math grading → Math evaluation: grades and aggregates
- Training control plane → Medical vLLM evaluation: trained checkpoint
- Medical evaluation runner → Medical vLLM evaluation: alternative workflow
