From 57ca3c0401e7b02b6d2ed50004c9837b07022af2 Mon Sep 17 00:00:00 2001 From: madroid Date: Tue, 8 Aug 2023 01:28:07 +0800 Subject: [PATCH 1/3] Add run.ipynb for easier feel the magic --- run.ipynb | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 run.ipynb diff --git a/run.ipynb b/run.ipynb new file mode 100644 index 0000000..f02a4cf --- /dev/null +++ b/run.ipynb @@ -0,0 +1,121 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "HLdoj4cz-xal" + }, + "source": [ + "# Run.c\n", + "\n", + "More details can be found in the [README.md](README.md) ." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nX78K1Fi-38d" + }, + "source": [ + "## Clone Project" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Une3Ozlnu1B7" + }, + "outputs": [], + "source": [ + "!git clone https://github.com/karpathy/llama2.c.git\n", + "%cd llama2.c" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1MB5LGla-8Ln" + }, + "source": [ + "## Build" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "V1EGferJv_7o" + }, + "outputs": [], + "source": [ + "!make run" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "MuMpJio8_AKi" + }, + "source": [ + "## Run" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "MRy23xxavJNO" + }, + "outputs": [], + "source": [ + "# run stories15M\n", + "# !wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin\n", + "# !./run stories110M.bin\n", + "\n", + "# run stories42M\n", + "# !wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories42M.bin\n", + "# !./run stories42M.bin\n", + "\n", + "# run stories110M\n", + "!wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories110M.bin\n", + "!./run stories110M.bin" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Wi48eJKI_FKO" + }, + "source": [ + "## Run with args" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "YFOv6U74vSSZ" + }, + "outputs": [], + "source": [ + "!./run stories110M.bin -t 0.8 -n 256 -i \"One day, Lily met a Shoggoth\"" + ] + } + ], + "metadata": { + "colab": { + "private_outputs": true, + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} From 27c5fc76b130cfd88bb41399b707a7651496be5d Mon Sep 17 00:00:00 2001 From: madroid Date: Tue, 8 Aug 2023 01:50:19 +0800 Subject: [PATCH 2/3] Add Google Colab button --- README.md | 2 ++ run.ipynb | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index 241c822..86c5848 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,8 @@ Please note that this started recently as just a fun weekend project: I took my ## feel the magic +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/karpathy/llama2.c/blob/master/run.ipynb) + First, navigate to the folder when you keep your projects and clone this repository to this folder: ```bash diff --git a/run.ipynb b/run.ipynb index f02a4cf..26b4b77 100644 --- a/run.ipynb +++ b/run.ipynb @@ -8,6 +8,8 @@ "source": [ "# Run.c\n", "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/karpathy/llama2.c/blob/master/run.ipynb)\n", + "\n", "More details can be found in the [README.md](README.md) ." ] }, From 9713609023fe330c7679a955150a63f3c0c4cde7 Mon Sep 17 00:00:00 2001 From: madroid Date: Tue, 8 Aug 2023 19:10:45 +0800 Subject: [PATCH 3/3] Add Colab GUI: select model/temperature/prompt/etc --- run.ipynb | 94 +++++++++++++++++++++++-------------------------------- 1 file changed, 40 insertions(+), 54 deletions(-) diff --git a/run.ipynb b/run.ipynb index 26b4b77..95c5b0f 100644 --- a/run.ipynb +++ b/run.ipynb @@ -13,15 +13,6 @@ "More details can be found in the [README.md](README.md) ." ] }, - { - "cell_type": "markdown", - "metadata": { - "id": "nX78K1Fi-38d" - }, - "source": [ - "## Clone Project" - ] - }, { "cell_type": "code", "execution_count": null, @@ -30,78 +21,73 @@ }, "outputs": [], "source": [ + "#@title Clone Project\n", + "\n", "!git clone https://github.com/karpathy/llama2.c.git\n", "%cd llama2.c" ] }, - { - "cell_type": "markdown", - "metadata": { - "id": "1MB5LGla-8Ln" - }, - "source": [ - "## Build" - ] - }, { "cell_type": "code", "execution_count": null, - "metadata": { - "id": "V1EGferJv_7o" - }, + "metadata": {}, "outputs": [], "source": [ + "#@title Build\n", + "\n", "!make run" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { - "id": "MuMpJio8_AKi" + "id": "thm0ZBrtSgoC" }, + "outputs": [], "source": [ - "## Run" + "#@title Pick Your Model\n", + "\n", + "#@markdown Choose model\n", + "model = \"stories15M\" #@param [\"stories15M\", \"stories42M\", \"stories110M\"]\n", + "\n", + "download_url = \"\"\n", + "\n", + "if(model == \"stories15M\"):\n", + " download_url = \"https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin\"\n", + "if(model == \"stories42M\"):\n", + " download_url = \"https://huggingface.co/karpathy/tinyllamas/resolve/main/stories42M.bin\"\n", + "if(model == \"stories110M\"):\n", + " download_url = \"https://huggingface.co/karpathy/tinyllamas/resolve/main/stories110M.bin\"\n", + "\n", + "print(f\"download_url: {download_url}\")\n", + "\n", + "!wget $download_url\n", + "\n", + "model_file = model + \".bin\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "id": "MRy23xxavJNO" + "id": "OgAc3KjuT-NM" }, "outputs": [], "source": [ - "# run stories15M\n", - "# !wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories15M.bin\n", - "# !./run stories110M.bin\n", + "#@title Generate Stories\n", "\n", - "# run stories42M\n", - "# !wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories42M.bin\n", - "# !./run stories42M.bin\n", + "# Generate args\n", + "max_token = 256 #@param {type:\"slider\", min:32, max:1024, step:32}\n", + "temperature = 0.8 #@param {type:\"slider\", min:0.0, max:1, step:0.05}\n", + "top_p = 0.9 #@param {type:\"slider\", min:0.0, max:1.0, step:0.05}\n", + "prompt = \"One day, Lily met a Shoggoth\" #@param {type:\"string\"}\n", "\n", - "# run stories110M\n", - "!wget https://huggingface.co/karpathy/tinyllamas/resolve/main/stories110M.bin\n", - "!./run stories110M.bin" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "Wi48eJKI_FKO" - }, - "source": [ - "## Run with args" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "YFOv6U74vSSZ" - }, - "outputs": [], - "source": [ - "!./run stories110M.bin -t 0.8 -n 256 -i \"One day, Lily met a Shoggoth\"" + "print(f\"model: {model_file}, max_token: {max_token}, temperature: {temperature}, top_p: {top_p}, prompt: {prompt}\")\n", + "print(f\"----------------------------\\n\")\n", + "\n", + "cmd = f'./run {model_file} -t {temperature} -p {top_p} -n {max_token} -i \"{prompt}\"'\n", + "!{cmd}" ] } ],