← Back to all products
$59
Fine-Tuning Pipeline
LoRA/QLoRA fine-tuning scripts, dataset preparation tools, training monitoring, model merging, and deployment automation.
MarkdownYAMLPythonLLMOpenAI
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 40 files
fine-tuning-pipeline/
├── LICENSE
├── README.md
├── configs/
│ ├── lora_config.yaml
│ ├── qlora_config.yaml
│ └── training_profiles.yaml
├── data/
│ ├── sample_conversations.jsonl
│ └── sample_instructions.jsonl
├── free-sample.zip
├── guide/
│ ├── 01-data-preparation.md
│ ├── 02-hyperparameter-tuning.md
│ └── 03-lora-explained.md
├── guides/
│ ├── data-preparation.md
│ ├── hyperparameter-tuning.md
│ └── lora-explained.md
├── index.html
├── requirements.txt
├── scripts/
│ ├── __pycache__/
│ │ ├── merge_and_export.cpython-312.pyc
│ │ ├── prepare_dataset.cpython-312.pyc
│ │ └── run_training.cpython-312.pyc
│ ├── merge_and_export.py
│ ├── prepare_dataset.py
│ └── run_training.py
└── src/
├── __init__.py
├── __pycache__/
│ ├── __init__.cpython-312.pyc
│ ├── dataset_preparation.cpython-312.pyc
│ ├── evaluation_hooks.cpython-312.pyc
│ ├── export_deploy.cpython-312.pyc
│ ├── instruction_templates.cpython-312.pyc
│ ├── lora_trainer.cpython-312.pyc
│ ├── model_merger.cpython-312.pyc
│ ├── training_config.cpython-312.pyc
│ └── training_monitor.cpython-312.pyc
├── dataset_preparation.py
├── evaluation_hooks.py
├── export_deploy.py
├── instruction_templates.py
├── lora_trainer.py
├── model_merger.py
├── training_config.py
└── training_monitor.py
📖 Documentation Preview README excerpt
Fine-Tuning Pipeline
End-to-end LoRA/QLoRA fine-tuning toolkit for large language models.
From raw data to deployment-ready model in a single pipeline: dataset preparation, instruction templating, training orchestration, monitoring, adapter merging, and export to GGUF/SafeTensors.
What You Get
- Dataset preparation engine with auto-format detection (Alpaca, OpenAI, ShareGPT, Q&A), deduplication, quality scoring, and train/val splitting
- 8 instruction templates (Alpaca, ChatML, Llama2, Llama3, Mistral, Phi3, Zephyr, Raw) with correct loss masking so the model learns to generate responses, not parrot instructions
- YAML-driven training config with pre-built profiles (quick test, small dataset, large dataset, code generation) and CLI override support
- LoRA/QLoRA trainer that wraps HuggingFace Transformers + PEFT with one-command training, automatic tokenizer setup, and gradient checkpointing
- Training monitor with anomaly detection: NaN loss, loss spikes, plateau detection, overfitting alerts, and crash-safe JSONL logging
- Model merger supporting single-adapter merge plus multi-adapter strategies (Linear, TIES, DARE) for combining task-specific adapters
- Adapter registry for tracking trained adapters with metadata, metrics, and base model compatibility
- Export automation for GGUF (llama.cpp/Ollama), SafeTensors (vLLM/TGI), with auto-generated Modelfiles, model cards, and inference configs
- Evaluation hooks for exact match, instruction following, safety regression, and text quality during training
- Three deep-dive guides covering data preparation, LoRA mechanics, and hyperparameter tuning
File Tree
fine-tuning-pipeline/
├── README.md
├── LICENSE
├── requirements.txt
├── src/
│ ├── __init__.py
│ ├── dataset_preparation.py # Load, dedup, filter, split, export
│ ├── instruction_templates.py # 8 prompt format templates with loss masking
│ ├── training_config.py # YAML config management with validation
│ ├── lora_trainer.py # LoRA/QLoRA training orchestration
│ ├── training_monitor.py # Loss tracking, anomaly detection, reporting
│ ├── model_merger.py # Adapter merging (Linear/TIES/DARE) + registry
│ ├── evaluation_hooks.py # In-training eval: exact match, safety, quality
│ └── export_deploy.py # GGUF/SafeTensors export + model cards
├── configs/
│ ├── lora_config.yaml # Standard LoRA training config
│ ├── qlora_config.yaml # QLoRA 4-bit optimized config
│ └── training_profiles.yaml # Quick-start presets by task type
├── scripts/
│ ├── prepare_dataset.py # CLI: dataset preparation
│ ├── run_training.py # CLI: launch training with config + overrides
│ └── merge_and_export.py # CLI: merge adapters and export models
├── data/
│ ├── sample_instructions.jsonl # 8 sample instruction-tuning examples
│ └── sample_conversations.jsonl # 4 sample multi-turn conversations
└── guides/
├── data-preparation.md # Dataset quality, formats, sizing
├── lora-explained.md # LoRA/QLoRA mechanics deep dive
└── hyperparameter-tuning.md # Tuning guide with decision trees
Quick Start
1. Install Dependencies
*... continues with setup instructions, usage examples, and more.*
📄 Code Sample .py preview
src/dataset_preparation.py
"""
Dataset Preparation — Fine-Tuning Pipeline
============================================
Handles the full data lifecycle before training: loading raw datasets,
deduplication, quality filtering, train/validation splitting, and
conversion to the JSONL format that the trainer expects.
The key insight behind good fine-tuning data is that quality beats quantity.
A 500-example dataset of expertly curated instruction-response pairs will
outperform 50,000 noisy scraped examples. This module enforces that by
providing dedup, length filters, and quality heuristics out of the box.
"""
from __future__ import annotations
import hashlib
import json
import logging
import os
import random
import re
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple
logger = logging.getLogger(__name__)
# ---------------------------------------------------------------------------
# Quality thresholds — tune these for your domain
# ---------------------------------------------------------------------------
MIN_INSTRUCTION_CHARS = 10 # Below this, the instruction is too vague
MAX_INSTRUCTION_CHARS = 4096 # Above this, the instruction is likely pasted junk
MIN_RESPONSE_CHARS = 20 # One-word answers rarely teach the model anything
MAX_RESPONSE_CHARS = 16384 # Cap to avoid runaway context lengths
MIN_QUALITY_SCORE = 0.3 # Composite heuristic score (0.0–1.0)
@dataclass
class DatasetStats:
"""Tracks what happened during dataset preparation for auditability."""
total_loaded: int = 0
duplicates_removed: int = 0
too_short_removed: int = 0
too_long_removed: int = 0
low_quality_removed: int = 0
custom_filter_removed: int = 0
final_count: int = 0
train_count: int = 0
# ... 486 more lines ...