Skip to content

Distribute and run LLMs with a single file.

Explain how to summarize HTML URLs and images

Justine Tunney3bc37ad32a4b
diff --git a/Makefile b/Makefile
index 58df943f..a3da3d8b 100644
--- a/Makefile
+++ b/Makefile
@@ -26,14 +26,12 @@ install: llamafile/zipalign.1 \
llama.cpp/server/server.1 \
llama.cpp/quantize/quantize.1 \
llama.cpp/perplexity/perplexity.1 \
- llama.cpp/llava/llava-cli.1 \
llama.cpp/llava/llava-quantize.1 \
o/$(MODE)/llamafile/zipalign \
o/$(MODE)/llama.cpp/main/main \
o/$(MODE)/llama.cpp/server/server \
o/$(MODE)/llama.cpp/quantize/quantize \
o/$(MODE)/llama.cpp/perplexity/perplexity \
- o/$(MODE)/llama.cpp/llava/llava-cli \
o/$(MODE)/llama.cpp/llava/llava-quantize
mkdir -p $(PREFIX)/bin
$(INSTALL) o/$(MODE)/llamafile/zipalign $(PREFIX)/bin/zipalign
@@ -41,7 +39,6 @@ install: llamafile/zipalign.1 \
$(INSTALL) o/$(MODE)/llama.cpp/server/server $(PREFIX)/bin/llamafile-server
$(INSTALL) o/$(MODE)/llama.cpp/quantize/quantize $(PREFIX)/bin/llamafile-quantize
$(INSTALL) o/$(MODE)/llama.cpp/perplexity/perplexity $(PREFIX)/bin/llamafile-perplexity
- $(INSTALL) o/$(MODE)/llama.cpp/llava/llava-cli $(PREFIX)/bin/llava-cli
$(INSTALL) o/$(MODE)/llama.cpp/llava/llava-quantize $(PREFIX)/bin/llava-quantize
mkdir -p $(PREFIX)/share/man/man1
$(INSTALL) -m 0644 llamafile/zipalign.1 $(PREFIX)/share/man/man1/zipalign.1
@@ -49,7 +46,6 @@ install: llamafile/zipalign.1 \
$(INSTALL) -m 0644 llama.cpp/server/server.1 $(PREFIX)/share/man/man1/llamafile-server.1
$(INSTALL) -m 0644 llama.cpp/quantize/quantize.1 $(PREFIX)/share/man/man1/llamafile-quantize.1
$(INSTALL) -m 0644 llama.cpp/perplexity/perplexity.1 $(PREFIX)/share/man/man1/llamafile-perplexity.1
- $(INSTALL) -m 0644 llama.cpp/llava/llava-cli.1 $(PREFIX)/share/man/man1/llava-cli.1
$(INSTALL) -m 0644 llama.cpp/llava/llava-quantize.1 $(PREFIX)/share/man/man1/llava-quantize.1
include build/deps.mk
diff --git a/README.md b/README.md
index e4092e74..cf1ab888 100644
--- a/README.md
+++ b/README.md
@@ -267,22 +267,55 @@ weights:
```sh
llamafile \
- -m ~/weights/wizardcoder-python-13b-v1.0.Q8_0.gguf \
+ -m wizardcoder-python-13b-v1.0.Q8_0.gguf \
--temp 0 \
-r $'```\n' \
- -p $'```c\nvoid *memcpy_sse2(char *dst, const char *src, size_t size) {\n'
+ -p $'```c\nvoid *memcpy(char *dst, const char *src, size_t size) {\n'
```
-Here's a similar example that instead utilizes Mistral-7B-Instruct weights:
+Here's a similar example that instead utilizes Mistral-7B-Instruct
+weights for prose composition:
```sh
llamafile \
- -m ~/weights/mistral-7b-instruct-v0.1.Q4_K_M.gguf \
+ -m mistral-7b-instruct-v0.1.Q4_K_M.gguf \
--temp 0.7 \
-r $'\n' \
-p $'### Instruction: Write a story about llamas\n### Response:\n'
```
+Here's an example of how you can use llamafile to summarize HTML URLs:
+
+```sh
+(
+ echo [INST]Summarize the following text:
+ links -codepage utf-8 \
+ -force-html \
+ -width 500 \
+ -dump https://www.poetryfoundation.org/poems/48860/the-raven |
+ sed 's/ */ /'
+ echo [/INST]
+) | llamafile \
+ -m mistral-7b-instruct-v0.1.Q4_K_M.gguf \
+ -c 6700 \
+ -f /dev/stdin \
+ --temp 0 \
+ -ngl 35 \
+ -n 500 \
+ --silent-prompt 2>/dev/null
+```
+
+Here's how you can use llamafile to describe a jpg/png/gif/bmp image:
+
+```sh
+llamafile --temp 0 \
+ --image ~/Pictures/lemurs.jpg \
+ -m llava-v1.5-7b-Q4_K.gguf \
+ --mmproj llava-v1.5-7b-mmproj-Q4_0.gguf \
+ -p $'### User: What do you see?\n### Assistant: ' \
+ --silent-prompt 2>/dev/null
+```
+
Here's an example of how to run llama.cpp's built-in HTTP server. This
example uses LLaVA v1.5-7B, a multimodal LLM that works with llama.cpp's
recently-added support for image inputs.
@@ -330,8 +363,8 @@ cp /usr/local/bin/llamafile-server llava-server.llamafile
zipalign -j0 \
llava-server.llamafile \
- ~/weights/llava-v1.5-7b-Q8_0.gguf \
- ~/weights/llava-v1.5-7b-mmproj-Q8_0.gguf \
+ llava-v1.5-7b-Q8_0.gguf \
+ llava-v1.5-7b-mmproj-Q8_0.gguf \
.args
./llava-server.llamafile
diff --git a/llama.cpp/README.llamafile b/llama.cpp/README.llamafile
index 174d02c3..ee591c74 100644
--- a/llama.cpp/README.llamafile
+++ b/llama.cpp/README.llamafile
@@ -35,4 +35,5 @@ LOCAL MODIFICATIONS
- Use runtime dispatching for matmul quants
- Remove operating system #ifdef statements
- Introduce --silent-prompt flag to main
+ - Meld llava-cli and llama.cpp main
- Remove stdout logging from LLaVA
diff --git a/llama.cpp/llava/BUILD.mk b/llama.cpp/llava/BUILD.mk
index 0c1650dc..9c68e309 100644
--- a/llama.cpp/llava/BUILD.mk
+++ b/llama.cpp/llava/BUILD.mk
@@ -13,11 +13,6 @@ o/$(MODE)/llama.cpp/llava/llava.a: \
o/$(MODE)/llama.cpp/llava/clip.o \
o/$(MODE)/llama.cpp/llava/llava.o
-o/$(MODE)/llama.cpp/llava/llava-cli: \
- o/$(MODE)/llama.cpp/llava/llava-cli.o \
- o/$(MODE)/llama.cpp/llava/llava.a \
- o/$(MODE)/llama.cpp/llama.cpp.a
-
o/$(MODE)/llama.cpp/llava/llava-quantize: \
o/$(MODE)/llama.cpp/llava/llava-quantize.o \
o/$(MODE)/llama.cpp/llava/llava.a \
@@ -26,5 +21,4 @@ o/$(MODE)/llama.cpp/llava/llava-quantize: \
.PHONY: o/$(MODE)/llama.cpp/llava
o/$(MODE)/llama.cpp/llava: \
o/$(MODE)/llama.cpp/llava/llava.a \
- o/$(MODE)/llama.cpp/llava/llava-cli \
o/$(MODE)/llama.cpp/llava/llava-quantize
diff --git a/llama.cpp/llava/README.md b/llama.cpp/llava/README.md
index 323c5fdd..73741b6d 100644
--- a/llama.cpp/llava/README.md
+++ b/llama.cpp/llava/README.md
@@ -9,12 +9,15 @@ models are available.
After API is confirmed, more models will be supported / uploaded.
## Usage
-Build with cmake or run `make llava-cli` to build it.
+Build with cmake or run `make o//llama.cpp/main/main` to build it.
-After building, run: `./llava-cli` to see the usage. For example:
+After building, run: `o//llama.cpp/main/main` to see the usage. For example:
```sh
-./llava-cli -m llava-v1.5-7b/ggml-model-q5_k.gguf --mmproj llava-v1.5-7b/mmproj-model-f16.gguf --image path/to/an/image.jpg
+o//llama.cpp/main/main \
+ -m llava-v1.5-7b/ggml-model-q5_k.gguf \
+ --mmproj llava-v1.5-7b/mmproj-model-f16.gguf \
+ --image path/to/an/image.jpg
```
**note**: A lower temperature like 0.1 is recommended for better quality. add `--temp 0.1` to the command to do so.
diff --git a/llama.cpp/llava/llava-cli.1 b/llama.cpp/llava/llava-cli.1
deleted file mode 100644
index 83cc04cc..00000000
--- a/llama.cpp/llava/llava-cli.1
+++ /dev/null
@@ -1,89 +0,0 @@
-.Dd December 5, 2023
-.Dt llava-cli 1
-.Os
-.Sh NAME
-.Nm llava-cli
-.Nd CLIP model command line interface
-.Sh SYNOPSIS
-.Nm
-.Op flags...
-.Sh DESCRIPTION
-.Nm
-is a command-line tool for LLaVA.
-.Sh OPTIONS
-The following options are available:
-.Bl -tag -width indent
-.It Fl h , Fl Fl help
-Show help message and exit.
-.It Fl Fl temp Ar N
-Temperature (default: 0.8)
-.It Fl Fl top-k Ar N
-Top-k sampling (default: 40, 0 = disabled)
-.It Fl Fl top-p Ar N
-Top-p sampling (default: 0.9, 1.0 = disabled)
-.It Fl Fl tfs Ar N
-Tail free sampling, parameter z (default: 1.0, 1.0 = disabled)
-.It Fl Fl typical Ar N
-Locally typical sampling, parameter p (default: 1.0, 1.0 = disabled)
-.It Fl Fl mirostat Ar N
-Use Mirostat sampling. Top K, Nucleus, Tail Free and Locally Typical samplers are ignored if used. (default: 0, 0 = disabled, 1 = Mirostat, 2 = Mirostat 2.0)
-.It Fl Fl mirostat-lr Ar N
-Mirostat learning rate, parameter eta (default: 0.1)
-.It Fl Fl mirostat-ent Ar N
-Mirostat target entropy, parameter tau (default: 5.0)
-.Fl Fl logit-bias Ar 15043+1
-to increase likelihood of token
-.Ar ' Hello' ,
-or
-.Fl Fl logit-bias Ar 15043-1
-to decrease likelihood of token
-.Ar ' Hello' .
-.It Fl p Ar PROMPT , Fl Fl prompt Ar PROMPT
-Prompt to start generation with (default: empty)
-.It Fl t Ar N , Fl Fl threads Ar N
-Number of threads to use during generation (default: nproc/2)
-.It Fl tb Ar N , Fl Fl threads-batch Ar N
-Number of threads to use during batch and prompt processing (default:
-same as
-.Fl Fl threads )
-.It Fl Fl image Ar IMAGE_FILE
-Path to an image file. use with multimodal models.
-.It Fl n Ar N , Fl Fl n-predict Ar N
-Number of tokens to predict (default: -1, -1 = infinity, -2 = until context filled)
-.It Fl b Ar N , Fl Fl batch-size Ar N
-Batch size for prompt processing (default: 512)
-.It Fl m Ar FNAME , Fl Fl model Ar FNAME
-Model path (default: models/7B/ggml-model-f16.gguf)
-.It Fl Fl mmproj Ar MMPROJ_FILE
-Path to a multimodal projector file for LLaVA. See llama.cpp/llava/README.md
-.It Fl Fl numa
-Attempt optimizations that help on some NUMA systems if run without this previously, it is recommended to drop the system page cache before using this. See https://github.com/ggerganov/llama.cpp/issues/1437.
-.It Fl c Ar N , Fl Fl ctx-size Ar N
-Size of the prompt context (default: 512, 0 = loaded from model)
-.It Fl Fl rope-scaling Ar {none,linear,yarn}
-RoPE frequency scaling method, defaults to linear unless specified by the model
-.It Fl Fl rope-scale Ar N
-RoPE context scaling factor, expands context by a factor of N
-.It Fl Fl rope-freq-base Ar N
-RoPE base frequency, used by NTK-aware scaling (default: loaded from model)
-.It Fl Fl rope-freq-scale Ar N
-RoPE frequency scaling factor, expands context by a factor of 1/N
-.It Fl Fl yarn-orig-ctx Ar N
-YaRN: original context size of model (default: 0 = model training context size)
-.It Fl Fl yarn-ext-factor Ar N
-YaRN: extrapolation mix factor (default: 1.0, 0.0 = full interpolation)
-.It Fl Fl yarn-attn-factor Ar N
-YaRN: scale sqrt(t) or attention magnitude (default: 1.0)
-.It Fl Fl yarn-beta-slow Ar N
-YaRN: high correction dim or alpha (default: 1.0)
-.It Fl Fl yarn-beta-fast Ar N
-YaRN: low correction dim or beta (default: 32.0)
-.It Fl s Ar SEED , Fl Fl seed Ar SEED
-Random Number Generator (RNG) seed (default: -1, use random seed for < 0)
-.It Fl Fl memory-f32
-Use f32 instead of f16 for memory key+value (default: disabled) Not recommended: doubles context memory required and no measurable increase in quality.
-.It Fl Fl logits-all
-Return logits for all tokens in the batch (default: disabled).El
-.Sh SEE ALSO
-.Xr llava-quantize 1 ,
-.Xr llamafile 1
diff --git a/llama.cpp/llava/llava-cli.cpp b/llama.cpp/llava/llava-cli.cpp
index a2cc3502..d68a12fd 100644
--- a/llama.cpp/llava/llava-cli.cpp
+++ b/llama.cpp/llava/llava-cli.cpp
@@ -6,8 +6,8 @@
#include "clip.h"
#include "llava.h"
#include "llama.cpp/llama.h"
-
#include "llama.cpp/base64.h"
+#include "llamafile/version.h"
#include <cstdio>
#include <cstdlib>
@@ -282,10 +282,7 @@ static void llava_free(struct llava_context * ctx_llava) {
llama_backend_free();
}
-int main(int argc, char ** argv) {
- llamafile_check_cpu();
- ggml_time_init();
-
+int llava_cli(int argc, char ** argv) {
gpt_params params;
if (!gpt_params_parse(argc, argv, params)) {
diff --git a/llama.cpp/llava/llava-quantize.1 b/llama.cpp/llava/llava-quantize.1
index 28fd7b98..3c39a104 100644
--- a/llama.cpp/llava/llava-quantize.1
+++ b/llama.cpp/llava/llava-quantize.1
@@ -6,6 +6,7 @@
.Nd CLIP model quantizer
.Sh SYNOPSIS
.Nm
+.Op options...
.Ar INPUT
.Ar OUTPUT
.Ar FORMAT
@@ -22,6 +23,14 @@ Is the output file, which will be a CLIP model in the GGUF format using the desi
.It Ev Ar FORMAT
Is the desired quantization format, which may be the integer id of a supported quantization type. See the quantization types section below for acceptable formats.
.El
+.Sh OPTIONS
+The following options are accepted:
+.Bl -tag -width indent
+.It Fl h , Fl Fl help
+Show help message and exit.
+.It Fl Fl version
+Print llamafile version.
+.El
.Sh QUANTIZATION TYPES
The following quantization types are available:
.Pp
@@ -38,5 +47,4 @@ The following quantization types are available:
8 is Q8_0
.El
.Sh SEE ALSO
-.Xr llava-cli 1 ,
.Xr llamafile 1
diff --git a/llama.cpp/llava/llava-quantize.cpp b/llama.cpp/llava/llava-quantize.cpp
index 850eb7ac..5b1e686a 100644
--- a/llama.cpp/llava/llava-quantize.cpp
+++ b/llama.cpp/llava/llava-quantize.cpp
@@ -1,11 +1,17 @@
// -*- mode:c++;indent-tabs-mode:nil;c-basic-offset:4;coding:utf-8 -*-
// vi: set et ft=c++ ts=4 sts=4 sw=4 fenc=utf-8 :vi
+#include "clip.h"
+#include "llama.cpp/ggml.h"
+#include "llamafile/version.h"
#include <stdio.h>
#include <stdlib.h>
-#include "llama.cpp/ggml.h"
-#include "clip.h"
+#include <string.h>
int main(int argc, char *argv[]) {
+ if (argc == 2 && !strcmp(argv[1], "--version")) {
+ printf("llamafile v" LLAMAFILE_VERSION_STRING " llava-quantize\n");
+ exit(0);
+ }
llamafile_check_cpu();
if (argc != 4) {
fprintf(stderr,
diff --git a/llama.cpp/llava/llava.h b/llama.cpp/llava/llava.h
index 7ffc54a8..045a4036 100644
--- a/llama.cpp/llava/llava.h
+++ b/llama.cpp/llava/llava.h
@@ -2,6 +2,7 @@
#define LLAVA_H
#include "llama.cpp/ggml.h"
+#include "llama.cpp/llama.h"
#ifdef LLAMA_SHARED
@@ -42,6 +43,7 @@ LLAVA_API void llava_image_embed_free(struct llava_image_embed * embed);
/** write the image represented by embed into the llama context with batch size n_batch, starting at context pos n_past. on completion, n_past points to the next position in the context after the image embed. */
LLAVA_API bool llava_eval_image_embed(struct llama_context * ctx_llama, const struct llava_image_embed * embed, int n_batch, int * n_past);
+LLAVA_API int llava_cli(int argc, char ** argv);
#ifdef __cplusplus
}
diff --git a/llama.cpp/main/BUILD.mk b/llama.cpp/main/BUILD.mk
index c657ae42..5e4546dc 100644
--- a/llama.cpp/main/BUILD.mk
+++ b/llama.cpp/main/BUILD.mk
@@ -8,10 +8,12 @@ LLAMA_CPP_MAIN_HDRS = $(filter %.h,$(LLAMA_CPP_MAIN_FILES))
LLAMA_CPP_MAIN_SRCS = $(filter %.cpp,$(LLAMA_CPP_MAIN_FILES))
LLAMA_CPP_MAIN_OBJS = $(LLAMA_CPP_MAIN_SRCS:%.cpp=o/$(MODE)/%.o)
+o/$(MODE)/llama.cpp/main/main: \
+ o/$(MODE)/llama.cpp/main/main.o \
+ o/$(MODE)/llama.cpp/llava/llava-cli.o \
+ o/$(MODE)/llama.cpp/llava/llava.a \
+ o/$(MODE)/llama.cpp/llama.cpp.a
+
.PHONY: o/$(MODE)/llama.cpp/main
-o/$(MODE)/llama.cpp/main: \
+o/$(MODE)/llama.cpp/main: \
o/$(MODE)/llama.cpp/main/main
-
-o/$(MODE)/llama.cpp/main/main: \
- o/$(MODE)/llama.cpp/main/main.o \
- o/$(MODE)/llama.cpp/llama.cpp.a
diff --git a/llama.cpp/main/main.1 b/llama.cpp/main/main.1
index 235591a6..02c5ebb2 100644
--- a/llama.cpp/main/main.1
+++ b/llama.cpp/main/main.1
@@ -7,7 +7,7 @@
.Sh SYNOPSIS
.Nm
.Op flags...
-.Op Fl m Ar weights.gguf
+.Op Fl m Ar model.gguf
.Op Fl p Ar prompt
.Sh DESCRIPTION
.Nm
@@ -29,6 +29,8 @@ The following options are available:
.Bl -tag -width indent
.It Fl h , Fl Fl help
Show help message and exit.
+.It Fl Fl version
+Print llamafile version.
.It Fl i , Fl Fl interactive
Run in interactive mode.
.It Fl Fl interactive-first
@@ -51,7 +53,7 @@ Number of threads to use during generation (default: nproc/2)
Number of threads to use during batch and prompt processing (default:
same as
.Fl Fl threads )
-.It Fl p Ar PROMPT , Fl Fl prompt Ar PROMPT
+.It Fl p Ar STRING , Fl Fl prompt Ar STRING
Prompt to start generation with (default: empty)
.It Fl e , Fl Fl escape
Process prompt escapes sequences (\[rs]n, \[rs]r, \[rs]t, \[rs]\[aa], \[rs]", \[rs]\[rs])
@@ -173,10 +175,6 @@ speculative decoding accept probability (default: 0.5)
Speculative decoding split probability (default: 0.1)
.It Fl cb , Fl Fl cont-batching
Enable continuous batching (a.k.a dynamic batching) (default: disabled)
-.It Fl Fl mmproj Ar MMPROJ_FILE
-Path to a multimodal projector file for LLaVA. See llama.cpp/llava/README.md
-.It Fl Fl image Ar IMAGE_FILE
-Path to an image file. use with multimodal models.
.It Fl Fl mlock
Force system to keep model in RAM rather than swapping or compressing.
.It Fl Fl no-mmap
@@ -208,7 +206,7 @@ Apply LoRA adapter with user defined scaling S (implies
.It Fl Fl lora-base Ar FNAME
Optional model to use as a base for the layers modified by the LoRA adapter
.It Fl m Ar FNAME , Fl Fl model Ar FNAME
-Model path (default: models/7B/ggml-model-f16.gguf)
+Model path in GGUF file format (default: models/7B/ggml-model-f16.gguf)
.It Fl md Ar FNAME , Fl Fl model-draft Ar FNAME
Draft model for speculative decoding (default: models/7B/ggml-model-f16.gguf)
.It Fl Fl unsecure
@@ -236,7 +234,6 @@ Don't truncate the old log file.
.Xr llamafile-server 1 ,
.Xr llamafile-quantize 1 ,
.Xr llamafile-perplexity 1 ,
-.Xr llava-cli 1 ,
.Xr llava-quantize 1 ,
.Xr zipalign 1 ,
.Xr unzip 1
diff --git a/llama.cpp/main/main.cc b/llama.cpp/main/main.cpp
similarity index 98%
rename from llama.cpp/main/main.cc
rename to llama.cpp/main/main.cpp
index b62773c2..86087441 100644
--- a/llama.cpp/main/main.cc
+++ b/llama.cpp/main/main.cpp
@@ -5,6 +5,7 @@
#include "llama.cpp/ggml-metal.h"
#include "llama.cpp/ggml-cuda.h"
#include "llamafile/version.h"
+#include "llama.cpp/llava/llava.h"
#include "tool/args/args.h"
#include "llama.cpp/common.h"
@@ -105,6 +106,15 @@ static int Eval(struct llama_context * ctx, struct llama_batch batch) {
return rc;
}
+static bool has_argument(int argc, char ** argv, const char * arg) {
+ for (int i = 1; i < argc; ++i) {
+ if (!strcmp(argv[i], arg)) {
+ return true;
+ }
+ }
+ return false;
+}
+
int main(int argc, char ** argv) {
if (argc == 2 && !strcmp(argv[1], "--version")) {
printf("llamafile v" LLAMAFILE_VERSION_STRING " main\n");
@@ -115,12 +125,20 @@ int main(int argc, char ** argv) {
ShowCrashReports();
LoadZipArgs(&argc, &argv);
+ if (has_argument(argc, argv, "--mmproj")) {
+ return llava_cli(argc, argv);
+ }
+
gpt_params params;
g_params = &params;
if (!gpt_params_parse(argc, argv, params)) {
return 1;
}
+ if (!params.image.empty()) {
+ fprintf(stderr, "%s: fatal error: --mmproj must also be passed if --image is passed\n", argv[0]);
+ return 1;
+ }
llama_sampling_params & sparams = params.sparams;
#ifndef LOG_DISABLE_LOGS
diff --git a/llama.cpp/quantize/quantize.1 b/llama.cpp/quantize/quantize.1
index 485e2257..103ec208 100644
--- a/llama.cpp/quantize/quantize.1
+++ b/llama.cpp/quantize/quantize.1
@@ -86,7 +86,6 @@ COPY Only copy tensors, no quantizing.
.Xr llamafile 1 ,
.Xr llamafile-server 1 ,
.Xr llamafile-perplexity 1 ,
-.Xr llava-cli 1 ,
.Xr llava-quantize 1 ,
.Xr zipalign 1 ,
.Xr unzip 1
diff --git a/llama.cpp/server/server.1 b/llama.cpp/server/server.1
index 28f5e3b6..90e87def 100644
--- a/llama.cpp/server/server.1
+++ b/llama.cpp/server/server.1
@@ -103,7 +103,6 @@ Disables pledge() sandboxing on Linux and OpenBSD
.Xr llamafile 1 ,
.Xr llamafile-quantize 1 ,
.Xr llamafile-perplexity 1 ,
-.Xr llava-cli 1 ,
.Xr llava-quantize 1 ,
.Xr zipalign 1 ,
.Xr unzip 1