From f2eda961376b93161d07668fb0f22961516ede5e Mon Sep 17 00:00:00 2001 From: anzz1 Date: Fri, 17 Mar 2023 03:58:34 +0200 Subject: [PATCH 01/26] Fix Makefile --- Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile b/Makefile index cbbfb158913a..fb83d41badc5 100644 --- a/Makefile +++ b/Makefile @@ -176,7 +176,7 @@ $(info I CC: $(CCV)) $(info I CXX: $(CXXV)) $(info ) -default: main quantize +default: chat quantize # # Build library @@ -191,10 +191,6 @@ utils.o: utils.cpp utils.h clean: rm -f *.o main quantize -main: main.cpp ggml.o utils.o - $(CXX) $(CXXFLAGS) main.cpp ggml.o utils.o -o main $(LDFLAGS) - ./main -h - chat: chat.cpp ggml.o utils.o $(CXX) $(CXXFLAGS) chat.cpp ggml.o utils.o -o chat $(LDFLAGS) From 8a3d6f2ea4bf1f3e43876d65666bc777d18e2565 Mon Sep 17 00:00:00 2001 From: anzz1 Date: Fri, 17 Mar 2023 04:00:40 +0200 Subject: [PATCH 02/26] CI: Enable Linux/MacOS builds --- .github/workflows/build.yml | 68 ++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59aac6314a33..034ab4de90bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,37 +14,43 @@ on: paths: ['CMakeLists.txt', 'Makefile', '**.h', '*.c', '**.cpp'] jobs: -# ubuntu-latest: -# runs-on: ubuntu-latest -# -# steps: -# - name: Clone -# uses: actions/checkout@v1 -# -# - name: Dependencies -# run: | -# sudo apt-get update -# sudo apt-get install build-essential -# -# - name: Build -# run: | -# make -# -# macOS-latest: -# runs-on: macOS-latest -# -# steps: -# - name: Clone -# uses: actions/checkout@v1 -# -# - name: Dependencies -# run: | -# brew update -# -# - name: Build -# run: | -# make -# + ubuntu-latest: + runs-on: ubuntu-latest + + steps: + - name: Clone + id: checkout + uses: actions/checkout@v1 + + - name: Dependencies + id: depends + run: | + sudo apt-get update + sudo apt-get install build-essential + + - name: Build + id: make_build + run: | + make + + macOS-latest: + runs-on: macOS-latest + + steps: + - name: Clone + id: checkout + uses: actions/checkout@v1 + + - name: Dependencies + id: depends + run: | + brew update + + - name: Build + id: make_build + run: | + make + windows-latest: runs-on: windows-latest From 5be098f51e6fbe4656d886b021a377d4c04310a0 Mon Sep 17 00:00:00 2001 From: Xiao-Yong Jin Date: Fri, 17 Mar 2023 00:20:24 -0500 Subject: [PATCH 03/26] Compute remaining tokens along the way and exit if over --- chat.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/chat.cpp b/chat.cpp index 885d1f69a1e5..7bce57a2b10d 100644 --- a/chat.cpp +++ b/chat.cpp @@ -919,7 +919,8 @@ int main(int argc, char ** argv) { " - If you want to submit another line, end your input in '\\'.\n"); } - int remaining_tokens = params.n_predict; + // we may want to slide the input window along with the context, but for now we restrict to the context length + int remaining_tokens = model.hparams.n_ctx - embd_inp.size(); int input_consumed = 0; bool input_noecho = true; @@ -935,7 +936,7 @@ int main(int argc, char ** argv) { - while (true) { + while (remaining_tokens > 0) { // predict if (embd.size() > 0) { const int64_t t_start_us = ggml_time_us(); @@ -980,7 +981,7 @@ int main(int argc, char ** argv) { input_noecho = false; // decrement remaining sampling budget - // --remaining_tokens; + --remaining_tokens; } else { // some user input remains from prompt or interaction, forward it to processing while (embd_inp.size() > input_consumed) { @@ -1054,6 +1055,8 @@ int main(int argc, char ** argv) { embd_inp.insert(embd_inp.end(), line_inp.begin(), line_inp.end()); embd_inp.insert(embd_inp.end(), response_inp.begin(), response_inp.end()); + remaining_tokens -= prompt_inp.size() + line_inp.size() + response_inp.size(); + input_noecho = true; // do not echo this again } From af02c947989fffab4f87494533bb5b07e2919bc7 Mon Sep 17 00:00:00 2001 From: "Alex \"mcmonkey\" Goodwin" Date: Fri, 17 Mar 2023 04:49:41 -0700 Subject: [PATCH 04/26] add easy Windows install instructions to the readme Also fix a typo of LLaMA's casing in the chat.cpp file, and add cmake's generated files to the gitignore --- .gitignore | 13 +++++++++++++ README.md | 23 ++++++++++++++++++++++- chat.cpp | 2 +- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 5eb1ff1b873f..699f76c4ae91 100644 --- a/.gitignore +++ b/.gitignore @@ -15,9 +15,22 @@ build-sanitize-addr/ build-sanitize-thread/ models/* +*.bin /main /quantize arm_neon.h compile_commands.json + +# Windows CMake files +*.vcxproj +*.filters +*.cmake +*.sln +x64/ +Debug/ +Release/ +CMakeFiles/ +CMakeCache.txt +*.dir/ diff --git a/README.md b/README.md index 14b294f1a56b..55786bb9b39c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ This combines the [LLaMA foundation model](https://github.com/facebookresearch/l ## Get started -``` +```sh git clone https://github.com/antimatter15/alpaca.cpp cd alpaca.cpp @@ -34,6 +34,27 @@ Save the `ggml-alpaca-7b-q4.bin` file in the same directory as your `./chat` exe The weights are based on the published fine-tunes from `alpaca-lora`, converted back into a pytorch checkpoint with a [modified script](https://github.com/tloen/alpaca-lora/pull/19) and then quantized with llama.cpp the regular way. +## Windows Setup + +- Download and install CMake: +- Download and install `git`. If you've never used git before, consider a GUI client like +- Clone this repo using your git client of choice (for GitHub Desktop, go to File -> Clone repository -> From URL and paste `https://github.com/antimatter15/alpaca.cpp` in as the URL) +- Open a Windows Terminal inside the folder you cloned the repository to +- Run the following commands one by one: + +```ps1 +cmake . +cmake --build . --config Release +``` + +- Download the weights via any of the links in "Get started" above, and save the file as `ggml-alpaca-7b-q4.bin` in the main Alpaca directory. +- In the terminal window, run this command: +```ps1 +.\Release\chat.exe +``` +- (You can add other launch options like `--n 8` as preferred onto the same line) +- You can now type to the AI in the terminal and it will reply. Enjoy! + ## Credit This combines [Facebook's LLaMA](https://github.com/facebookresearch/llama), [Stanford Alpaca](https://crfm.stanford.edu/2023/03/13/alpaca.html), [alpaca-lora](https://github.com/tloen/alpaca-lora) and [corresponding weights](https://huggingface.co/tloen/alpaca-lora-7b/tree/main) by Eric Wang (which uses [Jason Phang's implementation of LLaMA](https://github.com/huggingface/transformers/pull/21955) on top of Hugging Face Transformers), and [llama.cpp](https://github.com/ggerganov/llama.cpp) by Georgi Gerganov. The chat implementation is based on Matvey Soloviev's [Interactive Mode](https://github.com/ggerganov/llama.cpp/pull/61) for llama.cpp. Inspired by [Simon Willison's](https://til.simonwillison.net/llms/llama-7b-m2) getting started guide for LLaMA. diff --git a/chat.cpp b/chat.cpp index 885d1f69a1e5..5acb2bc95284 100644 --- a/chat.cpp +++ b/chat.cpp @@ -915,7 +915,7 @@ int main(int argc, char ** argv) { #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32) " - Press Ctrl+C to interject at any time.\n" #endif - " - Press Return to return control to LLaMa.\n" + " - Press Return to return control to LLaMA.\n" " - If you want to submit another line, end your input in '\\'.\n"); } From e7bdee6cc9fb1d7a9d2cad5dd315333b3f0d9e51 Mon Sep 17 00:00:00 2001 From: anzz1 Date: Fri, 17 Mar 2023 19:17:59 +0200 Subject: [PATCH 05/26] CI fine tuning --- .github/workflows/build.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 034ab4de90bf..4387bafd47b8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,9 @@ on: types: [opened, synchronize, edited, reopened, review_requested, ready_for_review] paths: ['CMakeLists.txt', 'Makefile', '**.h', '*.c', '**.cpp'] +env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + jobs: ubuntu-latest: runs-on: ubuntu-latest @@ -76,7 +79,7 @@ jobs: id: pack_artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} run: | - 7z a alpaca-bin-win-x64-${{ steps.commit.outputs.short }}.zip .\build\Release\* + 7z a alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip .\build\Release\* - name: Create release id: create_release @@ -85,7 +88,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ steps.commit.outputs.short }} + tag_name: ${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }} - name: Upload release id: upload_release @@ -95,8 +98,8 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: .\alpaca-bin-win-x64-${{ steps.commit.outputs.short }}.zip - asset_name: alpaca-bin-win-x64-${{ steps.commit.outputs.short }}.zip + asset_path: .\alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip + asset_name: alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip asset_content_type: application/octet-stream # ubuntu-latest-gcc: From d0f855a8df4a2ebe72d142cd343161b29a75f9ae Mon Sep 17 00:00:00 2001 From: Kevin Kwok Date: Fri, 17 Mar 2023 11:13:47 -0700 Subject: [PATCH 06/26] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 55786bb9b39c..0ca2e3812c85 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,12 @@ cmake --build . --config Release - (You can add other launch options like `--n 8` as preferred onto the same line) - You can now type to the AI in the terminal and it will reply. Enjoy! +## 13B + +TODO + +Torrent: `magnet:?xt=urn:btih:f3cf71b172129d6b5abccab393bc32253fac8159&dn=ggml-alpaca-13b-q4.bin&tr=udp%3A%2F%http://2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%https://t.co/zenhelfwRd%3A6969%2Fannounce&tr=https%3A%2F%https://t.co/zenhelfwRd%3A443%2Fannounce&tr=udp%3A%2F%https://t.co/RRAn1X65wE%3A6969%2Fannounce&tr=udp%3A%2F%https://t.co/uTXBeTLUMa%3A2810%2Fannounce` + ## Credit This combines [Facebook's LLaMA](https://github.com/facebookresearch/llama), [Stanford Alpaca](https://crfm.stanford.edu/2023/03/13/alpaca.html), [alpaca-lora](https://github.com/tloen/alpaca-lora) and [corresponding weights](https://huggingface.co/tloen/alpaca-lora-7b/tree/main) by Eric Wang (which uses [Jason Phang's implementation of LLaMA](https://github.com/huggingface/transformers/pull/21955) on top of Hugging Face Transformers), and [llama.cpp](https://github.com/ggerganov/llama.cpp) by Georgi Gerganov. The chat implementation is based on Matvey Soloviev's [Interactive Mode](https://github.com/ggerganov/llama.cpp/pull/61) for llama.cpp. Inspired by [Simon Willison's](https://til.simonwillison.net/llms/llama-7b-m2) getting started guide for LLaMA. From 7cd84a7027f4c60eb6fa7076333db47e35a169a9 Mon Sep 17 00:00:00 2001 From: Kevin Kwok Date: Fri, 17 Mar 2023 22:57:27 -0700 Subject: [PATCH 07/26] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0ca2e3812c85..c5669646663c 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ cmake --build . --config Release TODO -Torrent: `magnet:?xt=urn:btih:f3cf71b172129d6b5abccab393bc32253fac8159&dn=ggml-alpaca-13b-q4.bin&tr=udp%3A%2F%http://2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%https://t.co/zenhelfwRd%3A6969%2Fannounce&tr=https%3A%2F%https://t.co/zenhelfwRd%3A443%2Fannounce&tr=udp%3A%2F%https://t.co/RRAn1X65wE%3A6969%2Fannounce&tr=udp%3A%2F%https://t.co/uTXBeTLUMa%3A2810%2Fannounce` +Torrent: `magnet:?xt=urn:btih:053b3d54d2e77ff020ebddf51dad681f2a651071&dn=ggml-alpaca-13b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce` ## Credit From 97d327e1bf6c9d166a38feeaf01d728a566e60b8 Mon Sep 17 00:00:00 2001 From: Kevin Kwok Date: Fri, 17 Mar 2023 23:43:09 -0700 Subject: [PATCH 08/26] Update chat.cpp --- chat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chat.cpp b/chat.cpp index 5ee86ce78667..4bdd214ad7d5 100644 --- a/chat.cpp +++ b/chat.cpp @@ -30,7 +30,7 @@ // determine number of model parts based on the dimension static const std::map LLAMA_N_PARTS = { { 4096, 1 }, - { 5120, 2 }, + { 5120, 1 }, { 6656, 4 }, { 8192, 8 }, }; From 96e0519ae1bd42412872607abacc1bc60e4df136 Mon Sep 17 00:00:00 2001 From: antimatter15 Date: Fri, 17 Mar 2023 23:46:31 -0700 Subject: [PATCH 09/26] extending context window --- README.md | 5 +++++ chat.cpp | 1 + 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index c5669646663c..c8d6df9fa219 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,11 @@ TODO Torrent: `magnet:?xt=urn:btih:053b3d54d2e77ff020ebddf51dad681f2a651071&dn=ggml-alpaca-13b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce` + +``` +./chat -m ggml-alpaca-13b-q4.bin +``` + ## Credit This combines [Facebook's LLaMA](https://github.com/facebookresearch/llama), [Stanford Alpaca](https://crfm.stanford.edu/2023/03/13/alpaca.html), [alpaca-lora](https://github.com/tloen/alpaca-lora) and [corresponding weights](https://huggingface.co/tloen/alpaca-lora-7b/tree/main) by Eric Wang (which uses [Jason Phang's implementation of LLaMA](https://github.com/huggingface/transformers/pull/21955) on top of Hugging Face Transformers), and [llama.cpp](https://github.com/ggerganov/llama.cpp) by Georgi Gerganov. The chat implementation is based on Matvey Soloviev's [Interactive Mode](https://github.com/ggerganov/llama.cpp/pull/61) for llama.cpp. Inspired by [Simon Willison's](https://til.simonwillison.net/llms/llama-7b-m2) getting started guide for LLaMA. diff --git a/chat.cpp b/chat.cpp index 4bdd214ad7d5..7ed8ea4c7b7c 100644 --- a/chat.cpp +++ b/chat.cpp @@ -798,6 +798,7 @@ int main(int argc, char ** argv) { params.temp = 0.1f; params.top_p = 0.95f; + params.n_ctx = 2048; params.interactive = true; params.interactive_start = true; params.use_color = true; From e95e64bd49dcfbbdf880f5f94f42b13fa8437694 Mon Sep 17 00:00:00 2001 From: thement <40525767+thement@users.noreply.github.com> Date: Fri, 17 Mar 2023 21:05:58 +0100 Subject: [PATCH 10/26] Implement non-greedy tokenizer that tries to maximize token lengths (#242) * Implement non-greedy tokenizer that tries to maximize token lengths * Insert single space in front of the prompt - this is to match original llama tokenizer behavior --------- Co-authored-by: Jakub Horak --- chat.cpp | 2 ++ utils.cpp | 68 ++++++++++++++++++++++++++++++++++--------------------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/chat.cpp b/chat.cpp index 7ed8ea4c7b7c..6d84af20d445 100644 --- a/chat.cpp +++ b/chat.cpp @@ -852,6 +852,8 @@ int main(int argc, char ** argv) { std::vector logits; + // Add a space in front of the first character to match OG llama tokenizer behavior + params.prompt.insert(0, 1, ' '); // tokenize the prompt std::vector embd_inp;// = ::llama_tokenize(vocab, params.prompt, true); diff --git a/utils.cpp b/utils.cpp index aa3ad1053da0..d739b5d48923 100644 --- a/utils.cpp +++ b/utils.cpp @@ -275,41 +275,57 @@ std::vector gpt_tokenize(const gpt_vocab & vocab, const std::stri return tokens; } +// TODO: Calculate this constant from the vocabulary +#define MAX_TOKEN_LEN 18 +// SentencePiece implementation after https://guillaume-be.github.io/2020-05-30/sentence_piece std::vector llama_tokenize(const gpt_vocab & vocab, const std::string & text, bool bos) { - //auto res = gpt_tokenize(vocab, text); - - //if (bos) { - // res.insert(res.begin(), 1); // TODO: replace with vocab.bos - //} - std::vector res; - - if (bos) { - res.push_back(1); // TODO: replace with vocab.bos - } - - //find the longest token that matches the text - int pos = 0; - while (true) { - int l = 0; - int t = 0; - for (const auto & kv : vocab.id_to_token) { - if (kv.second.size() < l) continue; - if (kv.second.size() > text.size() - pos) continue; - if (text.substr(pos, kv.second.size()) == kv.second) { - l = kv.second.size(); - t = kv.first; + std::vector score; + std::vector prev; + int len = text.length(); + + score.resize(len + 1); + prev.resize(len + 1); + + // Forward pass + for (int i = 0; i < len; i++) { + int max_len = std::min(len - i, MAX_TOKEN_LEN); + for (int sub_len = 1; sub_len <= len - i; sub_len++) { + auto sub = text.substr(i, sub_len); + auto token = vocab.token_to_id.find(sub); + if (token != vocab.token_to_id.end()) { + int token_score = sub.length() * sub.length(); + int local_score = score[i] + token_score; + int next = i + sub_len; + if (score[next] < local_score) { + score[next] = local_score; + prev[next] = (*token).second; + } } } + } - if (l == 0) { - break; + // Backward pass + int i = len; + while (i > 0) { + gpt_vocab::id token_id = prev[i]; + if (token_id == 0) { + // TODO: Return error or something more meaningful + printf("failed to tokenize string!\n"); + break; } + res.push_back(token_id); + auto token = (*vocab.id_to_token.find(token_id)).second; + i -= token.length(); + } - res.push_back(t); - pos += l; + if (bos) { + res.push_back(1); // TODO: replace with vocab.bos } + // Pieces are in reverse order so correct that + std::reverse(res.begin(), res.end()); + return res; } From 1cb9215e5df342d26e399ec1405e5751c24ad572 Mon Sep 17 00:00:00 2001 From: antimatter15 Date: Sat, 18 Mar 2023 00:19:52 -0700 Subject: [PATCH 11/26] removing random prompt generation --- chat.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chat.cpp b/chat.cpp index 6d84af20d445..596a806d3bf2 100644 --- a/chat.cpp +++ b/chat.cpp @@ -815,9 +815,9 @@ int main(int argc, char ** argv) { fprintf(stderr, "%s: seed = %d\n", __func__, params.seed); std::mt19937 rng(params.seed); - if (params.prompt.empty()) { - params.prompt = gpt_random_prompt(rng); - } + // if (params.prompt.empty()) { + // params.prompt = gpt_random_prompt(rng); + // } // params.prompt = R"(// this function checks if the number n is prime //bool is_prime(int n) {)"; @@ -853,7 +853,7 @@ int main(int argc, char ** argv) { std::vector logits; // Add a space in front of the first character to match OG llama tokenizer behavior - params.prompt.insert(0, 1, ' '); + // params.prompt.insert(0, 1, ' '); // tokenize the prompt std::vector embd_inp;// = ::llama_tokenize(vocab, params.prompt, true); From 501a8e19d98c6d442923035c7f275df71ee0a900 Mon Sep 17 00:00:00 2001 From: antimatter15 Date: Sat, 18 Mar 2023 00:28:05 -0700 Subject: [PATCH 12/26] adding to credit section --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c8d6df9fa219..65e537cbc741 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ cmake --build . --config Release ## 13B -TODO +TODO: write more docs here (PRs welcome) Torrent: `magnet:?xt=urn:btih:053b3d54d2e77ff020ebddf51dad681f2a651071&dn=ggml-alpaca-13b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce` @@ -68,7 +68,7 @@ Torrent: `magnet:?xt=urn:btih:053b3d54d2e77ff020ebddf51dad681f2a651071&dn=ggml-a ## Credit -This combines [Facebook's LLaMA](https://github.com/facebookresearch/llama), [Stanford Alpaca](https://crfm.stanford.edu/2023/03/13/alpaca.html), [alpaca-lora](https://github.com/tloen/alpaca-lora) and [corresponding weights](https://huggingface.co/tloen/alpaca-lora-7b/tree/main) by Eric Wang (which uses [Jason Phang's implementation of LLaMA](https://github.com/huggingface/transformers/pull/21955) on top of Hugging Face Transformers), and [llama.cpp](https://github.com/ggerganov/llama.cpp) by Georgi Gerganov. The chat implementation is based on Matvey Soloviev's [Interactive Mode](https://github.com/ggerganov/llama.cpp/pull/61) for llama.cpp. Inspired by [Simon Willison's](https://til.simonwillison.net/llms/llama-7b-m2) getting started guide for LLaMA. +This combines [Facebook's LLaMA](https://github.com/facebookresearch/llama), [Stanford Alpaca](https://crfm.stanford.edu/2023/03/13/alpaca.html), [alpaca-lora](https://github.com/tloen/alpaca-lora) and [corresponding weights](https://huggingface.co/tloen/alpaca-lora-7b/tree/main) by Eric Wang (which uses [Jason Phang's implementation of LLaMA](https://github.com/huggingface/transformers/pull/21955) on top of Hugging Face Transformers), and [llama.cpp](https://github.com/ggerganov/llama.cpp) by Georgi Gerganov. The chat implementation is based on Matvey Soloviev's [Interactive Mode](https://github.com/ggerganov/llama.cpp/pull/61) for llama.cpp. Inspired by [Simon Willison's](https://til.simonwillison.net/llms/llama-7b-m2) getting started guide for LLaMA. [Andy Matuschak](https://twitter.com/andy_matuschak/status/1636769182066053120)'s thread on adapting this to 13B, using fine tuning weights by [Sam Witteveen](https://huggingface.co/samwit/alpaca13B-lora). ## Disclaimer From 7e126618c41a12f2ccd8a7ad2ba2c14274aa60cd Mon Sep 17 00:00:00 2001 From: antimatter15 Date: Sat, 18 Mar 2023 00:34:53 -0700 Subject: [PATCH 13/26] ci releases for mac and linux --- .github/workflows/build.yml | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4387bafd47b8..9f9a58c81c38 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,6 +36,24 @@ jobs: run: | make + - name: Pack artifacts + id: pack_artifacts + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + run: | + zip alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-linux-x64.zip chat + + - name: Upload release + id: upload_release + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: .\alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-linux-x64.zip + asset_name: alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-linux-x64.zip + asset_content_type: application/octet-stream + macOS-latest: runs-on: macOS-latest @@ -54,6 +72,24 @@ jobs: run: | make + - name: Pack artifacts + id: pack_artifacts + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + run: | + zip alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-mac-x64.zip chat + + - name: Upload release + id: upload_release + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: .\alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-mac-x64.zip + asset_name: alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-mac-x64.zip + asset_content_type: application/octet-stream + windows-latest: runs-on: windows-latest From 1c62e3598419e23ec91664cce66d8dcdc806eb44 Mon Sep 17 00:00:00 2001 From: antimatter15 Date: Sat, 18 Mar 2023 00:37:34 -0700 Subject: [PATCH 14/26] create release --- .github/workflows/build.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9f9a58c81c38..bff3e5609906 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,6 +41,15 @@ jobs: if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} run: | zip alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-linux-x64.zip chat + + - name: Create release + id: create_release + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + uses: zendesk/action-create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }} - name: Upload release id: upload_release @@ -72,11 +81,21 @@ jobs: run: | make + - name: Pack artifacts id: pack_artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} run: | zip alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-mac-x64.zip chat + + - name: Create release + id: create_release + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + uses: zendesk/action-create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }} - name: Upload release id: upload_release From 3f7d187b6b3338bc32d4f60029ab40fd38dbeeb5 Mon Sep 17 00:00:00 2001 From: antimatter15 Date: Sat, 18 Mar 2023 00:55:00 -0700 Subject: [PATCH 15/26] more copying stuff --- .github/workflows/build.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bff3e5609906..77b2586c4779 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,6 +36,11 @@ jobs: run: | make + - name: Set commit hash variables + id: commit + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + uses: pr-mpt/actions-commit-hash@v2 + - name: Pack artifacts id: pack_artifacts if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} @@ -81,6 +86,10 @@ jobs: run: | make + - name: Set commit hash variables + id: commit + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + uses: pr-mpt/actions-commit-hash@v2 - name: Pack artifacts id: pack_artifacts From 564b861bac1971c20cd0dfff9568787d9e6b31e6 Mon Sep 17 00:00:00 2001 From: antimatter15 Date: Sat, 18 Mar 2023 01:06:44 -0700 Subject: [PATCH 16/26] archiving artifacts --- .github/workflows/build.yml | 88 ++++++++++++++----------------------- 1 file changed, 32 insertions(+), 56 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 77b2586c4779..4aa2bdef5b2a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,37 +36,13 @@ jobs: run: | make - - name: Set commit hash variables - id: commit - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} - uses: pr-mpt/actions-commit-hash@v2 - - - name: Pack artifacts - id: pack_artifacts - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} - run: | - zip alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-linux-x64.zip chat - - - name: Create release - id: create_release - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} - uses: zendesk/action-create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Archive production artifacts + uses: actions/upload-artifact@v3 with: - tag_name: ${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }} + name: ubuntu + path: | + chat - - name: Upload release - id: upload_release - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: .\alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-linux-x64.zip - asset_name: alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-linux-x64.zip - asset_content_type: application/octet-stream macOS-latest: runs-on: macOS-latest @@ -86,37 +62,37 @@ jobs: run: | make - - name: Set commit hash variables - id: commit - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} - uses: pr-mpt/actions-commit-hash@v2 + - name: Archive production artifacts + uses: actions/upload-artifact@v3 + with: + name: macos + path: | + chat - - name: Pack artifacts - id: pack_artifacts - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + macOS-arm64: + runs-on: macOS-arm64 + + steps: + - name: Clone + id: checkout + uses: actions/checkout@v1 + + - name: Dependencies + id: depends run: | - zip alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-mac-x64.zip chat - - - name: Create release - id: create_release - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} - uses: zendesk/action-create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }} + brew update - - name: Upload release - id: upload_release - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Build + id: make_build + run: | + make + + - name: Archive production artifacts + uses: actions/upload-artifact@v3 with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: .\alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-mac-x64.zip - asset_name: alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-mac-x64.zip - asset_content_type: application/octet-stream + name: macos + path: | + chat windows-latest: runs-on: windows-latest From ddc4e24cb85fb4a05d9411e24b344974fb9f8cf4 Mon Sep 17 00:00:00 2001 From: antimatter15 Date: Sat, 18 Mar 2023 01:11:02 -0700 Subject: [PATCH 17/26] maybe macos-arm64 is case sensitive --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4aa2bdef5b2a..48ec93b9bc2d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -69,8 +69,8 @@ jobs: path: | chat - macOS-arm64: - runs-on: macOS-arm64 + macos-arm64: + runs-on: macos-arm64 steps: - name: Clone From 4a524c51ba42254fdae63abcf26d38f64dd4fc28 Mon Sep 17 00:00:00 2001 From: antimatter15 Date: Sat, 18 Mar 2023 01:15:51 -0700 Subject: [PATCH 18/26] commenting out aarch --- .github/workflows/build.yml | 40 ++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 48ec93b9bc2d..d206f21bbeaf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -69,30 +69,30 @@ jobs: path: | chat - macos-arm64: - runs-on: macos-arm64 + # macos-arm64: + # runs-on: macos-arm64 - steps: - - name: Clone - id: checkout - uses: actions/checkout@v1 + # steps: + # - name: Clone + # id: checkout + # uses: actions/checkout@v1 - - name: Dependencies - id: depends - run: | - brew update + # - name: Dependencies + # id: depends + # run: | + # brew update - - name: Build - id: make_build - run: | - make + # - name: Build + # id: make_build + # run: | + # make - - name: Archive production artifacts - uses: actions/upload-artifact@v3 - with: - name: macos - path: | - chat + # - name: Archive production artifacts + # uses: actions/upload-artifact@v3 + # with: + # name: macos + # path: | + # chat windows-latest: runs-on: windows-latest From a83e2e7a2447d782ed41810535a94d4c73b3dc8f Mon Sep 17 00:00:00 2001 From: Rupesh Sreeraman Date: Sat, 18 Mar 2023 16:41:20 +0530 Subject: [PATCH 19/26] Windows console ANSI color issue fixed --- chat.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/chat.cpp b/chat.cpp index 596a806d3bf2..f2ccf12fcbce 100644 --- a/chat.cpp +++ b/chat.cpp @@ -16,6 +16,7 @@ #include #elif defined (_WIN32) #include +#include #endif #define ANSI_COLOR_RED "\x1b[31m" @@ -886,6 +887,11 @@ int main(int argc, char ** argv) { sigaction(SIGINT, &sigint_action, NULL); #elif defined (_WIN32) signal(SIGINT, sigint_handler); + //Windows console ANSI color fix + HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD mode; + GetConsoleMode(hConsole, &mode); + SetConsoleMode(hConsole, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); #endif fprintf(stderr, "%s: interactive mode on.\n", __func__); From bb60fdaf32328651e049ff22a7ab43fb6575bbc1 Mon Sep 17 00:00:00 2001 From: Marius Ciocanel Date: Sat, 18 Mar 2023 13:10:25 +0000 Subject: [PATCH 20/26] Update command for downloading the weights to use `curl` `curl` is preinstalled on macOS and the new command is equivalent to the `wget` version but avoids having to install wget --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 65e537cbc741..d7358dad076f 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,9 @@ Alternatively you can download them with IPFS. ``` # any of these will work -wget -O ggml-alpaca-7b-q4.bin -c https://gateway.estuary.tech/gw/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC -wget -O ggml-alpaca-7b-q4.bin -c https://ipfs.io/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC -wget -O ggml-alpaca-7b-q4.bin -c https://cloudflare-ipfs.com/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC +curl -o ggml-alpaca-7b-q4.bin -C - https://gateway.estuary.tech/gw/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC +curl -o ggml-alpaca-7b-q4.bin -C - https://ipfs.io/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC +curl -o ggml-alpaca-7b-q4.bin -C - https://cloudflare-ipfs.com/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC ``` Save the `ggml-alpaca-7b-q4.bin` file in the same directory as your `./chat` executable. From c0e1cb53c7220f673b3ae1b8a3927fcb906c22af Mon Sep 17 00:00:00 2001 From: Nato Boram Date: Sat, 18 Mar 2023 14:45:10 -0400 Subject: [PATCH 21/26] =?UTF-8?q?=F0=9F=99=88=20Add=20output=20`chat`=20to?= =?UTF-8?q?=20`.gitignore`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 699f76c4ae91..da9e6bed8008 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +/chat + *.o *.a .cache/ From f69062f68e7bffb6060ca9b9d778c14fa889b863 Mon Sep 17 00:00:00 2001 From: anzz1 Date: Sat, 18 Mar 2023 21:51:12 +0200 Subject: [PATCH 22/26] Do the windows ANSI color fix properly --- chat.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/chat.cpp b/chat.cpp index f2ccf12fcbce..6524813727bd 100644 --- a/chat.cpp +++ b/chat.cpp @@ -887,11 +887,12 @@ int main(int argc, char ** argv) { sigaction(SIGINT, &sigint_action, NULL); #elif defined (_WIN32) signal(SIGINT, sigint_handler); - //Windows console ANSI color fix - HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); - DWORD mode; - GetConsoleMode(hConsole, &mode); - SetConsoleMode(hConsole, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); + + // Windows console ANSI color fix + DWORD mode; + HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); + if (hConsole && hConsole != INVALID_HANDLE_VALUE && GetConsoleMode(hConsole, &mode)) + SetConsoleMode(hConsole, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); #endif fprintf(stderr, "%s: interactive mode on.\n", __func__); From 1b19586681c371844492b26aa4bcf1f157bf863f Mon Sep 17 00:00:00 2001 From: anzz1 Date: Sat, 18 Mar 2023 22:21:58 +0200 Subject: [PATCH 23/26] Init the var too --- chat.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chat.cpp b/chat.cpp index 6524813727bd..38b39771ad98 100644 --- a/chat.cpp +++ b/chat.cpp @@ -889,7 +889,7 @@ int main(int argc, char ** argv) { signal(SIGINT, sigint_handler); // Windows console ANSI color fix - DWORD mode; + DWORD mode = 0; HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); if (hConsole && hConsole != INVALID_HANDLE_VALUE && GetConsoleMode(hConsole, &mode)) SetConsoleMode(hConsole, mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING); From e83984f583ec865ed445cf08ca9e96146aaa4ac7 Mon Sep 17 00:00:00 2001 From: anzz1 Date: Mon, 20 Mar 2023 02:31:42 +0200 Subject: [PATCH 24/26] add cached torrent links for people having trouble with magnet links, as torrents always work --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d7358dad076f..a1ecbe78cef8 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,11 @@ make chat ./chat ``` -You can download the weights for `ggml-alpaca-7b-q4.bin` with BitTorrent `magnet:?xt=urn:btih:5aaceaec63b03e51a98f04fd5c42320b2a033010&dn=ggml-alpaca-7b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce` +You can download the weights for `ggml-alpaca-7b-q4.bin` with BitTorrent: + +magnet: `magnet:?xt=urn:btih:5aaceaec63b03e51a98f04fd5c42320b2a033010&dn=ggml-alpaca-7b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce` +torrent: https://btcache.me/torrent/5AACEAEC63B03E51A98F04FD5C42320B2A033010 +torrent: https://torrage.info/torrent.php?h=5aaceaec63b03e51a98f04fd5c42320b2a033010 Alternatively you can download them with IPFS. @@ -59,7 +63,11 @@ cmake --build . --config Release TODO: write more docs here (PRs welcome) -Torrent: `magnet:?xt=urn:btih:053b3d54d2e77ff020ebddf51dad681f2a651071&dn=ggml-alpaca-13b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce` +You can download the weights for `ggml-alpaca-13b-q4.bin` with BitTorrent: + +magnet: `magnet:?xt=urn:btih:053b3d54d2e77ff020ebddf51dad681f2a651071&dn=ggml-alpaca-13b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce` +torrent: https://btcache.me/torrent/053B3D54D2E77FF020EBDDF51DAD681F2A651071 +torrent: https://torrage.info/torrent.php?h=053b3d54d2e77ff020ebddf51dad681f2a651071 ``` From 99f3908c515c73c7acbda307565234f33ec9738d Mon Sep 17 00:00:00 2001 From: Kevin Kwok Date: Mon, 20 Mar 2023 03:41:11 -0700 Subject: [PATCH 25/26] Automatically Generate Releases for Mac, Linux, Windows (#81) * trying to build for arm * cross compiling? * only mac * gh actions * fix * fixing dash * ensure that its executable * adding back windows * unindent * typo * oops * runs on * more release stuff * more release stuff * fix workflow * adding back linux builds * conditional stuff --- .github/workflows/build.yml | 322 ++++++++++-------------------------- Makefile | 7 + 2 files changed, 94 insertions(+), 235 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index d206f21bbeaf..d185e1ac5c59 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,15 +36,18 @@ jobs: run: | make + - name: Zip executables + run: zip alpaca-linux.zip chat + - name: Archive production artifacts uses: actions/upload-artifact@v3 with: - name: ubuntu + name: linux path: | - chat + alpaca-linux.zip - macOS-latest: + macos-latest: runs-on: macOS-latest steps: @@ -60,39 +63,45 @@ jobs: - name: Build id: make_build run: | - make + make chat_mac + + - name: Codesign executable + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + env: + MACOS_CERTIFICATE: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_P12_BASE64 }} + MACOS_CERTIFICATE_PWD: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_PASSWORD }} + KEYCHAIN_PWD: ${{ secrets.KEYCHAIN_PASSWORD }} + MACOS_CERT_ID: ${{ secrets.APPLE_DEVELOPER_CERTIFICATE_ID }} + + run: | + echo $MACOS_CERTIFICATE | base64 --decode > certificate.p12 + security create-keychain -p $KEYCHAIN_PWD build.keychain + security default-keychain -s build.keychain + security unlock-keychain -p $KEYCHAIN_PWD build.keychain + security import certificate.p12 -k build.keychain -P $MACOS_CERTIFICATE_PWD -T /usr/bin/codesign + security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k $KEYCHAIN_PWD build.keychain + /usr/bin/codesign --options runtime --force -s $MACOS_CERT_ID ./chat_mac -v + + - name: Zip executables + run: zip alpaca-mac.zip chat_mac + + - name: Notarize executables + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + env: + PROD_MACOS_NOTARIZATION_APPLE_ID: ${{ secrets.AC_USERNAME }} + PROD_MACOS_NOTARIZATION_PWD: ${{ secrets.AC_PASSWORD }} + PROD_MACOS_NOTARIZATION_TEAM_ID: ${{ secrets.PROD_MACOS_NOTARIZATION_TEAM_ID }} + run: | + xcrun notarytool store-credentials "notarytool-profile" --apple-id "$PROD_MACOS_NOTARIZATION_APPLE_ID" --team-id "$PROD_MACOS_NOTARIZATION_TEAM_ID" --password "$PROD_MACOS_NOTARIZATION_PWD" + xcrun notarytool submit "alpaca-mac.zip" --keychain-profile "notarytool-profile" --wait - name: Archive production artifacts uses: actions/upload-artifact@v3 with: name: macos path: | - chat - - # macos-arm64: - # runs-on: macos-arm64 - - # steps: - # - name: Clone - # id: checkout - # uses: actions/checkout@v1 - - # - name: Dependencies - # id: depends - # run: | - # brew update - - # - name: Build - # id: make_build - # run: | - # make + alpaca-mac.zip - # - name: Archive production artifacts - # uses: actions/upload-artifact@v3 - # with: - # name: macos - # path: | - # chat windows-latest: runs-on: windows-latest @@ -110,227 +119,70 @@ jobs: cmake .. cmake --build . --config Release - - name: Set commit hash variables - id: commit - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} - uses: pr-mpt/actions-commit-hash@v2 - - name: Pack artifacts id: pack_artifacts - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} run: | - 7z a alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip .\build\Release\* + 7z a alpaca-win.zip .\build\Release\* + + - name: Archive production artifacts + uses: actions/upload-artifact@v3 + with: + name: windows + path: | + alpaca-win.zip + + + release: + runs-on: ubuntu-latest + if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + needs: + - windows-latest + - macos-latest + - ubuntu-latest + + steps: + - name: Download all workflow run artifacts + uses: actions/download-artifact@v3 + + - name: Set commit hash variables + id: commit + uses: pr-mpt/actions-commit-hash@v2 - name: Create release id: create_release - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} uses: zendesk/action-create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: ${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }} + tag_name: ${{ steps.commit.outputs.short }} - - name: Upload release - id: upload_release - if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }} + - name: Upload windows release uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: .\alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip - asset_name: alpaca-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-x64.zip + asset_path: windows/alpaca-win.zip + asset_name: alpaca-win.zip asset_content_type: application/octet-stream -# ubuntu-latest-gcc: -# runs-on: ubuntu-latest -# -# strategy: -# matrix: -# build: [Debug, Release] -# -# steps: -# - name: Clone -# uses: actions/checkout@v1 -# -# - name: Dependencies -# run: | -# sudo apt-get update -# sudo apt-get install build-essential -# sudo apt-get install cmake -# -# - name: Configure -# run: cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }} -# -# - name: Build -# run: | -# make -# -# ubuntu-latest-clang: -# runs-on: ubuntu-latest -# -# strategy: -# matrix: -# build: [Debug, Release] -# -# steps: -# - name: Clone -# uses: actions/checkout@v1 -# -# - name: Dependencies -# run: | -# sudo apt-get update -# sudo apt-get install build-essential -# sudo apt-get install cmake -# -# - name: Configure -# run: cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }} -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -# -# - name: Build -# run: | -# make -# -# ubuntu-latest-gcc-sanitized: -# runs-on: ubuntu-latest -# -# strategy: -# matrix: -# sanitizer: [ADDRESS, THREAD, UNDEFINED] -# -# steps: -# - name: Clone -# uses: actions/checkout@v1 -# -# - name: Dependencies -# run: | -# sudo apt-get update -# sudo apt-get install build-essential -# sudo apt-get install cmake -# -# - name: Configure -# run: cmake . -DCMAKE_BUILD_TYPE=Debug -DLLAMA_SANITIZE_${{ matrix.sanitizer }}=ON -# -# - name: Build -# run: | -# make -# -# windows: -# runs-on: windows-latest -# -# strategy: -# matrix: -# build: [Release] -# arch: [Win32, x64] -# include: -# - arch: Win32 -# s2arc: x86 -# - arch: x64 -# s2arc: x64 -# -# steps: -# - name: Clone -# uses: actions/checkout@v1 -# -# - name: Add msbuild to PATH -# uses: microsoft/setup-msbuild@v1 -# -# - name: Configure -# run: > -# cmake -S . -B ./build -A ${{ matrix.arch }} -# -DCMAKE_BUILD_TYPE=${{ matrix.build }} -# -# - name: Build -# run: | -# cd ./build -# msbuild ALL_BUILD.vcxproj -t:build -p:configuration=${{ matrix.build }} -p:platform=${{ matrix.arch }} -# -# - name: Upload binaries -# uses: actions/upload-artifact@v1 -# with: -# name: llama-bin-${{ matrix.arch }} -# path: build/bin/${{ matrix.build }} -# -# windows-blas: -# runs-on: windows-latest -# -# strategy: -# matrix: -# build: [Release] -# arch: [Win32, x64] -# blas: [ON] -# include: -# - arch: Win32 -# obzip: https://github.com/xianyi/OpenBLAS/releases/download/v0.3.21/OpenBLAS-0.3.21-x86.zip -# s2arc: x86 -# - arch: x64 -# obzip: https://github.com/xianyi/OpenBLAS/releases/download/v0.3.21/OpenBLAS-0.3.21-x64.zip -# s2arc: x64 -# -# steps: -# - name: Clone -# uses: actions/checkout@v1 -# -# - name: Add msbuild to PATH -# uses: microsoft/setup-msbuild@v1 -# -# - name: Fetch OpenBLAS -# if: matrix.blas == 'ON' -# run: | -# C:/msys64/usr/bin/wget.exe -qO blas.zip ${{ matrix.obzip }} -# 7z x blas.zip -oblas -y -# copy blas/include/cblas.h . -# copy blas/include/openblas_config.h . -# echo "blasdir=$env:GITHUB_WORKSPACE/blas" >> $env:GITHUB_ENV -# -# - name: Configure -# run: > -# cmake -S . -B ./build -A ${{ matrix.arch }} -# -DCMAKE_BUILD_TYPE=${{ matrix.build }} -# -DLLAMA_SUPPORT_OPENBLAS=${{ matrix.blas }} -# -DCMAKE_LIBRARY_PATH="$env:blasdir/lib" -# -# - name: Build -# run: | -# cd ./build -# msbuild ALL_BUILD.vcxproj -t:build -p:configuration=${{ matrix.build }} -p:platform=${{ matrix.arch }} -# -# - name: Copy libopenblas.dll -# if: matrix.blas == 'ON' -# run: copy "$env:blasdir/bin/libopenblas.dll" build/bin/${{ matrix.build }} -# -# - name: Upload binaries -# if: matrix.blas == 'ON' -# uses: actions/upload-artifact@v1 -# with: -# name: llama-blas-bin-${{ matrix.arch }} -# path: build/bin/${{ matrix.build }} -# -# emscripten: -# runs-on: ubuntu-latest -# -# strategy: -# matrix: -# build: [Release] -# -# steps: -# - name: Clone -# uses: actions/checkout@v1 -# -# - name: Dependencies -# run: | -# wget -q https://github.com/emscripten-core/emsdk/archive/master.tar.gz -# tar -xvf master.tar.gz -# emsdk-master/emsdk update -# emsdk-master/emsdk install latest -# emsdk-master/emsdk activate latest -# -# - name: Configure -# run: echo "tmp" -# -# - name: Build -# run: | -# pushd emsdk-master -# source ./emsdk_env.sh -# popd -# emcmake cmake . -DCMAKE_BUILD_TYPE=${{ matrix.build }} -# make + - name: Upload mac release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: macos/alpaca-mac.zip + asset_name: alpaca-mac.zip + asset_content_type: application/octet-stream + + - name: Upload linux release + + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: linux/alpaca-linux.zip + asset_name: alpaca-linux.zip + asset_content_type: application/octet-stream diff --git a/Makefile b/Makefile index fb83d41badc5..93da626f8836 100644 --- a/Makefile +++ b/Makefile @@ -194,6 +194,13 @@ clean: chat: chat.cpp ggml.o utils.o $(CXX) $(CXXFLAGS) chat.cpp ggml.o utils.o -o chat $(LDFLAGS) +chat_mac: chat.cpp ggml.c utils.cpp + $(CC) $(CFLAGS) -c ggml.c -o ggml_x86.o -target x86_64-apple-macos + $(CC) $(CFLAGS) -c ggml.c -o ggml_arm.o -target arm64-apple-macos + + $(CXX) $(CXXFLAGS) chat.cpp ggml_x86.o utils.cpp -o chat_x86 $(LDFLAGS) -target x86_64-apple-macos + $(CXX) $(CXXFLAGS) chat.cpp ggml_arm.o utils.cpp -o chat_arm $(LDFLAGS) -target arm64-apple-macos + lipo -create -output chat_mac chat_x86 chat_arm quantize: quantize.cpp ggml.o utils.o $(CXX) $(CXXFLAGS) quantize.cpp ggml.o utils.o -o quantize $(LDFLAGS) From 7636ddb9e45807ce4317717f75a4d7ce5d23541a Mon Sep 17 00:00:00 2001 From: Kevin Kwok Date: Mon, 20 Mar 2023 22:16:27 -0700 Subject: [PATCH 26/26] Update README.md --- README.md | 81 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index a1ecbe78cef8..aec100114a5a 100644 --- a/README.md +++ b/README.md @@ -8,37 +8,69 @@ Run a fast ChatGPT-like model locally on your device. The screencast below is no This combines the [LLaMA foundation model](https://github.com/facebookresearch/llama) with an [open reproduction](https://github.com/tloen/alpaca-lora) of [Stanford Alpaca](https://github.com/tatsu-lab/stanford_alpaca) a fine-tuning of the base model to obey instructions (akin to the [RLHF](https://huggingface.co/blog/rlhf) used to train ChatGPT) and a set of modifications to [llama.cpp](https://github.com/ggerganov/llama.cpp) to add a chat interface. -## Get started +## Get Started (7B) -```sh -git clone https://github.com/antimatter15/alpaca.cpp -cd alpaca.cpp +Download the zip file corresponding to your operating system from the [latest release](https://github.com/antimatter15/alpaca.cpp/releases/latest). On Windows, download `alpaca-win.zip`, on Mac (both Intel or ARM) download `alpaca-mac.zip`, and on Linux (x64) download `alpaca-linux.zip`. -make chat +Download `ggml-alpaca-7b-q4.bin` and place it in the same folder as the `chat` executable in the zip file. There are several options: + +``` +# Any of these commands will work. +curl -o ggml-alpaca-7b-q4.bin -C - https://gateway.estuary.tech/gw/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC +curl -o ggml-alpaca-7b-q4.bin -C - https://ipfs.io/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC +curl -o ggml-alpaca-7b-q4.bin -C - https://cloudflare-ipfs.com/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC + +# BitTorrent +magnet:?xt=urn:btih:5aaceaec63b03e51a98f04fd5c42320b2a033010&dn=ggml-alpaca-7b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce +https://btcache.me/torrent/5AACEAEC63B03E51A98F04FD5C42320B2A033010 +https://torrage.info/torrent.php?h=5aaceaec63b03e51a98f04fd5c42320b2a033010 +``` + +Once you've downloaded the model weights and placed them into the same directory as the `chat` or `chat.exe` executable, run: + +``` ./chat ``` -You can download the weights for `ggml-alpaca-7b-q4.bin` with BitTorrent: +The weights are based on the published fine-tunes from `alpaca-lora`, converted back into a pytorch checkpoint with a [modified script](https://github.com/tloen/alpaca-lora/pull/19) and then quantized with llama.cpp the regular way. + +## Getting Started (13B) -magnet: `magnet:?xt=urn:btih:5aaceaec63b03e51a98f04fd5c42320b2a033010&dn=ggml-alpaca-7b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce` -torrent: https://btcache.me/torrent/5AACEAEC63B03E51A98F04FD5C42320B2A033010 -torrent: https://torrage.info/torrent.php?h=5aaceaec63b03e51a98f04fd5c42320b2a033010 +If you have more than 10GB of RAM, you can use the higher quality 13B `ggml-alpaca-13b-q4.bin` model. To download the weights, you can use +``` -Alternatively you can download them with IPFS. +# Any of these commands will work. +curl -o ggml-alpaca-13b-q4.bin -C - https://gateway.estuary.tech/gw/ipfs/Qme6wyw9MzqbrUMpFNVq42rC1kSdko7MGT9CL7o1u9Cv9G +curl -o ggml-alpaca-13b-q4.bin -C - https://ipfs.io/ipfs/Qme6wyw9MzqbrUMpFNVq42rC1kSdko7MGT9CL7o1u9Cv9G +curl -o ggml-alpaca-13b-q4.bin -C - https://cloudflare-ipfs.com/ipfs/Qme6wyw9MzqbrUMpFNVq42rC1kSdko7MGT9CL7o1u9Cv9G +# BitTorrent +magnet:?xt=urn:btih:053b3d54d2e77ff020ebddf51dad681f2a651071&dn=ggml-alpaca-13b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce +https://btcache.me/torrent/053B3D54D2E77FF020EBDDF51DAD681F2A651071 +https://torrage.info/torrent.php?h=053b3d54d2e77ff020ebddf51dad681f2a651071 ``` -# any of these will work -curl -o ggml-alpaca-7b-q4.bin -C - https://gateway.estuary.tech/gw/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC -curl -o ggml-alpaca-7b-q4.bin -C - https://ipfs.io/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC -curl -o ggml-alpaca-7b-q4.bin -C - https://cloudflare-ipfs.com/ipfs/QmQ1bf2BTnYxq73MFJWu1B7bQ2UD6qG7D7YDCxhTndVkPC + +Once you've downloaded the weights, you can run the following command to enter chat + +``` +./chat -m ggml-alpaca-13b-q4.bin ``` -Save the `ggml-alpaca-7b-q4.bin` file in the same directory as your `./chat` executable. -The weights are based on the published fine-tunes from `alpaca-lora`, converted back into a pytorch checkpoint with a [modified script](https://github.com/tloen/alpaca-lora/pull/19) and then quantized with llama.cpp the regular way. +## Building from Source (MacOS/Linux) + + +```sh +git clone https://github.com/antimatter15/alpaca.cpp +cd alpaca.cpp + +make chat +./chat +``` + -## Windows Setup +## Building from Source (Windows) - Download and install CMake: - Download and install `git`. If you've never used git before, consider a GUI client like @@ -59,21 +91,6 @@ cmake --build . --config Release - (You can add other launch options like `--n 8` as preferred onto the same line) - You can now type to the AI in the terminal and it will reply. Enjoy! -## 13B - -TODO: write more docs here (PRs welcome) - -You can download the weights for `ggml-alpaca-13b-q4.bin` with BitTorrent: - -magnet: `magnet:?xt=urn:btih:053b3d54d2e77ff020ebddf51dad681f2a651071&dn=ggml-alpaca-13b-q4.bin&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.com%3A2810%2Fannounce` -torrent: https://btcache.me/torrent/053B3D54D2E77FF020EBDDF51DAD681F2A651071 -torrent: https://torrage.info/torrent.php?h=053b3d54d2e77ff020ebddf51dad681f2a651071 - - -``` -./chat -m ggml-alpaca-13b-q4.bin -``` - ## Credit This combines [Facebook's LLaMA](https://github.com/facebookresearch/llama), [Stanford Alpaca](https://crfm.stanford.edu/2023/03/13/alpaca.html), [alpaca-lora](https://github.com/tloen/alpaca-lora) and [corresponding weights](https://huggingface.co/tloen/alpaca-lora-7b/tree/main) by Eric Wang (which uses [Jason Phang's implementation of LLaMA](https://github.com/huggingface/transformers/pull/21955) on top of Hugging Face Transformers), and [llama.cpp](https://github.com/ggerganov/llama.cpp) by Georgi Gerganov. The chat implementation is based on Matvey Soloviev's [Interactive Mode](https://github.com/ggerganov/llama.cpp/pull/61) for llama.cpp. Inspired by [Simon Willison's](https://til.simonwillison.net/llms/llama-7b-m2) getting started guide for LLaMA. [Andy Matuschak](https://twitter.com/andy_matuschak/status/1636769182066053120)'s thread on adapting this to 13B, using fine tuning weights by [Sam Witteveen](https://huggingface.co/samwit/alpaca13B-lora).