scieee AI-readable full text Open interactive document viewer

Software and Dataset For Fine-Tuning a local LLM for Thermo-Electric Generators with QLoRA: from generalist to specialist

Monzón-Verona, José Miguel; García-Alonso, Santiago; Santana-Martín, Francisco Jorge

Abstract

This document provides a comprehensive guide to the software and datasets contained inthis repository. These resources were developed for the research presented in the article: "[Ar-ticle Title Fine-Tuning a local LLM for Thermo-Electric Generators with QLoRA: from gener-alist to specialist:;Preprinthttps://www.preprints.org/manuscript/202511.1348 ]". This work presents a complete pipeline for transforming general-purposeLarge Language Models (LLMs) into specialized technical assistants for thermoelectric genera-tor (TEG) applications. Using QLoRA (Quantized Low-Rank Adaptation), we eciently ne-tuned two open-source modelsJanV1-expert-TEG and Qwen3-4B-thinking-2507-TEG on acurated dataset of 202 question-answer pairs covering thermoelectric materials, device physics,performance optimization, and engineering applications. The methodology enables special-ization without full model retraining, signicantly reducing computational requirements whilemaintaining technical accuracy. We introduce a novel evaluation framework combining humanexpert review with LLM-as-a-Judge scoring using state-of-the-art models (GPT-4, Gemini 1.5Pro). The resulting specialist models demonstrate enhanced performance on technical queries,achieving higher relevance and accuracy scores compared to their base counterparts. All re-sources, including trained adapters, merged models, training scripts, and evaluation datasets,are provided for reproducibility and further research in domain-specic AI applications forrenewable energy technologies.

Full text

Software and Dataset For Fine-Tuning a local LLM for Thermo-Electric Generators with QLoRA: from generalist to specialist José Miguel Monzón-Verona, Santiago García-Alonso, and Francisco Jorge Santana-Martín November 9, 2025 Abstract This document provides a comprehensive guide to the software and datasets contained in this repository. These resources were developed for the research presented in the article: "[Article Title Fine-Tuning a local LLM for Thermo-Electric Generators with QLoRA: from generalist to specialist]" . This work presents a complete pipeline for transforming general-purpose Large Language Models (LLMs) into specialized technical assistants for thermoelectric generator (TEG) applications. Using QLoRA (Quantized Low-Rank Adaptation), we eciently netuned two open-source models JanV1-expert-TEG and Qwen3-4B-thinking-2507-TEG on a curated dataset of 202 question-answer pairs covering thermoelectric materials, device physics, performance optimization, and engineering applications. The methodology enables specialization without full model retraining, signicantly reducing computational requirements while maintaining technical accuracy. We introduce a novel evaluation framework combining human expert review with LLM-as-a-Judge scoring using state-of-the-art models (GPT-4, Gemini 1.5 Pro). The resulting specialist models demonstrate enhanced performance on technical queries, achieving higher relevance and accuracy scores compared to their base counterparts. All resources, including trained adapters, merged models, training scripts, and evaluation datasets, are provided for reproducibility and further research in domain-specic AI applications for renewable energy technologies. 1 Repository Description This repository contains all materials required to reproduce the ne-tuning process and evaluation of specialized LLMs for thermoelectric generator applications. The pipeline transforms generalist models into technical experts using ecient quantization and adaptation techniques. 2 Repository Structure .JanV1-expert-TEG/ # Fine-tuned JanV1-4B model gguf/ # Quantized GGUF version Qwen3-4B-thinking-2507-TEG/ # Fine-tuned Qwen3 model gguf/ 1 inference_tests/ # Evaluation datasets 16_advanced_questions.json # High-level technical questions 42_general_questions.json # General thermoelectric questions 202_questions_train/ # Training resources train.py # Training script with QLoRA dataset_v4_improved.json # 202 Q&A training pairs assets/ fine_tuning_pipeline.png # Methodology diagram 3 Methodology: QLoRA Fine-Tuning Pipeline 3.1 Overview The ne-tuning process follows a 4-phase architecture (see Figure 1) that enables ecient specialization while preserving the base model's general capabilities. 3.2 Phase 1: Preparation & Fine-Tuning (The Specialist's Workshop) In this initial phase, we prepare the domain-specic dataset and train a small, ecient adapter using QLoRA:  Dataset Curation : 202 expert-level question-answer pairs covering thermoelectric theory, material science (Seebeck coecient, gure of merit ZT ), device engineering, and applications.  Base Model : We start from janhq/Jan-v1-4B and Qwen3-4B-thinking-2507 as foundation models.  QLoRA Conguration :  4-bit quantization of the base model (NF4 type)  LoRA rank = 64, alpha = 128  Target modules: q_proj , v_proj , k_proj , o_proj  Learning rate: 2e-4 with linear warmup  Training : The train.py script executes ne-tuning for 15 epochs with batch size 4, saving only the adapter weights ( 50 MB) without modifying the 4B parameter base model. 3.3 Phase 2: Consolidation & Optimization (The Production Furnace) The trained adapter is merged into a deployable format: 1. Adapter Merging : Using merge.py , the LoRA adapter is baked into a copy of the base model, creating a standalone Hugging Face model ( merged_model/ ). 2. GGUF Conversion : The merged model is quantized to 4-bit GGUF format via llama.cpp for ecient CPU/GPU inference, reducing memory usage by 75% while maintaining 98% of performance. 3. Ollama Integration : The GGUF model is registered in Ollama's model library using ollama create , enabling simple deployment with ollama run JanV1-expert-TEG . 2 3.4 Phase 3: Deployment & Serving (Go-Live) The optimized models are served through:  Local Ollama server for API access  Direct Hugging Face Transformers inference  Quantized versions for resource-constrained environments 3.5 Phase 4: Usage & Evaluation (Advanced Quality Control) We implemented a two-tier evaluation system: 1. LLM-as-a-Judge : Using GPT-4 and Gemini 1.5 Pro to score responses on:  Technical accuracy (0-10)  Response coherence (0-10)  Domain relevance (0-10)  Completeness of explanation (0-10) 2. Human Expert Review : Domain specialists validate 58 test questions (16 advanced + 42 general) against reference answers, focusing on:  Correctness of physical principles  Appropriate use of equations and units  Practical engineering applicability Figure 1: Four-phase QLoRA ne-tuning pipeline for TEG specialization 3 Model JanV1-expert-TEG Qwen3-4B-thinking-2507-TEG Base Model Jan-v1-4B Qwen3-4B-thinking-2505 Parameters 4 Billion 4 Billion Adapter Size 3.18% of 4.3 GB 3.18% of 4,3GB GGUF Size 4.3GB 4.3 GB Context Length 2048 tokens 2048 tokens Specialization TEG Materials & Devices TEG Materials & Devices Table 1: Model specications and le sizes 4 Model Specications 5 Installation & Usage 5.1 Requirements  Python 3.10+  CUDA 12.1+ (for GPU training)  16 GB RAM minimum (8 GB for inference only)  Ollama (optional, for serving) 5.2 Installation # Install dependencies pip install ollama # For GGUF inference docker exec ollama ollama create janV1 -4 B - expert - TEG -f / JanV1 - expert - TEG / gguf / Modelfile . termo - expert docker exec ollama ollama list docker exec - it ollama ollama run janV1 -4 B - expert - TEG 5.3 Running Inference # Option 1: Using Ollama (recommended) ollama run ./JanV1 -expert -TEG/gguf/modelfile # Option 2: Using Hugging Face python inference.py --model JanV1 -expert -TEG/merged_model --prompt "What is the optimal doping concentration for Bi2Te3 at 300K?" 4 5.4 Reproducing Fine-Tuning cd 202 _questions_train python train . py python merge_unsloth 6 Datasets 6.1 Training Dataset - File : 202_questions_train/dataset_v4_improved.json - Size : 202 Q&A pairs - Coverage : Thermoelectric eects, materials (Bi 2 Te 3 , PbTe, SiGe), device physics, eciency calculations, module design 6.2 Evaluation Datasets - Advanced : 16 questions on Seebeck coecient optimization, thermal conductivity trade-os, and multi-physics modeling - General : 42 questions covering basic principles, material selection criteria, and performance metrics 5 7 Evaluation Results Figure 2: Summary and evaluation of the responses of LLMs 8 Citation If you use this work, please cite: @software{teg_llm_finetuning_2025, title = {Fine-Tuning a local LLM for Thermo-Electric Generators with QLoRA: from generalist to specialist}, author = {José Miguel Monzón-Verona, Santiago García-Alonso, and Francisco Jorge Santana-Martín}]}, year = {2025}, publisher = {MDPI: Applied Sciences}, doi = {}, url = {https://} } 9 License This repository is released under the MIT License. The ne-tuned models follow the original licenses of their base models (Apache 2.0 for Jan-v1-4B, Qwen License for Qwen3). 6