Upload training/evez-kaggle-training.ipynb with huggingface_hub
Browse files
training/evez-kaggle-training.ipynb
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": ["# 🧬 EVEZ Self-Training Pipeline\n", "### Kaggle T4 GPU Fine-Tuning\n", "**Steps:** Settings → Accelerator → GPU T4 → Run All\n", "**Time:** ~20 min | **Cost:** $0 (free tier)"]
|
| 7 |
+
},
|
| 8 |
+
{
|
| 9 |
+
"cell_type": "code",
|
| 10 |
+
"metadata": {},
|
| 11 |
+
"source": ["!pip install -q transformers datasets peft trl torch accelerate\n", "import torch\n", "print(f'GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else \"NONE\"}')"],
|
| 12 |
+
"outputs": [],
|
| 13 |
+
"execution_count": null
|
| 14 |
+
},
|
| 15 |
+
{
|
| 16 |
+
"cell_type": "code",
|
| 17 |
+
"metadata": {},
|
| 18 |
+
"source": ["import json, urllib.request\n", "url = 'https://raw.githubusercontent.com/EVEZX/neuros/main/training/evez-alpaca.json'\n", "urllib.request.urlretrieve(url, 'evez-alpaca.json')\n", "with open('evez-alpaca.json') as f:\n", " data = json.load(f)\n", "print(f'✅ Loaded {len(data)} instruction pairs')"],
|
| 19 |
+
"outputs": [],
|
| 20 |
+
"execution_count": null
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"cell_type": "code",
|
| 24 |
+
"metadata": {},
|
| 25 |
+
"source": ["from transformers import AutoModelForCausalLM, AutoTokenizer\n", "from peft import LoraConfig, get_peft_model\n", "from trl import SFTTrainer, SFTConfig\n", "from datasets import Dataset\n", "\n", "formatted = []\n", "for d in data:\n", " text = f\"### Instruction:\\n{d['instruction']}\\n### Input:\\n{d.get('input','')}\\n### Response:\\n{d['output']}\"\n", " formatted.append({'text': text})\n", "dataset = Dataset.from_list(formatted)\n", "\n", "model_name = 'HuggingFaceTB/SmolLM2-135M'\n", "tokenizer = AutoTokenizer.from_pretrained(model_name)\n", "tokenizer.pad_token = tokenizer.eos_token\n", "model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map='auto')\n", "\n", "lora_config = LoraConfig(r=8, lora_alpha=16, lora_dropout=0.05, target_modules=['q_proj','v_proj'], task_type='CAUSAL_LM')\n", "model = get_peft_model(model, lora_config)\n", "model.print_trainable_parameters()"],
|
| 26 |
+
"outputs": [],
|
| 27 |
+
"execution_count": null
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"cell_type": "code",
|
| 31 |
+
"metadata": {},
|
| 32 |
+
"source": ["training_args = SFTConfig(output_dir='./evez-adapter', num_train_epochs=3, per_device_train_batch_size=4, learning_rate=2e-4, logging_steps=10, max_seq_length=512, dataset_text_field='text')\n", "trainer = SFTTrainer(model=model, args=training_args, train_dataset=dataset, processing_class=tokenizer)\n", "trainer.train()"],
|
| 33 |
+
"outputs": [],
|
| 34 |
+
"execution_count": null
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"cell_type": "code",
|
| 38 |
+
"metadata": {},
|
| 39 |
+
"source": ["model.save_pretrained('./evez-adapter')\n", "tokenizer.save_pretrained('./evez-adapter')\n", "print('✅ Training complete! Adapter saved to ./evez-adapter/')"],
|
| 40 |
+
"outputs": [],
|
| 41 |
+
"execution_count": null
|
| 42 |
+
}
|
| 43 |
+
],
|
| 44 |
+
"metadata": {
|
| 45 |
+
"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"},
|
| 46 |
+
"accelerator": "GPU"
|
| 47 |
+
},
|
| 48 |
+
"nbformat": 4,
|
| 49 |
+
"nbformat_minor": 4
|
| 50 |
+
}
|