Workflow A · Qwen LoRA
Transformers 5.xThe released script trains a causal language-model objective across the formatted sequence; it does not implement completion-only masking or a held-out validation split.
A source-first engineering reference for Qwen2.5 LoRA, supervised fine-tuning, Direct Preference Optimization and ORPO. Explore isolated training stacks, data contracts, adapter outputs and detailed Python implementations using PyTorch, Hugging Face Transformers, PEFT and TRL.
SYSTEM DESIGN
The repository separates modern Qwen adapter training from a strictly pinned legacy TRL preference-optimization pipeline. They should not share one Python environment.
The released script trains a causal language-model objective across the formatted sequence; it does not implement completion-only masking or a held-out validation split.
The legacy workflow includes an optional Phi-2 path with additional CUDA and quantization prerequisites; the default path uses SmolLM-135M.
ENGINEERING CAPABILITIES
Implementation details drawn from the released Python scripts, requirements and README—not hypothetical claims about benchmark results.
A causal-language-model fine-tuning path using Qwen/Qwen2.5-0.5B-Instruct, query/value projection adapters and a dedicated modern Transformers stack.
Supervised fine-tuning using instruction/response text and a completion-only training collator in the separately pinned TRL workflow.
Pairwise preference updates using chosen/rejected responses and a frozen copy of the SFT adapter as reference.
An independent preference-optimization training route rather than a third stage after SFT and DPO.
PEFT LoRA adapters with rank 8, alpha 16 and 0.05 dropout; adapter checkpoints remain coupled to their base model.
JSONL instruction/output records for Qwen and embedded SFT/preference examples for the separate TRL workflow.
AdamW-family optimizers, configurable precision, microbatching, gradient accumulation and learning-rate schedules.
Transformers 5.x for the Qwen workflow; exact Transformers 4.40.0 / TRL 0.8.6 versions for the second path.
CPU validation and training paths, optional NVIDIA CUDA, memory-aware sequence lengths and runtime dependency checks.
Qwen LoRA output plus SFT, DPO and ORPO adapter-save routines, subject to successful execution.
Separate Python programs and Jupyter companions for inspecting and running the post-training workflow.
Syntax, data-schema and legacy sample checks documented; full training and GPU performance are not independently benchmarked.
MODEL TRAINING
The project exposes three distinct optimization concepts across two independently managed training environments.
Use Qwen2.5-0.5B-Instruct with PEFT adapters trained on an instruction/answer corpus. The model and tokenizer are downloaded from Hugging Face when not cached.
5 epochs, batch size 1, accumulation 4q_proj, v_projUse the dedicated TRL 0.8.6 interface with SmolLM-135M by default, completion-only SFT masking, and chosen/rejected response training.
| Configuration | Qwen LoRA | Legacy SFT / DPO / ORPO |
|---|---|---|
| Default pretrained model | Qwen2.5-0.5B-Instruct | SmolLM-135M |
| Framework | Transformers 5.x + PEFT | Transformers 4.40.0 + TRL 0.8.6 |
| Training objective | Causal LM on formatted prompt + answer | Completion-only SFT; DPO or ORPO preference loss |
| Sample data | 49 records documented in README; supply required JSONL | 6 SFT records + 5 preference pairs embedded in source |
| Output | Qwen adapter + tokenizer if training completes | SFT, DPO or ORPO adapters if training completes |
| Validation status | Syntax and README-described dataset checks; no published full-training benchmark | Embedded example validation; no published full-training benchmark |
RUN THE CODE
Use two Python 3.12 environments. The checked-in Qwen script is qwen_alien_romulus_finetune_fixed.py; the legacy script is LLM_Training_Fixed_v2.py.
git clone https://github.com/su394611-del/Pre-training-and-Fine-tuning.git
cd Pre-training-and-Fine-tuning
py -3.12 -m venv .venv-qwen
.\.venv-qwen\Scripts\python.exe -m pip install --upgrade pip
.\.venv-qwen\Scripts\python.exe -m pip install -r requirements.txt
.\.venv-qwen\Scripts\python.exe -m pip check# The script expects: .\data\alien_romulus_qa.jsonl
# Inspect data.zip and supply the required JSONL file at that path.
# Each line needs nonempty instruction and output fields.
New-Item -ItemType Directory -Force .\data
# Once the JSONL file is in place, run:
.\.venv-qwen\Scripts\python.exe qwen_alien_romulus_finetune_fixed.py# Run in a new terminal from the repository root.
py -3.12 -m venv .venv-trl
.\.venv-trl\Scripts\python.exe -m pip install --upgrade pip
.\.venv-trl\Scripts\python.exe -m pip install -r requirements_legacy_llm_v2.txt
.\.venv-trl\Scripts\python.exe LLM_Training_Fixed_v2.py --mode validate
.\.venv-trl\Scripts\python.exe LLM_Training_Fixed_v2.py --mode check# Option A: SFT, then DPO (same legacy environment)
.\.venv-trl\Scripts\python.exe LLM_Training_Fixed_v2.py --mode sft-dpo
# Option B: ORPO as a separate experiment
.\.venv-trl\Scripts\python.exe LLM_Training_Fixed_v2.py --mode orpoSOURCE & DOCUMENTATION
Direct links to the exact source files, environment specifications and project documentation.