{ "cells": [ { "cell_type": "markdown", "id": "playground-intro", "metadata": {}, "source": [ "# ChadGPT — open, run, and test\n", "\n", "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://huggingface.co/sam-eer12/chadGPT/colab)\n", "[![Open in Kaggle](https://kaggle.com/static/images/open-in-kaggle.svg)](https://huggingface.co/sam-eer12/chadGPT/kaggle)\n", "\n", "This notebook installs the required packages and automatically fetches the inference code, tokenizer, configuration, and model weights from **sam-eer12/chadGPT** on Hugging Face. No code to clone, files to upload, or Hugging Face login/token is needed.\n", "\n", "1. Open either launcher link and sign in to Colab or Kaggle.\n", "2. On **Kaggle**, enable **Internet** in notebook settings. Optionally select a GPU accelerator; CPU also works. Complete any account verification that Kaggle requests. On **Colab**, connect a runtime; a GPU is optional.\n", "3. Run **Install dependencies → Download and load → Test inference** in order. Read or change the example prompt in the test cell to try the model inside the notebook.\n", "\n", "The first model download is approximately **1 GB**. CUDA is selected when available, otherwise Apple MPS or CPU. Installation keeps the notebook's existing PyTorch/CUDA stack. No Hugging Face PRO subscription is required.\n", "\n", "[Model card and full training history](https://huggingface.co/sam-eer12/chadGPT)\n", "\n", "ChadGPT is an experimental 250M-parameter model trained from scratch on Kaggle over approximately two months. Its answers and generated code can be incorrect." ] }, { "cell_type": "markdown", "id": "install-guide", "metadata": {}, "source": [ "## 1. Install inference dependencies\n", "\n", "Kaggle and Colab normally provide PyTorch already. This cell keeps the existing PyTorch/CUDA stack. On a local notebook without PyTorch, install it separately first." ] }, { "cell_type": "code", "execution_count": null, "id": "install-packages", "metadata": {}, "outputs": [], "source": [ "%pip install -q tiktoken==0.12.0 safetensors==0.8.0 huggingface_hub==1.21.0" ] }, { "cell_type": "markdown", "id": "load-guide", "metadata": {}, "source": [ "## 2. Download and load the model\n", "\n", "Download the standalone inference files and model weights from the public Hugging Face repository. The weights and inference implementation are pinned to the verified initial model release." ] }, { "cell_type": "code", "execution_count": null, "id": "load-model", "metadata": {}, "outputs": [], "source": [ "import sys\n", "from pathlib import Path\n", "\n", "import torch\n", "from huggingface_hub import snapshot_download\n", "\n", "MODEL_REPO = \"sam-eer12/chadGPT\"\n", "MODEL_REVISION = \"1d79625c1b3194140ccfcb933ae49b6599820fbb\"\n", "\n", "torch.set_num_threads(2)\n", "print('Loading ChadGPT (approximately 1 GB on first download)…')\n", "model_dir = Path(snapshot_download(\n", " repo_id=MODEL_REPO,\n", " revision=MODEL_REVISION,\n", " allow_patterns=[\n", " \"model.safetensors\", \"config.json\", \"tokenizer.tiktoken\",\n", " \"tokenizer_config.json\", \"inference.py\", \"modeling_chadgpt.py\",\n", " ],\n", "))\n", "sys.path.insert(0, str(model_dir.resolve()))\n", "from inference import chat, load_model\n", "\n", "model, tokenizer = load_model(model_dir, device=\"auto\")\n", "print('Model ready on:', next(model.parameters()).device)\n", "print('PyTorch:', torch.__version__)\n", "print('Run the next cell to test inference.')" ] }, { "cell_type": "markdown", "id": "inference-guide", "metadata": {}, "source": [ "## 3. Test inference inside the notebook\n", "\n", "Run this cell for a sample response. Change **prompt** and run it again to ask another question. This test prints the answer here and does not start a public web server." ] }, { "cell_type": "code", "execution_count": null, "id": "test-inference", "metadata": {}, "outputs": [], "source": [ "prompt = \"Explain what a neural network is in simple terms.\" #@param {type:\"string\"}\n", "max_new_tokens = 96 #@param {type:\"integer\"}\n", "\n", "response = chat(\n", " model, tokenizer,\n", " messages=[\n", " {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n", " {\"role\": \"user\", \"content\": prompt},\n", " ],\n", " max_new_tokens=int(max_new_tokens), temperature=0.7, top_k=40,\n", ")\n", "print(response or \"The model ended its response without generating text. Try another prompt.\")" ] } ], "metadata": { "colab": { "name": "ChadGPT Inference", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 5 }