How zhuchichi56/asft works
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 Training control plane · main.py Evaluation coordinator · evaluate.py Math evaluation · alpaca_eval_test.py AlpacaEval workflow
Components 21
Training
Local or multi-GPU ASFT fine-tuning.
- Training control plane · Parses training modes and runs fine-tuning.
train_v2.py - Training launcher · Provides default shell invocation.
train_v2.sh - Debug training · Separate development training entry point.
dev/train_debug.py - User JSONL dataset · Training data is supplied outside the repository.
- ASFT optimization · Anchors supervised optimization with KL drift control.
train_v2.py - LoRA adapters · Enables parameter-efficient updates.
train_v2.py - Dataset acquisition · Downloads the Hugging Face ASFT dataset.
download_data.py
Runtime
Distributed and ML dependency boundary.
- Model and tokenizer · Weights and runtime behavior come from the ML stack.
- DeepSpeed runtime · Optional ZeRO distributed execution boundary.
- ZeRO-2 bf16 config
scripts/ds_zero2_bf16.json - ZeRO-3 bf16 config
scripts/ds_zero3_bf16.json - ML dependencies · CUDA PyTorch and optional FlashAttention support training.
requirements.txt
AlpacaEval
Vendored generation and pairwise-judging subsystem.
- AlpacaEval workflow · Runs instruction evaluation over trained checkpoints.
eval/alpaca_eval_test.py - Evaluation coordinator · Coordinates generation, judging, and metrics.
eval/alpacaeval/src/alpaca_eval/main.py - Decoder adapters · Isolates provider and local inference APIs.
eval/alpacaeval/src/alpaca_eval/decoders/openai.py - Pairwise judging · Converts completions into preferences.
eval/alpacaeval/src/alpaca_eval/annotators/pairwise_evaluator.py
Benchmark Evaluation
Independent math and medical batch workflows.
- Math evaluation · Coordinates benchmark evaluation and aggregation.
eval/math_evaluation/evaluate.py - Math inference · Produces model outputs from benchmark inputs.
eval/math_evaluation/inference.py - Math grading · Parses, optionally executes, and grades answers.
eval/math_evaluation/grader.py - Medical vLLM evaluation · GPU-serving medical benchmark entry point.
eval/medeval/vllm_medical_test.py - Medical evaluation runner · Runs benchmark-specific medical evaluation.
eval/medeval/run_med_eval.py
Connections 22
- 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