Dataset Viewer
Auto-converted to Parquet Duplicate
text
stringlengths
1
118
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# QLoRA on Goetia-26B-A4B — plain transformers + peft + trl\n",
"\n",
"This is the notebook I used for `Dark-Goetia-26B-A4B-LoRA` v2, cleaned up\n",
"and with the comments translated.\n",
"\n",
"**Environment it actually ran on:** torch 2.12.0+cu130, transformers 5.14.1,\n",
"single A100-SXM4-80GB (rented). ~51 min for 2 epochs, 1489 sessions.\n",
"\n",
"**Config:** QLoRA nf4, attention-only targets, r=32 / alpha=64, lr 2e-5,\n",
"max_len 2048, batch 1 x grad_accum 8.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Cell 1 — dependencies. After install: Kernel -> Restart.\n",
"!pip install --no-cache-dir -U \"transformers>=4.46\" \"peft>=0.13\" \"trl>=0.12\" \\\n",
" \"bitsandbytes>=0.44\" \"accelerate>=1.0\" datasets sentencepiece protobuf"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Cell 2 — environment sanity check\n",
"import torch, transformers\n",
"print(\"torch\", torch.__version__, \"| CUDA\", torch.version.cuda)\n",
"print(\"GPU count:\", torch.cuda.device_count())\n",
"for i in range(torch.cuda.device_count()):\n",
" p = torch.cuda.get_device_properties(i)\n",
" print(f\" [{i}] {p.name}, {p.total_memory/1e9:.0f} GB\")\n",
"print(\"transformers\", transformers.__version__)\n",
"assert torch.cuda.device_count() >= 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Cell 3 — config\n",
"MODEL_ID = \"Naphula/Goetia-26B-A4B-v1.3-Absolute-Heretic-ARA\"\n",
"MODEL_DIR = \"./goetia\"\n",
"DATA_PATH = \"./dataset.jsonl\"\n",
"OUT_DIR = \"./goetia-lora-v2\"\n",
"EPOCHS = 2\n",
"MAX_LEN = 2048 # i tried 3072, but catch OOM\n",
"RANK = 32\n",
"ALPHA = 64"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Cell 5 — dataset: ShareGPT jsonl -> messages format\n",
"import json\n",
"from datasets import Dataset\n",
"\n",
"ROLE = {\"system\": \"system\", \"human\": \"user\", \"gpt\": \"assistant\"}\n",
"rows = []\n",
"with open(DATA_PATH, encoding=\"utf-8\") as f:\n",
" for line in f:\n",
" line = line.strip()\n",
" if not line:\n",
" continue\n",
" conv = json.loads(line)[\"conversations\"]\n",
" rows.append({\"messages\": [{\"role\": ROLE[m[\"from\"]], \"content\": m[\"value\"]}\n",
" for m in conv]})\n",
"print(\"sessions:\", len(rows))\n",
"\n",
"# Cheap guard: a session with no assistant turn contributes nothing but\n",
"# still eats a training step.\n",
"assert all(any(m[\"role\"] == \"assistant\" for m in r[\"messages\"]) for r in rows)\n",
"\n",
"split = max(10, len(rows) // 20)\n",
"ds_train = Dataset.from_list(rows[:-split])\n",
"ds_eval = Dataset.from_list(rows[-split:])\n",
"print(\"train\", len(ds_train), \"| eval\", len(ds_eval))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
End of preview. Expand in Data Studio

⚠️ Note: Use Pytorch template 2.4. This works best on 12B because it is specifically calibrated for A100 SXM on runpod. Download v2 for multiarch support.

Gemma4FinetuneKit

💎 Gemma 4 Finetune Kit

by @Naphula

Here is the complete, start-to-finish guide using .tar.gz and your exact Hugging Face repository (26B-Suite/Gemma4-FinetuneKit).

This was developed for use with Runpod A100 SXM but can be adapted to other server types.

You should adjust settings like learning rate, epoch etc. as this wasn't calibrated yet (maybe 1e-4 and 2-3 epochs).


On Any Future / Fresh Pod (Restore & Install in 15 Seconds)

Whenever you spin up a brand-new pod, paste this single block into the terminal:

pip install hf && \
hf download 26B-Suite/Gemma4-FinetuneKit gemma4_wheels.tar.gz --repo-type dataset --local-dir /workspace && \
tar -xzvf /workspace/gemma4_wheels.tar.gz -C /workspace && \
pip install --no-cache-dir --no-index --upgrade --find-links=/workspace/clean_wheels \
  torch torchvision torchaudio transformers peft trl accelerate bitsandbytes datasets sentencepiece protobuf huggingface_hub

You are now ready to run python trainRunpod.py directly.


Notes

Yes, skipping Docker and using the wheelhouse method is completely fine, and for your use case, it is actually simpler and more flexible.

Why the Wheelhouse Method is Great

  1. Zero External Registries: You do not have to manage Docker Hub, GitHub Container Registries, or CI/CD build actions.
  2. True Immutability: Pre-compiled .whl binaries cannot change over time. Even if PyPI packages update or remove older versions, your .whl files remain exact byte-for-byte copies of the environment you verified.
  3. Template Agnostic: You can spin up any standard RunPod PyTorch template (or even switch cloud providers like Lambda Labs, Vast.ai, or Modal) and restore your exact environment in seconds.

Once executed, your pod will be locked to the exact working stack in about 15–20 seconds, ready to run python trainRunpod.py every single time.


Why .tar.gz is Better for RunPod / Linux:

  1. Pre-installed everywhere: The tar utility comes pre-installed in 100% of Linux Docker containers, cloud VMs, and RunPod pods. You will never have to run apt-get install zip unzip on a fresh pod.
  2. Preserves Unix file permissions: .tar.gz natively preserves exact Linux file permissions, symlinks, and executable attributes for binary wheels.
  3. Faster Extraction & Native Streaming: tar extracts multi-gigabyte wheel archives faster than unzip on Linux.

Gemma 4 12B - Unsloth Runpod SFT Template 🦥

The next step is to upload trainRunpod.py and merge_and_push.py to the pod.

Then you set your HF token, edit the scripts to point to your model/dataset/output names, and execute.

For example, 13696 is quite high for MAX_SEQ_LENGTH so you may want to lower it after auditing your dataset's max token count with dataset_audit.py

trainRunpod.py probably has room for improvement and adapting other features from axolotl payloads.

export HF_TOKEN="your_token_here"
python trainRunpod.py

After the finetune completes, you can then run merge_and_push.py to merge the LoRA into the base_model and upload directly to HF.

There you have it—a quick, simple guide for SFT finetuning Gemma 4 12B.

example


A Note on Datasets

This guide assumes you are already using ShareGPT format.

If you are starting from scratch or polishing a dataset then I recommend using this tool to build the JSON files.

If you are ready to combine the JSONs into a unified parquet for Gemma 4, use the following script: datasets_unify_sharegpt.py

I also highly recommend running the shuffle_parquet.py script to randomize the Q&A pairs after unification.


Quantization

After the safetensor merging, you must change "Gemma4UnifiedForConditionalGeneration" to "Gemma4ForConditionalGeneration" in the config.json in order to quantize the model to GGUF format.


Credits

Special thanks to @SubMaroon and @juiceb0xc0de for helping pin down some of the Gemma 4 python bugs.


Other Tools

Included are many scripts from the Poor Man's Portable Finetuner and ShareGPT Dataset Editor. You can use these to build, audit, and shuffle new datasets. These should be compatible with other model architectures but may require some adjustments.

Downloads last month
160