Download scripts/generate_kaggle_notebook.py from ViuAI/ViuAI-40M: direct link, hf CLI and curl.
- Browser
- Download file 7.02 kB
-
https://huggingface.co/ViuAI/ViuAI-40M/resolve/main/scripts/generate_kaggle_notebook.py
- Command line
-
hf download hf://ViuAI/ViuAI-40M/scripts/generate_kaggle_notebook.py
-
curl -L -o generate_kaggle_notebook.py https://huggingface.co/ViuAI/ViuAI-40M/resolve/main/scripts/generate_kaggle_notebook.py
7.02 kB
| """ | |
| 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}") | |