Tahap 02Google Colab Pro · Unsloth QLoRA · Hugging Face Hub
Konfigurator Fine-Tuning Colab Pro
Susun parameter QLoRA untuk melatih model 1.5B–7B di atas base model kode open-weights, pantau estimasi VRAM serta kuota Compute Units, lalu unduh notebook .ipynb siap pakai.
Estimasi VRAM QLoRA
9.7 / 24 GB
Muat aman di L4
Estimasi Durasi Sesi
~58 mnt
Batch optimal: 4 · 3 epoch
Pemakaian Colab Pro
4.66 CU
Auto runtime.unassign() aktif
Ukuran Output Model
~4.41 GB
Target: GGUF_Q4_K_M
Parameter Fine-Tuning
Paham logika bahasa C secara mendalam; paling akurat untuk dialek Enki UNUL.
Ollama lokal, Antigravity IDE, llama.cpp, dan VPS CPU.
Catatan Arsitektur Google Colab Pro
Konfigurasi aman. runtime.unassign() otomatis menghentikan pemakaian Compute Units setelah push ke Hugging Face.
Sesuai batasan layanan Colab, gunakan Colab Pro khusus untuk pabrik pelatihan on-demand (1–3 jam) atau worker antrean semi on-trigger—jangan mengekspos server REST API publik 24/7 secara permanen di dalam notebook.
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "unul_unsloth_colab.ipynb",
"provenance": [],
"gpuType": "L4"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# UNUL-Coder Fine-Tuning Pipeline (Google Colab Pro + Unsloth)\n",
"- **Base Model**: `unsloth/Qwen2.5-Coder-7B-Instruct-bnb-4bit`\n",
"- **Target GPU**: `L4` (Estimasi VRAM: 9.7 GB)\n",
"- **Hugging Face Target**: `wisatamasalalu/unul-coder-7b`\n",
"- **Dataset**: `unul_dataset.jsonl` (2500 baris, 3 epoch)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"!pip install \"unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git\"\n",
"!pip install --no-deps trl peft accelerate bitsandbytes datasets huggingface_hub\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from google.colab import userdata\n",
"from unsloth import FastLanguageModel\n",
"from datasets import load_dataset\n",
"from trl import SFTTrainer\n",
"from transformers import TrainingArguments\n\n",
"HF_TOKEN = userdata.get('HF_TOKEN') # Simpan token write Hugging Face di Colab Secrets\n",
"max_seq_length = 2048\n\n",
"model, tokenizer = FastLanguageModel.from_pretrained(\n",
" model_name=\"unsloth/Qwen2.5-Coder-7B-Instruct-bnb-4bit\",\n",
" max_seq_length=max_seq_length,\n",
" dtype=None,\n",
" load_in_4bit=True,\n",
")\n\n",
"model = FastLanguageModel.get_peft_model(\n",
" model,\n",
" r=16,\n",
" target_modules=[\"q_proj\", \"k_proj\", \"v_proj\", \"o_proj\", \"gate_proj\", \"up_proj\", \"down_proj\"],\n",
" lora_alpha=16,\n",
" lora_dropout=0,\n",
" bias=\"none\",\n",
" use_gradient_checkpointing=\"unsloth\",\n",
" random_state=3407,\n",
")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Muat dataset ChatML JSONL hasil Compiler-in-the-Loop validator\n",
"dataset = load_dataset(\"json\", data_files=\"unul_dataset.jsonl\", split=\"train\")\n\n",
"def format_chatml(batch):\n",
" texts = [\n",
" tokenizer.apply_chat_template(msgs, tokenize=False, add_generation_prompt=False)\n",
" for msgs in batch[\"messages\"]\n",
" ]\n",
" return {\"text\": texts}\n\n",
"dataset = dataset.map(format_chatml, batched=True)\n\n",
"trainer = SFTTrainer(\n",
" model=model,\n",
" tokenizer=tokenizer,\n",
" train_dataset=dataset,\n",
" dataset_text_field=\"text\",\n",
" max_seq_length=max_seq_length,\n",
" args=TrainingArguments(\n",
" per_device_train_batch_size=4,\n",
" gradient_accumulation_steps=4,\n",
" warmup_steps=10,\n",
" num_train_epochs=3,\n",
" learning_rate=2e-4,\n",
" fp16=False,\n",
" bf16=True,\n",
" logging_steps=10,\n",
" optim=\"adamw_8bit\",\n",
" output_dir=\"outputs_unul\",\n",
" ),\n",
")\n",
"trainer.train()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from google.colab import drive\n",
"drive.mount('/content/drive')\n",
"model.save_pretrained('/content/drive/MyDrive/unul-ai-checkpoints/latest_lora')\n",
"tokenizer.save_pretrained('/content/drive/MyDrive/unul-ai-checkpoints/latest_lora')\n",
"\n",
"# Ekspor & unggah GGUF Q4_K_M langsung ke Hugging Face Hub\n",
"model.push_to_hub_gguf(\"wisatamasalalu/unul-coder-7b\", tokenizer, quantization_method=\"q4_k_m\", token=HF_TOKEN)\n",
"\n",
"# Matikan VM Colab Pro otomatis agar kuota Compute Units langsung berhenti\n",
"from google.colab import runtime\n",
"print(\"Training & push Hugging Face selesai. Mematikan runtime...\")\n",
"runtime.unassign()\n"
]
}
]
}