AI / MLCompleted2 min read

MentorAI Fine-Tuning Pipeline

LLM Engineering

MentorAI Fine-Tuning Pipeline

Overview

The MentorAI Fine-Tuning Pipeline is a standalone Python package (mentorai-finetuning) providing a reproducible pipeline for adapting Qwen2.5-0.5B/7B-Instruct to domain-specific tasks. It supports SFT, LoRA, and QLoRA via a unified CLI (mentorai-cli) with hardware-aware auto-planning that detects available GPU/CPU resources. The pipeline handles dataset engineering (Alpaca, ChatML, ShareGPT formats), tokenization, training with PEFT + TRL + Accelerate, and evaluation using ROUGE, BLEU, BERTScore, sacrebleu, and LLM-as-Judge. Training is tracked with MLflow. Adapters are merged and exported as Safetensors, served via a FastAPI inference server that feeds MentorAI's RAG pipeline.

Problem & Solution

The Problem

No reusable, production-ready pipeline exists for fine-tuning open-source LLMs on domain-specific data — every project starts from scratch.

The Solution

Standalone Python package (mentorai-finetuning) with CLI that automates the full cycle: raw documents → knowledge extraction → instruction dataset → QLoRA/LoRA fine-tuning → adapter merge → evaluation → FastAPI inference.

Architecture & Dataflow

Pipeline Architecture
Raw Documents → Knowledge Extraction → Dataset Engineering (Alpaca/ChatML/ShareGPT) → Tokenization → SFT → LoRA → QLoRA (4-bit) → Evaluation (ROUGE/BLEU/BERTScore/LLM-as-Judge) → Adapter Merge → Safetensors Export → FastAPI Inference

Technical Stack & Implementation

AI / ML & Models

  • Qwen2.5-0.5B/7B-Instruct
  • PyTorch
  • HuggingFace Transformers
  • PEFT / QLoRA / LoRA
  • TRL
  • BitsAndBytes
  • Accelerate
  • MLflow

Backend & APIs

  • FastAPI
  • Python
  • mentorai-cli

Data & Storage

  • Datasets (HuggingFace)
  • Pandas

DevOps & Infra

  • Docker
  • CUDA

Technical Challenges & Solutions

01

Generating high-quality instruction-answer pairs from raw domain documents

02

Preventing catastrophic forgetting while improving domain performance on a 0.5B model

03

Hardware-aware auto-planning that gracefully handles varying GPU memory constraints

Key Highlights & Results

Trained QLoRA adapters for Qwen2.5-0.5B/7B with full evaluation metrics

CLI reduces manual fine-tuning setup from days to a single command

Inference server integrates directly with MentorAI's RAG pipeline

Standalone Python package (mentorai-finetuning) with unified CLI
Hardware-aware auto-planning (detects GPU/CPU, optimizes batch size)
SFT / LoRA / QLoRA fine-tuning with 4-bit quantization via BitsAndBytes
Dataset engineering: Alpaca, ChatML, ShareGPT format support
Evaluation suite: ROUGE, BLEU, BERTScore, sacrebleu, LLM-as-Judge
MLflow experiment tracking and model registry
Adapter merge and Safetensors export for production deployment
FastAPI inference server for real-time serving