From 999b1bf7760bb235695c9e3601898faf3dbe92b5 Mon Sep 17 00:00:00 2001 From: rdentato Date: Sun, 6 Aug 2023 21:07:09 +0000 Subject: [PATCH 1/8] Added conditinal include of the OpenMP header. --- run.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/run.c b/run.c index 02cc877..4ff9e5d 100644 --- a/run.c +++ b/run.c @@ -20,6 +20,11 @@ $ ./run #include #include #endif + +#ifdef _OPENMP +#include +#endif + // ---------------------------------------------------------------------------- // Transformer and RunState structs, and related memory management From e49c16caa5ffdbf2428174adb3d27af7d5c3e3a2 Mon Sep 17 00:00:00 2001 From: rdentato Date: Mon, 7 Aug 2023 06:51:57 +0000 Subject: [PATCH 2/8] Changed how rng_seed is handled. Now 0 is treated as time(NULL). --- run.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run.c b/run.c index 4ff9e5d..5cb1b96 100644 --- a/run.c +++ b/run.c @@ -522,7 +522,7 @@ int main(int argc, char *argv[]) { char *checkpoint = NULL; // e.g. out/model.bin float temperature = 1.0f; // 0.0 = greedy deterministic. 1.0 = original. don't set higher float topp = 0.9f; // top-p in nucleus sampling - rng_seed = (unsigned int)time(NULL); // seed rng with time by default + rng_seed = 0; // seed rng with time by default int steps = 256; // number of steps to run for char *prompt = NULL; // prompt string @@ -541,7 +541,7 @@ int main(int argc, char *argv[]) { else if (argv[i][1] == 'i') { prompt = argv[i + 1]; } else { error_usage(); } } - if(rng_seed == 0) { fprintf(stderr, "Cannot use seed=0 because of the rng alg used\n"); return 1; } + if(rng_seed == 0) { rng_seed = (unsigned int)time(NULL);} // read in the model.bin file Config config; From ff6a2f0a7a257fcfd0f82759b542d0f09af924f6 Mon Sep 17 00:00:00 2001 From: rdentato Date: Mon, 7 Aug 2023 07:28:03 +0000 Subject: [PATCH 3/8] Reset the #include --- run.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/run.c b/run.c index 5cb1b96..9f4a1b2 100644 --- a/run.c +++ b/run.c @@ -20,11 +20,6 @@ $ ./run #include #include #endif - -#ifdef _OPENMP -#include -#endif - // ---------------------------------------------------------------------------- // Transformer and RunState structs, and related memory management From 57ca3c0401e7b02b6d2ed50004c9837b07022af2 Mon Sep 17 00:00:00 2001 From: madroid Date: Tue, 8 Aug 2023 01:28:07 +0800 Subject: [PATCH 4/8] 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 5/8] 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 6/8] 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}" ] } ], From 256e7f885bac3f5f98cb21287ec064c02c3987fc Mon Sep 17 00:00:00 2001 From: Rahul TR Date: Wed, 9 Aug 2023 17:59:47 +0530 Subject: [PATCH 7/8] Added C# port information in readme --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b62a8d8..126c901 100644 --- a/README.md +++ b/README.md @@ -238,7 +238,9 @@ If your candidate PRs have elements of these it doesn't mean they won't get merg - Kotlin - [llama2.kt](https://github.com/madroidmaq/llama2.kt) by @[madroidmaq](https://github.com/madroidmaq): a Kotlin port of this project - Python - - [llama2.py](https://github.com/tairov/llama2.py) by @[tairov](https://github.com/tairov): a simple one file pure Python port of this project with zero dependencies + - [llama2.py](https://github.com/tairov/llama2.py) by @[tairov](https://github.com/tairov): a simple one file pure Python port of this project with zero dependencies +- C# + - [llama2.cs](https://github.com/trrahul/llama2.cs) by @[trrahul](https://github.com/trrahul): a C# port of this project - [llama2.c - Llama 2 Everywhere](https://github.com/trholding/llama2.c) by @[trholding](https://github.com/trholding): Standalone, Bootable & Portable Binary Llama 2 ## unsorted todos From 3f69c6cdc43a82a65e4bdc0270fc4ecd9dca7cf9 Mon Sep 17 00:00:00 2001 From: Andrej Karpathy Date: Thu, 10 Aug 2023 05:06:49 +0000 Subject: [PATCH 8/8] change the default to use runfast, which imo works just fine --- run.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run.ipynb b/run.ipynb index 95c5b0f..cd69b79 100644 --- a/run.ipynb +++ b/run.ipynb @@ -35,7 +35,7 @@ "source": [ "#@title Build\n", "\n", - "!make run" + "!make runfast" ] }, {