From 0d054e292e5492981867be69c788edd04dc8adeb Mon Sep 17 00:00:00 2001 From: Slaren <2141330+slaren@users.noreply.github.com> Date: Fri, 31 Mar 2023 20:03:48 +0200 Subject: [PATCH 1/7] Show error message when -f fails --- examples/common.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/common.cpp b/examples/common.cpp index af3ad9eb7..50c536503 100644 --- a/examples/common.cpp +++ b/examples/common.cpp @@ -66,6 +66,11 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) { break; } std::ifstream file(argv[i]); + if (!file) { + fprintf(stderr, "error: failed to open file '%s'\n", argv[i]); + invalid_param = true; + break; + } std::copy(std::istreambuf_iterator(file), std::istreambuf_iterator(), back_inserter(params.prompt)); if (params.prompt.back() == '\n') { params.prompt.pop_back(); From d0a7f742e76bb48c0bd852f0b3bf09ec0b75b200 Mon Sep 17 00:00:00 2001 From: rimoliga <53384203+rimoliga@users.noreply.github.com> Date: Sat, 1 Apr 2023 11:57:30 -0300 Subject: [PATCH 2/7] readme: replace termux links with homepage, play store is deprecated (#680) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 07066cd81..f5744eacc 100644 --- a/README.md +++ b/README.md @@ -301,7 +301,7 @@ And after 4.45 hours, you will have the final perplexity. ### Android -You can easily run `llama.cpp` on Android device with [termux](https://play.google.com/store/apps/details?id=com.termux). +You can easily run `llama.cpp` on Android device with [termux](https://termux.dev/). First, obtain the [Android NDK](https://developer.android.com/ndk) and then build with CMake: ``` $ mkdir build-android @@ -310,7 +310,7 @@ $ export NDK= $ cmake -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-23 -DCMAKE_C_FLAGS=-march=armv8.4a+dotprod .. $ make ``` -Install [termux](https://play.google.com/store/apps/details?id=com.termux) on your device and run `termux-setup-storage` to get access to your SD card. +Install [termux](https://termux.dev/) on your device and run `termux-setup-storage` to get access to your SD card. Finally, copy the `llama` binary and the model files to your device storage. Here is a demo of an interactive session running on Pixel 5 phone: https://user-images.githubusercontent.com/271616/225014776-1d567049-ad71-4ef2-b050-55b0b3b9274c.mp4 From a717cba8440b380f43cd3e2510862fc1ea3de9a2 Mon Sep 17 00:00:00 2001 From: Ikko Eltociear Ashimine Date: Sun, 2 Apr 2023 01:38:18 +0900 Subject: [PATCH 3/7] py: huggingface -> Hugging Face (#686) --- convert-ggml-to-pth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/convert-ggml-to-pth.py b/convert-ggml-to-pth.py index 7ddfe3a1b..25a44237a 100644 --- a/convert-ggml-to-pth.py +++ b/convert-ggml-to-pth.py @@ -254,7 +254,7 @@ def main(): parser.add_argument( "--hf", action="store_true", - help="Whether to save the model in the huggingface format. (default: False)", + help="Whether to save the model in the Hugging Face format. (default: False)", ) parser.add_argument( "--chat", "-c", action="store_true", help="Whether to open a chat with the model. (default: False)" From 5b70e7de4c0b8186669d0c5609ba61a2d46de562 Mon Sep 17 00:00:00 2001 From: Murilo Santana Date: Sat, 1 Apr 2023 23:41:12 -0300 Subject: [PATCH 4/7] fix default params for examples/main (#697) --- examples/common.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/common.cpp b/examples/common.cpp index 50c536503..5400f6b01 100644 --- a/examples/common.cpp +++ b/examples/common.cpp @@ -39,6 +39,8 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) { bool invalid_param = false; std::string arg; + gpt_params default_params; + for (int i = 1; i < argc; i++) { arg = argv[i]; @@ -173,7 +175,7 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) { } params.n_parts = std::stoi(argv[i]); } else if (arg == "-h" || arg == "--help") { - gpt_print_usage(argc, argv, params); + gpt_print_usage(argc, argv, default_params); exit(0); } else if (arg == "--random-prompt") { params.random_prompt = true; @@ -185,13 +187,13 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) { params.input_prefix = argv[i]; } else { fprintf(stderr, "error: unknown argument: %s\n", arg.c_str()); - gpt_print_usage(argc, argv, params); + gpt_print_usage(argc, argv, default_params); exit(1); } } if (invalid_param) { fprintf(stderr, "error: invalid parameter for argument: %s\n", arg.c_str()); - gpt_print_usage(argc, argv, params); + gpt_print_usage(argc, argv, default_params); exit(1); } From c4f89d8d73aab4318a6c61e3835135adfcf55407 Mon Sep 17 00:00:00 2001 From: Fabian Date: Sun, 2 Apr 2023 09:17:05 +0200 Subject: [PATCH 5/7] make : use -march=native -mtune=native on x86 (#609) --- Makefile | 91 ++------------------------------------------------------ 1 file changed, 2 insertions(+), 89 deletions(-) diff --git a/Makefile b/Makefile index 83a4514ef..2f828bf10 100644 --- a/Makefile +++ b/Makefile @@ -70,95 +70,8 @@ endif # TODO: probably these flags need to be tweaked on some architectures # feel free to update the Makefile for your architecture and send a pull request or issue ifeq ($(UNAME_M),$(filter $(UNAME_M),x86_64 i686)) - ifeq ($(UNAME_S),Darwin) - F16C_M := $(shell sysctl machdep.cpu.features) - ifneq (,$(findstring F16C,$(F16C_M))) - CFLAGS += -mf16c - endif - AVX1_M := $(shell sysctl machdep.cpu.features) - ifneq (,$(findstring FMA,$(AVX1_M))) - CFLAGS += -mfma - endif - ifneq (,$(findstring AVX1.0,$(AVX1_M))) - CFLAGS += -mavx - endif - AVX2_M := $(shell sysctl machdep.cpu.leaf7_features) - ifneq (,$(findstring AVX2,$(AVX2_M))) - CFLAGS += -mavx2 - endif - else ifeq ($(UNAME_S),Linux) - AVX1_M := $(shell grep "avx " /proc/cpuinfo) - ifneq (,$(findstring avx,$(AVX1_M))) - CFLAGS += -mavx - endif - AVX2_M := $(shell grep "avx2 " /proc/cpuinfo) - ifneq (,$(findstring avx2,$(AVX2_M))) - CFLAGS += -mavx2 - endif - FMA_M := $(shell grep "fma " /proc/cpuinfo) - ifneq (,$(findstring fma,$(FMA_M))) - CFLAGS += -mfma - endif - F16C_M := $(shell grep "f16c " /proc/cpuinfo) - ifneq (,$(findstring f16c,$(F16C_M))) - CFLAGS += -mf16c - endif - SSE3_M := $(shell grep "sse3 " /proc/cpuinfo) - ifneq (,$(findstring sse3,$(SSE3_M))) - CFLAGS += -msse3 - endif - AVX512F_M := $(shell grep "avx512f " /proc/cpuinfo) - ifneq (,$(findstring avx512f,$(AVX512F_M))) - CFLAGS += -mavx512f - endif - AVX512BW_M := $(shell grep "avx512bw " /proc/cpuinfo) - ifneq (,$(findstring avx512bw,$(AVX512BW_M))) - CFLAGS += -mavx512bw - endif - AVX512DQ_M := $(shell grep "avx512dq " /proc/cpuinfo) - ifneq (,$(findstring avx512dq,$(AVX512DQ_M))) - CFLAGS += -mavx512dq - endif - AVX512VL_M := $(shell grep "avx512vl " /proc/cpuinfo) - ifneq (,$(findstring avx512vl,$(AVX512VL_M))) - CFLAGS += -mavx512vl - endif - AVX512CD_M := $(shell grep "avx512cd " /proc/cpuinfo) - ifneq (,$(findstring avx512cd,$(AVX512CD_M))) - CFLAGS += -mavx512cd - endif - AVX512ER_M := $(shell grep "avx512er " /proc/cpuinfo) - ifneq (,$(findstring avx512er,$(AVX512ER_M))) - CFLAGS += -mavx512er - endif - AVX512IFMA_M := $(shell grep "avx512ifma " /proc/cpuinfo) - ifneq (,$(findstring avx512ifma,$(AVX512IFMA_M))) - CFLAGS += -mavx512ifma - endif - AVX512PF_M := $(shell grep "avx512pf " /proc/cpuinfo) - ifneq (,$(findstring avx512pf,$(AVX512PF_M))) - CFLAGS += -mavx512pf - endif - else ifeq ($(UNAME_S),Haiku) - AVX1_M := $(shell sysinfo -cpu | grep -w "AVX") - ifneq (,$(findstring AVX,$(AVX1_M))) - CFLAGS += -mavx - endif - AVX2_M := $(shell sysinfo -cpu | grep -w "AVX2") - ifneq (,$(findstring AVX2,$(AVX2_M))) - CFLAGS += -mavx2 - endif - FMA_M := $(shell sysinfo -cpu | grep -w "FMA") - ifneq (,$(findstring FMA,$(FMA_M))) - CFLAGS += -mfma - endif - F16C_M := $(shell sysinfo -cpu | grep -w "F16C") - ifneq (,$(findstring F16C,$(F16C_M))) - CFLAGS += -mf16c - endif - else - CFLAGS += -mfma -mf16c -mavx -mavx2 - endif + # Use all CPU extensions that are available: + CFLAGS += -march=native -mtune=native endif ifneq ($(filter ppc64%,$(UNAME_M)),) POWER9_M := $(shell grep "POWER9" /proc/cpuinfo) From 81040f10aae3160317c5787c9c59acb219927826 Mon Sep 17 00:00:00 2001 From: Stephan Walter Date: Sun, 2 Apr 2023 07:18:53 +0000 Subject: [PATCH 6/7] llama : do not allocate KV cache for "vocab_only == true" (#682) Fixes sanitizer CI --- llama.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/llama.cpp b/llama.cpp index bed24207d..1b3157cd2 100644 --- a/llama.cpp +++ b/llama.cpp @@ -1608,7 +1608,7 @@ struct llama_context * llama_init_from_file( } // reserve memory for context buffers - { + if (!params.vocab_only) { if (!kv_cache_init(ctx->model.hparams, ctx->model.kv_self, memory_type, ctx->model.hparams.n_ctx)) { fprintf(stderr, "%s: kv_cache_init() failed for self-attention cache\n", __func__); llama_free(ctx); From 6e7801d08d81c931a5427bae46f00763e993f54a Mon Sep 17 00:00:00 2001 From: Leonardo Neumann Date: Sun, 2 Apr 2023 04:56:20 -0300 Subject: [PATCH 7/7] examples : add gpt4all script (#658) --- examples/gpt4all.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 examples/gpt4all.sh diff --git a/examples/gpt4all.sh b/examples/gpt4all.sh new file mode 100755 index 000000000..d974f95a9 --- /dev/null +++ b/examples/gpt4all.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# +# Temporary script - will be removed in the future +# + +cd `dirname $0` +cd .. + +./main --color --instruct --threads 4 \ + --model ./models/gpt4all-7B/gpt4all-lora-quantized.bin \ + --file ./prompts/alpaca.txt \ + --batch_size 8 --ctx_size 2048 \ + --repeat_last_n 64 --repeat_penalty 1.3 \ + --n_predict 128 --temp 0.1 --top_k 40 --top_p 0.95