Downloads · 30 days
8
14% of all-time downloads
ash270/tinyllama-ai-ml-tutor-qlora
tinyllama-ai-ml-tutor-qlora is a text generation model from ash270. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
A QLoRA fine-tuned adapter for TinyLlama-1.1B-Chat-v1.0 that specializes it into an AI/ML tutor — it answers conceptual, "why", "how", comparison, code, debugging, math, interview, and real-world questions about machi…
Downloads · 30 days
8
14% of all-time downloads
All-time downloads
58
Public
Repo size
9.5 MB
Likes
0
Public
Click a slice to open those files.
.safetensors9 MB · 69%
From the Hugging Face model README
A QLoRA fine-tuned adapter for TinyLlama-1.1B-Chat-v1.0 that specializes it into an AI/ML tutor — it answers conceptual, "why", "how", comparison, code, debugging, math, interview, and real-world questions about machine learning, PyTorch, and Transformers, in a consistent, structured teaching format (Definition → Why It Matters → Intuition → Example → Key Points → Summary).
This is a LoRA adapter (not a full model) trained on top of TinyLlama/TinyLlama-1.1B-Chat-v1.0 using QLoRA (4-bit NF4 quantized base + LoRA adapters) and Hugging Face's SFTTrainer (TRL). It was trained on 2,000 synthetically generated AI/ML tutor Q&A examples covering topics like Self-Attention, Gradient Descent, PyTorch Autograd, LoRA, and QLoRA itself. The goal was not to expand the model's general knowledge, but to make its explanations of AI/ML topics consistently structured and teaching-oriented, compared to the base model's more generic, sometimes factually inconsistent answers.
src/api/) that serves base vs. fine-tuned answers side by side (uvicorn src.api.main:app --reload, then GET /chat?q=...)Ask the model AI/ML conceptual questions (e.g. "What is self-attention?", "Why does QLoRA use 4-bit quantization?", "Debug this PyTorch autograd error") and receive a structured, tutor-style explanation. Well suited for learners who want consistent, scaffolded explanations rather than open-ended chat.
Could be embedded as the explanation engine behind an educational chatbot, a study-assistant app, or a lightweight local tutoring tool where compute is constrained (the 1.1B base + 4-bit quantization make it runnable on modest/free-tier GPUs).
llama-3.1-8b-instant), so the model can inherit that generator's inaccuracies, oversimplifications, or repetitive phrasing.Users (both direct and downstream) should treat this as an educational aid for a narrow set of AI/ML topics, not an authoritative source — verify important technical claims against primary references (papers, official docs). Be aware the model may confidently state incorrect information, especially outside its trained topic set.
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel
import torch
base_model_id = "TinyLlama/TinyLlama-1.1B-Chat-v1.0"
adapter_id = "ash270/tinyllama-ai-ml-tutor-qlora"
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
)
tokenizer = AutoTokenizer.from_pretrained(adapter_id)
base_model = AutoModelForCausalLM.from_pretrained(
base_model_id, quantization_config=bnb_config, device_map="auto"
)
model = PeftModel.from_pretrained(base_model, adapter_id)
model.eval()
messages = [{"role": "user", "content": "Explain the bias-variance tradeoff simply."}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
with torch.no_grad():
output = model.generate(**inputs, max_new_tokens=300, temperature=0.7, do_sample=True)
input_len = inputs["input_ids"].shape[1]
print(tokenizer.decode(output[0][input_len:], skip_special_tokens=True))
2,000 synthetically generated AI/ML tutor Q&A examples, created by prompting Groq's llama-3.1-8b-instant (OpenAI-compatible API) to produce one example at a time, cycling through:
Each generated example was required to follow the target teaching structure (Definition → Why It Matters → Intuition → Example → Key Points → Summary) and was validated (single user/assistant turn, ≥100-character answer) before being kept. Data was split 80/10/10 (seed=40): 1,600 train / 200 validation / 200 test.
Metadata columns (id, topic, domain, category, difficulty) were dropped, keeping only the messages field, which was formatted using the tokenizer's chat template (apply_chat_template).
load_in_4bit=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.float16, bnb_4bit_use_double_quant=Truer=8, lora_alpha=16, target_modules=["q_proj","k_proj","v_proj","o_proj"], lora_dropout=0.05, bias="none", task_type="CAUSAL_LM"paged_adamw_8bittrl.SFTTrainer, evaluated/saved every epoch with load_best_model_at_end=True (metric: eval_loss)Training ran for the full 3 epochs (1,365 steps total); the best checkpoint by eval_loss was the final one (checkpoint-1365). Exact wall-clock time and hardware were not logged in the repository — recommend adding these if you have them (e.g. from your Colab session).
200 held-out test examples (data/raw/test.jsonl), drawn from the same synthetic generation pipeline and topic/question-type distribution as the training data, not used during training.
Evaluation was disaggregated informally by topic (Self-Attention, Gradient Descent, Autograd, LoRA, QLoRA) and question type (concept, why, how, comparison, code, debugging, mathematics, interview, real_world) via qualitative inspection of evaluation/result.jsonl, rather than a formal per-factor breakdown.
SFTTrainer.evaluation/result.jsonl), generated with max_new_tokens=300, temperature=0.7, sampling enabled — inspected for response structure, topical grounding, and adherence to the target teaching format.| Metric (best checkpoint, step 1365 / epoch 3) | Value |
|---|---|
| Evaluation loss | 0.625 |
| Evaluation mean token accuracy | 0.820 |
| Train loss (final logged step) | ~0.60 |
| Train mean token accuracy (final logged step) | ~0.82 |
Qualitatively, the fine-tuned model reliably follows the Definition → Why It Matters → Intuition → Example → Key Points → Summary structure on held-out questions, while the base model produces more generic, less consistently structured, and occasionally factually incorrect answers (e.g. the base model, unprompted, misdefined "QLoRA" as "Quantized Logistic Regression").
Fine-tuning measurably improved token-level prediction accuracy on held-out AI/ML tutoring data (eval loss 0.625, eval token accuracy ~82%) and, qualitatively, made responses far more structured and topically grounded than the base model. No formal automatic quality benchmark (e.g. ROUGE, human preference scoring) has been run yet — this is planned future work.
Not performed. No interpretability analysis (attention visualization, probing, etc.) has been done on this adapter.
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
LoRA adapter (rank 8, alpha 16, targeting q_proj/k_proj/v_proj/o_proj) applied to TinyLlama/TinyLlama-1.1B-Chat-v1.0, a Llama-architecture decoder-only transformer, trained with a standard causal language modeling (next-token prediction) objective via supervised fine-tuning (SFT) on chat-formatted instruction/response pairs.
Not precisely logged; training was run via a Colab notebook (notebooks/run_pipeline.ipynb). Fill in the specific GPU (e.g. T4, A100) if known.
transformers==4.51peft==0.16.0trl==0.19.1accelerate==1.8.1bitsandbytes==0.46.1datasets==3.6.0sentencepieceopenai (used for the Groq-based synthetic data generation step)BibTeX:
@misc{jha2025tinyllamaaimltutor,
author = {Ashish Kumar Jha},
title = {TinyLlama AI/ML Tutor: A QLoRA Fine-Tuned Adapter for AI/ML Education},
year = {2025},
publisher = {Hugging Face},
howpublished = {\url{https://huggingface.co/ash270/tinyllama-ai-ml-tutor-qlora}}
}
APA:
Jha, A. K. (2025). TinyLlama AI/ML Tutor: A QLoRA fine-tuned adapter for AI/ML education [LoRA adapter]. Hugging Face. https://huggingface.co/ash270/tinyllama-ai-ml-tutor-qlora
See the full training pipeline, dataset generation code, evaluation results, and a FastAPI comparison demo in the GitHub repository.
Ashish Kumar Jha (@Ash8389 / @ash270)
Open an issue on the GitHub repository or reach out via Hugging Face: @ash270