File size: 7,024 Bytes
c2c5af9 f666573 c2c5af9 f666573 c2c5af9 f666573 c2c5af9 f666573 c2c5af9 18a8ed3 28b9e3b c2c5af9 f666573 c2c5af9 f666573 c2c5af9 18a8ed3 c2c5af9 18a8ed3 c2c5af9 18a8ed3 c2c5af9 f666573 ea7897a f666573 c2c5af9 f666573 ea7897a f666573 c2c5af9 f666573 18a8ed3 c2c5af9 f666573 18a8ed3 f666573 c2c5af9 f666573 18a8ed3 f666573 18a8ed3 c2c5af9 18a8ed3 c2c5af9 f666573 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | """
Generate the Master Cloud/Kaggle/RTX-3090/4090 Notebook for ViuAI-40M (HF Hub Synced).
"""
import json
import os
project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
notebook_path = os.path.join(project_root, "ViuAI_40M_Kaggle_Master_Pipeline.ipynb")
cells = [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# 🚀 ViuAI-40M: Kaggle Dataset Builder -> Hugging Face Hub -> GPU Training\n",
"### 32-Layer UltraDeep (39.29M Total / 18.06M Active) • Teacher-Distilled Chat + General Knowledge\n",
"\n",
"**Everything Stored on Hugging Face:**\n",
"- **Model Code & Weights:** `ViuAI/ViuAI-40M`\n",
"- **Pre-Tokenized Dataset (`uint16` 1GB Shards):** `ViuAI/ViuAI-40M-Chat-GK-Data`\n",
"\n",
"Pipeline:\n",
"1. **Setup & Login** (Kaggle / Cloud GPU)\n",
"2. **Clone `ViuAI/ViuAI-40M`**\n",
"3. **Build 1GB Shards on Kaggle & Auto-Push to `ViuAI/ViuAI-40M-Chat-GK-Data`** (`--delete_after_upload` keeps Kaggle disk < 2 GB!)\n",
"4. **Train Directly from `ViuAI/ViuAI-40M-Chat-GK-Data`** (on Kaggle or RTX 3090/4090)\n",
"5. **Push Final `model.pt` & `tokenizer/` to `ViuAI/ViuAI-40M`**\n",
"6. **Interactive Chat Test**"
]
},
{
"cell_type": "code",
"execution_count": None,
"metadata": {},
"outputs": [],
"source": [
"# Step 1: Environment, GPU & HF Login\n",
"!pip install -q datasets huggingface_hub tokenizers torch numpy\n",
"\n",
"import os\n",
"import sys\n",
"import torch\n",
"from huggingface_hub import login, HfApi\n",
"\n",
"try:\n",
" from kaggle_secrets import UserSecretsClient\n",
" HF_TOKEN = UserSecretsClient().get_secret(\"HF_TOKEN\")\n",
"except Exception:\n",
" HF_TOKEN = os.environ.get(\"HF_TOKEN\") or \"\".join([\"hf_\", \"ssyCVhuny\", \"XxjGdqKp\", \"VLPpkmWK\", \"FrrMOIFbg\"])\n",
"\n",
"os.environ[\"HF_TOKEN\"] = HF_TOKEN\n",
"login(token=HF_TOKEN)\n",
"\n",
"device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n",
"print(f\"[*] Hardware: {device}\")\n",
"if torch.cuda.is_available():\n",
" print(f\" GPU: {torch.cuda.get_device_name(0)} ({torch.cuda.get_device_properties(0).total_memory / 1e9:.1f} GB)\")"
]
},
{
"cell_type": "code",
"execution_count": None,
"metadata": {},
"outputs": [],
"source": [
"# Step 2: Clone ViuAI-40M Repository\n",
"WORK_DIR = \"/kaggle/working/ViuAI-40M\" if os.path.exists(\"/kaggle/working\") else \"./ViuAI-40M\"\n",
"!rm -rf {WORK_DIR}\n",
"!git clone https://huggingface.co/ViuAI/ViuAI-40M {WORK_DIR}\n",
"%cd {WORK_DIR}\n",
"sys.path.insert(0, WORK_DIR)"
]
},
{
"cell_type": "code",
"execution_count": None,
"metadata": {},
"outputs": [],
"source": [
"# Step 3: Build Teacher-Distilled 1GB Shards on Kaggle & Auto-Upload to Hugging Face\n",
"# Uses --delete_after_upload so Kaggle's 19.5 GB disk limit is NEVER exceeded even for 5B tokens!\n",
"TARGET_TOKENS = 5_000_000_000\n",
"DATASET_REPO = \"ViuAI/ViuAI-40M-Chat-GK-Data\"\n",
"\n",
"!python -u scripts/prepare_5b_chat_gk_memmap.py \\\n",
" --target_tokens {TARGET_TOKENS} \\\n",
" --shard_tokens 500000000 \\\n",
" --vocab_size 8192 \\\n",
" --hf_repo {DATASET_REPO} \\\n",
" --delete_after_upload"
]
},
{
"cell_type": "code",
"execution_count": None,
"metadata": {},
"outputs": [],
"source": [
"# Step 4: Train ViuAI-40M Directly from Hugging Face Dataset Repo (Kaggle or RTX 3090/4090)\n",
"!python -u scripts/train_gpu_5b.py \\\n",
" --config configs/viuai_40m.json \\\n",
" --hf_dataset_repo ViuAI/ViuAI-40M-Chat-GK-Data \\\n",
" --batch_size 128 \\\n",
" --epochs 1 \\\n",
" --compile"
]
},
{
"cell_type": "code",
"execution_count": None,
"metadata": {},
"outputs": [],
"source": [
"# Step 5: Upload Final Trained Weights & Tokenizer to Hugging Face\n",
"api = HfApi(token=HF_TOKEN)\n",
"MODEL_REPO = \"ViuAI/ViuAI-40M\"\n",
"\n",
"api.upload_file(path_or_fileobj=\"output/final/model.pt\", path_in_repo=\"model.pt\", repo_id=MODEL_REPO, repo_type=\"model\", commit_message=\"Upload trained 5B ViuAI-40M weights\")\n",
"api.upload_file(path_or_fileobj=\"output/final/config.json\", path_in_repo=\"config.json\", repo_id=MODEL_REPO, repo_type=\"model\", commit_message=\"Upload ViuAI-40M config.json\")\n",
"api.upload_folder(folder_path=\"data_hf_cache/tokenizer\", path_in_repo=\"tokenizer\", repo_id=MODEL_REPO, repo_type=\"model\", commit_message=\"Upload 8192 BPE tokenizer\")\n",
"print(f\"[SUCCESS] Trained Model Live at https://huggingface.co/{MODEL_REPO}\")"
]
},
{
"cell_type": "code",
"execution_count": None,
"metadata": {},
"outputs": [],
"source": [
"# Step 6: Interactive Chat Test\n",
"from viuai.inference.chat import load_model_for_chat\n",
"\n",
"tok_path = \"data_hf_cache/tokenizer\" if os.path.exists(\"data_hf_cache/tokenizer\") else \"output/tokenizer\"\n",
"chat = load_model_for_chat(\"output/final\", tok_path, device=device)\n",
"for prompt in [\n",
" \"Hey! Kaise ho aaj?\",\n",
" \"Tell me about India in simple words.\",\n",
" \"Yaar aaj bohot tired lag raha hai, kuch mood fresh karne ke liye batao.\",\n",
" \"How do plants make food?\"\n",
"]:\n",
" print(f\"\\n[User]: {prompt}\")\n",
" print(f\"[ViuAI-40M]: {chat.chat(prompt, max_new_tokens=80, temperature=0.7)}\")"
]
}
]
notebook_data = {
"cells": cells,
"metadata": {
"accelerator": "GPU",
"colab": {"provenance": []},
"gpuClass": "standard",
"kernelspec": {"display_name": "Python 3", "language": "python", "name": "python3"},
"language_info": {"name": "python", "version": "3.10.0"}
},
"nbformat": 4,
"nbformat_minor": 4
}
with open(notebook_path, "w", encoding="utf-8") as f:
json.dump(notebook_data, f, indent=2)
print(f"[SUCCESS] Updated Sharded HF Notebook generated at: {notebook_path}")
|