--- base_model: Qwen/Qwen3.5-4B library_name: peft pipeline_tag: text-generation tags: - base_model:adapter:Qwen/Qwen3.5-4B - lora - sft - transformers - trl - unsloth license: apache-2.0 datasets: - thisisandreeeee/simple-llm-sft --- # Simple LLM — Qwen3.5-4B SFT This repository contains a LoRA adapter for [`Qwen/Qwen3.5-4B`](https://huggingface.co/Qwen/Qwen3.5-4B). It was trained to make technical answers simpler while preserving correctness. The target style uses shorter sentences, common words, active voice, and one main idea per sentence. Necessary technical terms, code, commands, and factual detail should remain unchanged. ## Intended use Use this adapter to generate or rewrite technical explanations, documentation, procedures, runbooks, and similar material in clearer English. This is an experimental style adapter. It does not make the base model more factually reliable. Check generated code, commands, security advice, and other high-impact content before use. The adapter was evaluated on English technical prompts and is not validated for other languages or domains. ## Base model [`Qwen/Qwen3.5-4B`](https://huggingface.co/Qwen/Qwen3.5-4B) ## Dataset [`thisisandreeeee/simple-llm-sft`](https://huggingface.co/datasets/thisisandreeeee/simple-llm-sft) - 901 training examples - 99 validation examples - 100 separate holdout prompts for the reported evaluation - Deterministic, subject-stratified split with seed 42 Each SFT example contains one user message and one assistant message. The user message is context, but loss is computed only on assistant tokens. Qwen3.5 thinking is disabled in the chat template. The dataset construction is implemented in [`simple_llm/sft_dataset.py`](https://github.com/thisisandreeeee/simple-llm/blob/00c0e5b32ef64038a49a5527ee0fd13d19faf3f2/simple_llm/sft_dataset.py). ## Training We selected Qwen3.5-4B because it is small enough to fine-tune cheaply while remaining useful for technical questions. Training used Unsloth and TRL supervised fine-tuning with completion-only loss. The base model was frozen. Only LoRA adapters on the attention and MLP projection layers were trained. The model fit on an NVIDIA L4 at bf16, so the run did not use QLoRA or 4-bit model quantization. | Setting | Value | | ----------------------- | --------------------------------------------------------------------------- | | Method | Supervised fine-tuning | | PEFT method | LoRA | | LoRA rank | 16 | | LoRA alpha | 16 | | LoRA dropout | 0 | | Target modules | `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj` | | Precision | bf16 | | Epochs | 2 | | Per-device batch size | 2 | | Gradient accumulation | 4 | | Effective batch size | 8 | | Learning rate | 1e-4 | | Warmup ratio | 0.05 | | Optimizer | 8-bit AdamW | | LR schedule | Linear | | Weight decay | 0.01 | | Maximum sequence length | 2,048 tokens | | Seed | 42 | | Validation | Every 25 steps; restore the checkpoint with the lowest validation loss | The complete training entry point and pinned runtime packages are in [`simple_llm/sft_training.py`](https://github.com/thisisandreeeee/simple-llm/blob/00c0e5b32ef64038a49a5527ee0fd13d19faf3f2/simple_llm/sft_training.py). ## Hardware Training ran on one NVIDIA L4 through Modal. Modal also hosted evaluation and inference. ## Evaluation We evaluated 100 held-out technical prompts across ten domains. The comparison covered the raw base model, the base model with a Simple English system prompt, and the SFT adapter. DeepSeek judged technical adequacy, task fulfillment, clarity, and semantic simplicity on a 0–1 scale. Separate deterministic rules measured style properties. | Condition | Mean sentence length ↓ | Long-sentence fraction ↓ | Semantic simplicity ↑ | Technical adequacy ↑ | | ---------------------------- | ---------------------: | -----------------------: | --------------------: | -------------------: | | Qwen3.5-4B base | 17.93 | 25.44% | 0.658 | 0.683 | | Base + Simple English prompt | **11.15** | **4.22%** | 0.748 | 0.592 | | Qwen3.5-4B SFT | 15.37 | 15.76% | **0.792** | **0.719** | The SFT run improved semantic simplicity and technical adequacy over both comparators in this evaluation. The prompt-only condition produced the shortest sentences, but it also had the lowest technical adequacy score. These results are directional, not a general benchmark. Conditions did not use identical decoding: the two baselines used greedy decoding, while SFT used sampling with temperature 0.7, top-p 0.8, and top-k 20. Two base outputs and two SFT outputs were truncated and excluded from applicable score means. Some judge requests also failed, so judge means can cover slightly different subsets. For this benchmark, the adapter contribution was scaled to 0.25 and then merged into the base model. The published adapter stores its original weights, so loading it at the default scale will not exactly reproduce the table. See the [inference implementation](https://github.com/thisisandreeeee/simple-llm/blob/45c3f7b324de5643aa4bea35a76f6c437d7108a4/simple_llm/modal_inference.py) and the following experiment entry points: - [Base model](https://github.com/thisisandreeeee/simple-llm/blob/45c3f7b324de5643aa4bea35a76f6c437d7108a4/experiments/03_qwen35_4b_base.py) - [Prompt engineering](https://github.com/thisisandreeeee/simple-llm/blob/45c3f7b324de5643aa4bea35a76f6c437d7108a4/experiments/04_qwen35_4b_sysprompt.py) - [SFT adapter](https://github.com/thisisandreeeee/simple-llm/blob/45c3f7b324de5643aa4bea35a76f6c437d7108a4/experiments/05_qwen35_4b_sft.py) ## Usage Install compatible Transformers and PEFT versions, then load the adapter over the base model: ```python from peft import PeftModel from transformers import AutoModelForCausalLM, AutoTokenizer base_model_id = "Qwen/Qwen3.5-4B" adapter_id = "thisisandreeeee/simple-llm-qwen3.5-4b-sft" tokenizer = AutoTokenizer.from_pretrained(adapter_id) base_model = AutoModelForCausalLM.from_pretrained( base_model_id, torch_dtype="auto", device_map="auto", ) model = PeftModel.from_pretrained(base_model, adapter_id) messages = [ { "role": "user", "content": "Explain database indexes and their main trade-offs.", } ] inputs = tokenizer.apply_chat_template( messages, tokenize=True, add_generation_prompt=True, enable_thinking=False, return_tensors="pt", return_dict=True, ).to(model.device) outputs = model.generate( **inputs, max_new_tokens=512, temperature=0.7, top_p=0.8, top_k=20, do_sample=True, ) response = tokenizer.decode( outputs[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True, ) print(response) ``` Replace `adapter_id` if this repository is published under a different Hugging Face model ID. You can also merge the loaded adapter with `model.merge_and_unload()` for inference. ## Code and reproducibility - Repository: [`thisisandreeeee/simple-llm`](https://github.com/thisisandreeeee/simple-llm) - Training data and code revision: [`00c0e5b32ef64038a49a5527ee0fd13d19faf3f2`](https://github.com/thisisandreeeee/simple-llm/commit/00c0e5b32ef64038a49a5527ee0fd13d19faf3f2) - Evaluation revision: [`45c3f7b324de5643aa4bea35a76f6c437d7108a4`](https://github.com/thisisandreeeee/simple-llm/commit/45c3f7b324de5643aa4bea35a76f6c437d7108a4) - Training run: `qwen35-4b-sft-20260821-025306` The training workflow saves the dataset hashes, package versions, base-model revision, GPU details, and full trainer configuration with each run. ## Framework versions - Unsloth 2026.7.6 - PyTorch 2.11.0 - Transformers 5.5.0 - TRL 0.24.0 - Datasets 4.3.0 - PEFT 0.20.0