Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
Tune CUDA build scripts some more
Justine Tunney2f41a6df9870
diff --git a/llamafile/copy.sh b/llamafile/copy.shnew file mode 100755index 00000000..66b4040d--- /dev/null+++ b/llamafile/copy.sh@@ -0,0 +1,18 @@+#!/bin/sh+set -x+HOST=${1:?HOST}++ssh $HOST mkdir -p lfbuild+scp llama.cpp/ggml-cuda.cu \+ llama.cpp/ggml-cuda.h \+ llama.cpp/ggml-impl.h \+ llama.cpp/ggml-alloc.h \+ llama.cpp/ggml-backend.h \+ llama.cpp/ggml-backend-impl.h \+ llama.cpp/ggml.h \+ llamafile/tinyblas.h \+ llamafile/tinyblas.cu \+ llamafile/llamafile.h \+ llamafile/cuda.bat \+ llamafile/cuda.sh \+ $HOST:lfbuild/diff --git a/llamafile/cuda.c b/llamafile/cuda.cindex fb40468a..c42b5109 100644--- a/llamafile/cuda.c+++ b/llamafile/cuda.c@@ -406,29 +406,20 @@ static bool ExtractCudaDso(char dso[static PATH_MAX]) {strlcat(dso, "ggml-cuda.", PATH_MAX);strlcat(dso, GetDsoExtension(), PATH_MAX);- // check if we need to extract again- switch (llamafile_is_file_newer_than(zip, dso)) {- case -1:- return false;- case false:- return true;- case true:- break;- default:- __builtin_unreachable();- }-// extract prebuilt dsoreturn llamafile_extract(zip, dso);}-static bool LinkCudaDso(const char *dso) {+static bool LinkCudaDso(char *dso) {// runtime link dynamic shared objectvoid *lib;lib = cosmo_dlopen(dso, RTLD_LAZY);if (!lib) {tinyprint(2, Dlerror(), ": failed to load library\n", NULL);+ if ((IsLinux() || IsBsd()) && !commandv("cc", dso, PATH_MAX)) {+ tinyprint(2, "you need to install a c compiler for gpu support\n", NULL);+ }return false;}@@ -466,6 +457,7 @@ static bool LinkCudaDso(const char *dso) {}static bool ImportCudaImpl(void) {+ char path[PATH_MAX];// No dynamic linking support on OpenBSD yet.if (IsOpenbsd()) {@@ -473,14 +465,13 @@ static bool ImportCudaImpl(void) {}// try building cuda code from source using cublas- char dso[PATH_MAX];- if (CompileNativeCuda(dso)) {- return LinkCudaDso(dso);+ if (CompileNativeCuda(path)) {+ return LinkCudaDso(path);}- // try using a prebuilt dso- if (ExtractCudaDso(dso)) {- return LinkCudaDso(dso);+ // try using a prebuilt path+ if (ExtractCudaDso(path)) {+ return LinkCudaDso(path);}// too baddiff --git a/llamafile/cuda.sh b/llamafile/cuda.shindex 4eea5065..43efb779 100755--- a/llamafile/cuda.sh+++ b/llamafile/cuda.sh@@ -1,22 +1,18 @@#!/bin/sh-set -x-HOST=${1:?HOST}-ssh $HOST mkdir -p lfbuild-scp llama.cpp/ggml-cuda.cu \- llama.cpp/ggml-cuda.h \- llama.cpp/ggml-impl.h \- llama.cpp/ggml-alloc.h \- llama.cpp/ggml-backend.h \- llama.cpp/ggml-backend-impl.h \- llama.cpp/tinyblas.cu \- llama.cpp/tinyblas.h \- llama.cpp/ggml.h \- llamafile/llamafile.h \- llamafile/cuda.bat \- $HOST:lfbuild/--# TODO(jart): make windows tools able to do automation somehow-# ssh $HOST 'cd lfbuild; C:/WINDOWS/system32/cmd.exe /k cuda.bat'-# mkdir -p o//llama.cpp-# scp $HOST:lfbuild/ggml-cuda.dll o//llama.cpp/+/usr/local/cuda/bin/nvcc \+ -arch=all \+ --shared \+ --forward-unknown-to-host-compiler \+ -use_fast_math \+ --compiler-options "-fPIC -O3 -march=native -mtune=native" \+ -DNDEBUG \+ -DGGML_BUILD=1 \+ -DGGML_SHARED=1 \+ -DGGML_CUDA_DMMV_X=32 \+ -DGGML_CUDA_MMV_Y=1 \+ -DK_QUANTS_PER_ITERATION=2 \+ -DGGML_CUDA_PEER_MAX_BATCH_SIZE=128 \+ -DGGML_USE_TINYBLAS \+ -o ggml-cuda.so \+ ggml-cuda.cu