|
2 | 2 |
|
3 | 3 |  |
4 | 4 |
|
5 | | -## The Goal |
| 5 | +## Motivation |
6 | 6 |
|
7 | | -We dream of a world where ML hackers are able to grok with **REALLY BIG GPT** models without having GPU clusters consuming a shit tons of **$$$** - using only machines in their own homelabs. |
| 7 | +We dream of a world where fellow ML hackers are grokking **REALLY BIG GPT** models in their homelabs without having GPU clusters consuming a shit tons of **$$$**. |
8 | 8 |
|
9 | | -The code of the project is based on the legendary **[ggml.cpp](https://github.com/ggerganov/llama.cpp)** framework of Georgi Gerganov written in C++ |
| 9 | +The code of the project is based on the legendary **[ggml.cpp](https://github.com/ggerganov/llama.cpp)** framework of Georgi Gerganov written in C++ with the same attitude to performance and elegance. |
10 | 10 |
|
11 | | -We hope using our beloved Golang instead of *soo-powerful* but *too-low-level* language will allow much greater adoption of the **NoGPU** ideas. |
12 | | - |
13 | | -The V1 supports only FP32 math, so you'll need at least 32GB RAM to work even with the smallest **LLaMA-7B** model. As a preliminary step you should have binary files converted from original LLaMA model locally. |
| 11 | +We hope using Golang instead of *soo-powerful* but *too-low-level* language will allow much greater adoption. |
14 | 12 |
|
15 | 13 | ## V0 Roadmap |
16 | 14 |
|
17 | | -- [x] Run tensor math in pure Golang based on C++ source |
| 15 | +- [x] Tensor math in pure Golang |
18 | 16 | - [x] Implement LLaMA neural net architecture and model loading |
19 | | -- [x] Run smaller LLaMA-7B model |
20 | | -- [x] Be sure Go inference works EXACT SAME way as C++ |
21 | | -- [x] Let Go shine! Enable multi-threading and boost performance |
| 17 | +- [x] Test with smaller LLaMA-7B model |
| 18 | +- [x] Be sure Go inference works exactly same way as C++ |
| 19 | +- [x] Let Go shine! Enable multi-threading and messaging to boost performance |
22 | 20 |
|
23 | | -## V1 Roadmap |
| 21 | +## V1 Roadmap - Spring'23 |
24 | 22 |
|
25 | 23 | - [x] Cross-patform compatibility with Mac, Linux and Windows |
26 | | -- [x] Release first stable version for ML hackers |
27 | | -- [x] Support bigger LLaMA models: 13B, 30B, 65B |
28 | | -- [x] ARM NEON support on Apple Silicon (modern Macs) and ARM servers |
29 | | -- [x] Performance boost with x64 AVX2 support for Intel and AMD |
| 24 | +- [x] Release first stable version for ML hackers - v1.0 |
| 25 | +- [x] Enable bigger LLaMA models: 13B, 30B, 65B - v1.1 |
| 26 | +- [x] ARM NEON support on Apple Silicon (modern Macs) and ARM servers - v1.2 |
| 27 | +- [x] Performance boost with x64 AVX2 support for Intel and AMD - v1.2 |
| 28 | +- [x] Better memory use and GC optimizations - v1.3 |
| 29 | +- [x] Introduce Server Mode (embedded REST API) for use in real projects - v1.4 |
| 30 | +- [x] Release converted models for free access over the Internet - v1.4 |
| 31 | +- [ ] INT8 quantization to allow x4 bigger models fit same memory |
| 32 | +- [ ] Benchmark LLaMA.go against some mainstream Python / C++ frameworks |
| 33 | +- [ ] Enable some popular models of LLaMA family: Vicuna, Alpaca, etc |
30 | 34 | - [ ] Speed-up AVX2 with memory aligned tensors |
31 | | -- [ ] INT8 quantization to allow x4 bigger models fit the same memory |
32 | | -- [ ] Enable interactive mode for real-time chat with GPT |
33 | | -- [ ] Allow automatic download converted model weights from the Internet |
| 35 | +- [ ] Extensive logging for production monitoring |
| 36 | +- [ ] Interactive mode for real-time chat with GPT |
| 37 | + |
| 38 | +## V2 Roadmap - Summer'23 |
| 39 | + |
| 40 | +- [ ] Automatic CPU / GPU features detection |
34 | 41 | - [ ] Implement metrics for RAM and CPU usage |
35 | | -- [ ] Server Mode for use in Clouds as part of Microservice Architecture |
| 42 | +- [ ] Standalone GUI or web interface for better access to framework |
| 43 | +- [ ] Support popular open models: Open Assistant, StableLM, BLOOM, Anthropic, etc. |
| 44 | +- [ ] AVX512 support - yet another performance boost for AMD Epyc and Intel Sapphire Rapids |
| 45 | +- [ ] Nvidia GPUs support (CUDA or Tensor Cores) |
36 | 46 |
|
37 | | -## V2 Roadmap |
| 47 | +## V3 Roadmap - Fall'23 |
38 | 48 |
|
39 | 49 | - [ ] Allow plugins and external APIs for complex projects |
40 | | -- [ ] AVX512 support - yet another performance boost for AMD Epyc |
41 | | -- [ ] FP16 and BF16 support when hardware support there |
42 | | -- [ ] Support INT4 and GPTQ quantization |
| 50 | +- [ ] Allow model training and fine-tuning |
| 51 | +- [ ] Speed up execution on GPU cards and clusters |
| 52 | +- [ ] FP16 and BF16 math if hardware support is there |
| 53 | +- [ ] INT4 and GPTQ quantization |
| 54 | +- [ ] AMD Radeon GPUs support with OpenCL |
| 55 | + |
| 56 | +## How to Run? |
| 57 | + |
| 58 | +First, obtain and convert original LLaMA models on your own, or just download ready-to-rock ones: |
| 59 | + |
| 60 | +**LLaMA-7B:** [llama-7b-fp32.bin](https://nogpu.com/llama-7b-fp32.bin) |
| 61 | + |
| 62 | +**LLaMA-13B:** [llama-7b-fp32.bin](https://nogpu.com/llama-7b-fp32.bin) |
| 63 | + |
| 64 | +Both models store FP32 weights, so you'll needs at least 32Gb of RAM (not VRAM or GPU RAM) for LLaMA-7B. Double to 64Gb for LLaMA-13B. |
43 | 65 |
|
44 | | -## How to Run |
| 66 | +Next, build app binary from sources (see instructions below), or just download already built one: |
| 67 | + |
| 68 | +**Windows:** [llama-go-v1.4.0.exe](./builds/llama-go-v1.4.0.exe) |
| 69 | + |
| 70 | +**MacOS:** [llama-go-v1.4.0-macos](./builds/llama-go-v1.4.0-macos) |
| 71 | + |
| 72 | +**Linux:** [llama-go-v1.4.0-linux](./builds/llama-go-v1.4.0-linux) |
| 73 | + |
| 74 | +So now you have both executable and model, go try it for yourself: |
45 | 75 |
|
46 | 76 | ```shell |
47 | | -go run main.go \ |
48 | | - --model ~/models/7B/ggml-model-f32.bin \ |
49 | | - --temp 0.80 \ |
50 | | - --context 128 \ |
51 | | - --predict 128 \ |
52 | | - --prompt "Why Golang is so popular?" |
| 77 | +llama-go-v1.4.0-macos \ |
| 78 | + --model ~/models/llama-7b-fp32.bin \ |
| 79 | + --prompt "Why Golang is so popular?" \ |
53 | 80 | ``` |
54 | 81 |
|
55 | | -Or build it with Makefile and then run binary. |
56 | | - |
57 | | -## Useful CLI parameters: |
| 82 | +## Useful command line flags: |
58 | 83 |
|
59 | 84 | ```shell |
60 | 85 | --prompt Text prompt from user to feed the model input |
61 | | ---model Path and file name of converted .bin LLaMA model |
| 86 | +--model Path and file name of converted .bin LLaMA model [ llama-7b-fp32.bin, etc ] |
| 87 | +--server Start in Server Mode acting as REST API endpoint |
| 88 | +--host Host to allow requests from in Server Mode [ localhost by default ] |
| 89 | +--port Port listen to in Server Mode [ 8080 by default ] |
| 90 | +--pods Maximum pods or units of parallel execution allowed in Server Mode [ 1 by default ] |
62 | 91 | --threads Adjust to the number of CPU cores you want to use [ all cores by default ] |
63 | | ---predict Number of tokens to predict [ 64 by default ] |
64 | | ---context Context size in tokens [ 64 by default ] |
65 | | ---temp Model temperature hyper parameter [ 0.8 by default ] |
66 | | ---silent Hide welcome logo and other output [ show by default ] |
| 92 | +--context Context size in tokens [ 1024 by default ] |
| 93 | +--predict Number of tokens to predict [ 512 by default ] |
| 94 | +--temp Model temperature hyper parameter [ 0.5 by default ] |
| 95 | +--silent Hide welcome logo and other output [ shown by default ] |
67 | 96 | --chat Chat with user in interactive mode instead of compute over static prompt |
68 | | ---profile Profe CPU performance while running and store results to [cpu.pprof] file |
| 97 | +--profile Profe CPU performance while running and store results to cpu.pprof file |
69 | 98 | --avx Enable x64 AVX2 optimizations for Intel and AMD machines |
70 | 99 | --neon Enable ARM NEON optimizations for Apple Macs and ARM server |
71 | 100 | ``` |
72 | 101 |
|
| 102 | +## Going Production |
| 103 | +
|
| 104 | +LLaMA.go embeds standalone HTTP server exposing REST API. To enable it, run app with special flags: |
| 105 | +
|
| 106 | +```shell |
| 107 | +llama-go-v1.4.0-macos \ |
| 108 | + --model ~/models/llama-7b-fp32.bin \ |
| 109 | + --server \ |
| 110 | + --host 127.0.0.1 \ |
| 111 | + --port 8080 \ |
| 112 | + --pods 4 \ |
| 113 | + --threads 4 |
| 114 | +``` |
| 115 | +
|
| 116 | +Depending on the model size, how many CPU cores available there, how many requests you want to process in parallel, how fast you'd like to get answers, choose **pods** and **threads** parameters wisely. |
| 117 | +
|
| 118 | +**Pods** is a number of inference instances that might run in parallel. |
| 119 | +
|
| 120 | +**Threads** parameter sets how many cores will be used for tensor math within a pod. |
| 121 | +
|
| 122 | +So for example if you have machine with 16 hardware cores capable running 32 hyper-threads in parallel, you might end up with something like that: |
| 123 | +
|
| 124 | +```shell |
| 125 | +--server --pods 4 --threads 8 |
| 126 | +``` |
| 127 | +
|
| 128 | +When there is no free pod to handle arriving request, it will be placed into the waiting queue and started when some pod gets job finished. |
| 129 | +
|
| 130 | +# REST API examples |
| 131 | +
|
| 132 | +## Place new job |
| 133 | +
|
| 134 | +Send POST request (with Postman) to your server address with JSON containing unique UUID v4 and prompt: |
| 135 | +
|
| 136 | +```json |
| 137 | +{ |
| 138 | + "id": "5fb8ebd0-e0c9-4759-8f7d-35590f6c9fc3", |
| 139 | + "prompt": "Why Golang is so popular?" |
| 140 | +} |
| 141 | +``` |
| 142 | +
|
| 143 | +## Check job status |
| 144 | +
|
| 145 | +Send GET request (with Postman or browser) to URL like http://host:port/jobs/status/:id |
| 146 | +
|
| 147 | +```shell |
| 148 | +GET http://localhost:8080/jobs/status/5fb8ebd0-e0c9-4759-8f7d-35590f6c9fcb |
| 149 | +``` |
| 150 | +
|
| 151 | +## Get the results |
| 152 | +
|
| 153 | +Send GET request (with Postman or browser) to URL like http://host:port/jobs/:id |
| 154 | +
|
| 155 | +```shell |
| 156 | +GET http://localhost:8080/jobs/5fb8ebd0-e0c9-4759-8f7d-35590f6c9fcb |
| 157 | +``` |
| 158 | +
|
| 159 | +# How to build |
| 160 | +
|
| 161 | +First, install **Golang** and **git** (you'll need to download installers in case of Windows). |
| 162 | +
|
| 163 | +```shell |
| 164 | +brew install git |
| 165 | +brew install golang |
| 166 | +``` |
| 167 | +
|
| 168 | +Then clone the repo and enter the project folder: |
| 169 | +
|
| 170 | +``` |
| 171 | +git clone https://github.com/gotzmann/llama.go.git |
| 172 | +cd llama.go |
| 173 | +``` |
| 174 | +
|
| 175 | +Some Go magic to install external dependencies: |
| 176 | +
|
| 177 | +``` |
| 178 | +go tidy |
| 179 | +go vendor |
| 180 | +``` |
| 181 | +
|
| 182 | +Now we are ready to build the binary from the source code: |
| 183 | +
|
| 184 | +```shell |
| 185 | +go build -o llama-go-v1.exe -ldflags "-s -w" main.go |
| 186 | +``` |
| 187 | +
|
73 | 188 | ## FAQ |
74 | 189 |
|
75 | | -**1] Where might I get original LLaMA model files?** |
| 190 | +**1) From where I might obtain original LLaMA models?** |
76 | 191 |
|
77 | | -Contact Meta directly or look around for some torrent alternatives |
| 192 | +Contact Meta directly or just look around for some torrent alternatives. |
78 | 193 |
|
79 | | -**2] How to convert original LLaMA files into supported format?** |
| 194 | +**2) How to convert original LLaMA files into supported format?** |
80 | 195 |
|
81 | | -Youl'll need original FP16 files placed into **models** directory, then convert with command: |
| 196 | +Place original PyTorch FP16 files into **models** directory, then convert with command: |
82 | 197 |
|
83 | 198 | ```shell |
84 | 199 | python3 ./scripts/convert.py ~/models/LLaMA/7B/ 0 |
|
0 commit comments