unsloth-finetuning
Skill này làm gì
Công cụ này giúp huấn luyện mô hình AI trên một máy tính với bộ nhớ video (VRAM) hạn chế. Nó giúp huấn luyện nhanh hơn và dùng ít bộ nhớ hơn, cho phép tùy chỉnh các mô hình AI trước đây chỉ có thể huấn luyện trên máy rất mạnh.
Khi nào nên dùng
- ✓Khi bạn muốn huấn luyện một mô hình AI trên máy tính của mình và VRAM bị giới hạn.
- ✓Khi một lần huấn luyện thất bại vì vấn đề bộ nhớ và bạn cần điều chỉnh.
- ✓Khi bạn muốn xuất mô hình đã huấn luyện sang một định dạng cụ thể (GGUF, vLLM).
Liên kết skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/unsloth-finetuning/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Làm sao để huấn luyện mô hình 'unsloth/Qwen3-8B' chỉ với 16GB VRAM và xuất sang định dạng GGUF?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Công cụ hoạt động bằng cách tối ưu việc dùng VRAM và thời gian huấn luyện. Nó cho phép tinh chỉnh mô hình bằng các kỹ thuật như LoRA/QLoRA và đảm bảo mô hình hiểu đúng các cuộc hội thoại trước khi xuất.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Unsloth Fine-Tuning
Overview
Unsloth trains LLMs with custom kernels that cut VRAM use and step time without changing the math, which makes single-GPU fine-tuning practical on hardware that would otherwise OOM. This skill covers Unsloth Core — the Python API — because that is what an agent can drive programmatically; the Desktop app and Studio web UI are interactive and out of scope.
The hard parts of an Unsloth run are not the training call. They are sizing the job against available VRAM, getting the chat template and loss masking right, and choosing an export format the target runtime can actually load. This skill covers those three.
When to Use This Skill
- Use when fine-tuning an LLM on one GPU and VRAM is the binding constraint.
- Use when a training run OOMs and needs to be resized rather than rewritten.
- Use when doing preference or RL post-training (GRPO, DPO) on consumer hardware.
- Use when a fine-tuned model must be exported to GGUF, vLLM, or merged 16-bit weights.
- Use when a fine-tune "ran fine" but the model's output format is wrong — usually a chat template or loss-masking bug, not a hyperparameter one.
Do not use this skill when
- The training is multi-node or large-scale multi-GPU. Use plain TRL with Accelerate/DeepSpeed.
- The architecture is unsupported by Unsloth. Fall back to TRL; do not force it.
- The user wants managed cloud training. That is Hugging Face Jobs, not local Unsloth.
- The user wants the Desktop or Studio GUI. Point them at the installer, not this skill.
How It Works
Step 1: Size the run before writing code
VRAM is the constraint that decides everything else. Estimate weights first, then leave room for activations and optimizer state:
| Load mode | Weight cost | 8B model | Use when |
|---|---|---|---|
load_in_4bit (QLoRA) |
~0.55 GB per 1B params | ~4.5 GB | Default. Under 16 GB VRAM. |
load_in_8bit |
~1.1 GB per 1B params | ~9 GB | Quality-sensitive, 16-24 GB. |
load_in_16bit |
~2 GB per 1B params | ~16 GB | LoRA at full precision, 24 GB+. |
full_finetuning=True |
~2 GB weights + ~12 GB optimizer | ~112 GB | Rarely justified. Prefer LoRA. |
Add roughly 2-6 GB for activations, scaling with max_seq_length and batch size. Treat these
as planning figures and confirm against nvidia-smi on the first run — they vary by
architecture, attention implementation and vocabulary size.
If the estimate does not fit, reduce in this order: max_seq_length, then batch size (raising
gradient_accumulation_steps to hold the effective batch constant), then LoRA rank, then model
size. Cutting rank before sequence length usually costs more quality than it saves memory.
Step 2: Load the model
import unsloth must come before transformers, trl or peft. Unsloth patches those
libraries at import time; importing them first silently disables the optimizations.
import unsloth # must be first
import os
import re
from unsloth import FastLanguageModel
def reviewed_revision(variable):
revision = os.environ.get(variable, "")
if re.fullmatch(r"[0-9a-fA-F]{40}", revision) is None:
raise RuntimeError(f"{variable} must be a reviewed full 40-character Hub commit SHA")
return revision.lower()
model_revision = reviewed_revision("UNSLOTH_MODEL_REVISION")
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "unsloth/Qwen3-8B",
revision = model_revision,
max_seq_length = 2048,
load_in_4bit = True,
dtype = None, # auto-detects bf16 where supported
)
Pick the loader that matches the modality: FastLanguageModel for text-only causal LMs,
FastVisionModel for vision-language models, FastModel when the modality is decided at runtime.
The unsloth/ Hub namespace holds pre-quantized copies that download faster and skip a local
quantization pass. Upstream repos such as Qwen/ or meta-llama/ work identically.
Before setting UNSLOTH_MODEL_REVISION, inspect that exact Hub commit and obtain approval for the
download. Record the repository and full revision with the run; never substitute a branch, tag,
range, or moving default.
Step 3: Fix the chat template before training
This is the most common silent failure. A run with the wrong template converges cleanly and produces a model that ignores its stop tokens or emits prompt scaffolding at inference.
from unsloth.chat_templates import (
get_chat_template,
standardize_data_formats,
…
Câu hỏi thường gặp
VRAM là gì và vì sao quan trọng?
VRAM là bộ nhớ chuyên dụng trên card đồ họa của bạn. Mô hình AI cần rất nhiều VRAM để huấn luyện. Công cụ này giúp dùng ít VRAM hơn.
LoRA và QLoRA là gì?
Đây là các kỹ thuật cho phép chỉ huấn luyện một phần nhỏ của mô hình AI, tiết kiệm đáng kể bộ nhớ và thời gian. QLoRA còn tiết kiệm bộ nhớ hơn nữa.
“Chat template” là gì?
Đó là định dạng mà mô hình AI dùng để hiểu cách các cuộc hội thoại được cấu trúc. Chat template sai có thể khiến mô hình trả lời sai.
Chi tiết
Mô tả gốc của tác giả
Fine-tune and post-train LLMs with Unsloth Core on a single consumer GPU: VRAM sizing, LoRA/QLoRA, GRPO/DPO, chat-template correctness, and GGUF export.
Độ phổ biến
- Sao GitHub
- 48k
- Vị trí xếp hạng
- #6066
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
00-andruia-consultant
48kGiúp agent của bạn bắt đầu hoặc cải thiện các dự án AI. Phân tích mã, gợi ý công cụ và lập kế hoạch hành động bằng tiếng Tây Ban Nha.
007
48kCho phép agent của bạn thực hiện kiểm toán bảo mật và mô hình hóa mối đe dọa. Hữu ích để bảo vệ dự án khỏi các cuộc tấn công và lỗ hổng.
10-andruia-skill-smith
48kGiúp agent của bạn tạo hoặc cải thiện các công cụ AI. Xác định cách công cụ hoạt động, viết tài liệu và kiểm tra cấu trúc.
20-andruia-niche-intelligence
48kGiúp agent của bạn tạo bản tóm tắt về một ngành cụ thể. Hữu ích để hiểu bối cảnh, quy tắc, cách người dùng tương tác và rủi ro của dự án.
Skill tương tự
add-model-provider
394kGiúp agent của bạn kết nối nhà cung cấp mô hình AI mới với OpenClaw bằng lệnh an toàn, giữ API key khỏi văn bản thuần và chạy thử.
acp-router
394kGiúp agent của bạn gửi một tác vụ đến trợ lý lập trình như Claude Code hoặc Cursor qua OpenClaw, để công việc chạy ngay trong công cụ đó.
browser-automation
394kHướng dẫn agent của bạn điều khiển trang web từng bước, gồm đăng nhập, tab và cách khôi phục khi trang ngừng phản hồi.