Generate a complete QLoRA fine-tuning script with dataset preparation, training loop, evaluation, and model merging.
You are an ML engineer specializing in LLM fine-tuning. Generate a complete QLoRA fine-tuning pipeline. ## Configuration - **Base Model**: [BASE_MODEL e.g. meta-llama/Llama-4-8B-Instruct] - **Dataset**: [DATASET e.g. custom JSONL with instruction/response pairs] - **Task**: [TASK e.g. code generation / medical QA / legal summarization] - **Hardware**: [HARDWARE e.g. single A100 80GB / 2x RTX 4090 / 4x H100] - **Quantization**: [QUANT e.g. 4-bit NF4 / 8-bit] - **Max Sequence Length**: [MAX_SEQ e.g. 4096] ## Required Components ### 1. Dataset Preparation (`prepare_data.py`) - Load [DATASET] and convert to chat template format - Apply [BASE_MODEL] tokenizer with proper special tokens - Implement train/val/test split (80/10/10) - Add data quality filters: remove duplicates, check token counts - Save as HuggingFace Dataset with push_to_hub option ### 2. Training Script (`train.py`) - Load [BASE_MODEL] with BitsAndBytes [QUANT] quantization - Configure LoRA: r=[LORA_R e.g. 64], alpha=[LORA_ALPHA e.g. 128], target_modules=[TARGETS e.g. q_proj,k_proj,v_proj,o_proj,gate_proj,up_proj,down_proj] - Set training hyperparameters: - Learning rate: [LR e.g. 2e-4] with cosine scheduler - Batch size: [BATCH e.g. 4] with gradient accumulation [GRAD_ACCUM e.g. 8] - Epochs: [EPOCHS e.g. 3] - Warmup ratio: 0.03 - Weight decay: 0.01 - Enable gradient checkpointing for memory efficiency - Use SFTTrainer from trl library - Add Weights & Biases logging - Save checkpoints every [SAVE_STEPS e.g. 100] steps ### 3. Evaluation (`evaluate.py`) - Run inference on test set with temperature=0 - Calculate task-specific metrics for [TASK] - Generate comparison report: base model vs fine-tuned - Include perplexity, BLEU/ROUGE scores, and custom metrics ### 4. Model Merging (`merge_and_export.py`) - Merge LoRA adapters back into base model - Save in safetensors format - Convert to GGUF for llama.cpp deployment - Push merged model to HuggingFace Hub ### 5. Configuration (`config.yaml`) - All hyperparameters in a single YAML config - Environment-specific overrides Include shell scripts for single-GPU and multi-GPU (DeepSpeed ZeRO-3) training. Add requirements.txt with exact versions.
Free to copy and use. Compatible with Claude 4 Opus, GPT-5, Gemini 2.5 Pro, Llama 4 Maverick.
Replace all parameters with your specific model, dataset, and hardware details. Run prepare_data.py first, then train.py. Monitor loss curves in W&B dashboard.
Initial release
Sign in and download this prompt to leave a review.