Distribute and run LLMs with a single file.
C++ cross-platformggufllama-cpplocal-ailocal-inferencelocal-llmopen-source-aisingle-file-executablespeech-to-text
revise README for clarity and easier onboarding for new users
Stephen Hoodda4673b89b63
diff --git a/README.md b/README.mdindex 94a8854e..6aa92dca 100644--- a/README.md+++ b/README.md@@ -2,64 +2,163 @@-**llamafile lets you distribute and run LLMs with a single file ([blog post](https://hacks.mozilla.org/2023/11/introducing-llamafile/))**+**llamafile lets you distribute and run LLMs with a single file. ([announcement blog post](https://hacks.mozilla.org/2023/11/introducing-llamafile/))**-Our goal is to make the "build once anywhere, run anywhere" dream come-true for AI developers. We're doing that by combining [llama.cpp](https://github.com/ggerganov/llama.cpp)-with [Cosmopolitan Libc](https://github.com/jart/cosmopolitan) into one-framework that lets you build apps for LLMs as a single-file artifact-that runs locally on most PCs and servers.+Our goal is to make open source large language models much more+accessible to both developers and end users. We're doing that by+combining [llama.cpp](https://github.com/ggerganov/llama.cpp) with [Cosmopolitan Libc](https://github.com/jart/cosmopolitan) into one+framework that collapses all the complexity of LLMs down to+a single-file executable (called a "llamafile") that runs+locally on most computers, with no installation.-First, your llamafiles can run on multiple CPU microarchitectures. We+## Quickstart++The easiest way to try it for yourself is to download our example+llamafile for the [LLaVA](https://llava-vl.github.io/) model (license: [LLaMA](https://github.com/facebookresearch/llama/blob/main/LICENSE),+[OpenAI](https://openai.com/policies/terms-of-use)). LLaVA is a new LLM that can do more+than just chat; you can also upload images and ask it questions+about them. With llamafile, this all happens locally; no data+ever leaves your computer.++1. Download [llava-v1.5-7b-q4-server.llamafile](https://huggingface.co/jartine/llava-v1.5-7B-GGUF/resolve/main/llava-v1.5-7b-q4-server.llamafile?download=true) (3.97 GB).++2. Open your computer's terminal.++3. If you're using macOS, Linux, or BSD, you'll need to grant permission+for your computer to execute this new file. (You only need to do this+once.)++```sh+chmod +x llava-v1.5-7b-q4-server.llamafile+```++4. If you're on Windows, rename the file by adding ".exe" on the end.++5. Run the llamafile. e.g.:++```sh+./llava-v1.5-7b-q4-server.llamafile+```++6. Your browser should open automatically and display a chat interface.+(If it doesn't, just open your browser and point it at https://localhost:8080.)++7. When you're done chatting, return to your terminal and hit+```Control-C``` to shut down llamafile.++**Having trouble? See the "Gotchas" section below.**++## Other example llamafiles++We also provide example llamafiles for two other models, so you can+easily try out llamafile with different kinds of LLMs.++| Model | License | Command-line llamafile | Server llamafile |+| --- | --- | --- | --- |+| Mistral-7B-Instruct | [Apache 2.0](https://choosealicense.com/licenses/apache-2.0/) | [mistral-7b-instruct-v0.1-Q4_K_M-main.llamafile (4.07 GB)](https://huggingface.co/jartine/mistral-7b.llamafile/resolve/main/mistral-7b-instruct-v0.1-Q4_K_M-main.llamafile?download=true) | [mistral-7b-instruct-v0.1-Q4_K_M-server.llamafile (4.07 GB)](https://huggingface.co/jartine/mistral-7b.llamafile/resolve/main/mistral-7b-instruct-v0.1-Q4_K_M-server.llamafile?download=true) |+| WizardCoder-Python-13B | [LLaMA 2](https://ai.meta.com/resources/models-and-libraries/llama-downloads/) | [wizardcoder-python-13b-main.llamafile (7.33 GB)](https://huggingface.co/jartine/wizardcoder-13b-python/resolve/main/wizardcoder-python-13b-main.llamafile?download=true) | [wizardcoder-python-13b-server.llamafile (7.33GB)](https://huggingface.co/jartine/wizardcoder-13b-python/resolve/main/wizardcoder-python-13b-server.llamafile?download=true) |++"Server llamafiles" work just like the LLaVA example above: you simply run+them from your terminal and then access the chat UI in your web browser at+https://localhost:8080.++"Command-line llamafiles" run entirely inside your terminal and+operate just like llama.cpp's "main" function. This means you+have to provide some command-line parameters, just like with+llama.cpp.++Here is an example for the Mistral command-line llamafile:++```sh+./mistral-7b-instruct-v0.1-Q4_K_M-main.llamafile --temp 0.7 -r '\n' -p '### Instruction: Write a story about llamas\n### Response:\n'+```++And here is an example for WizardCoder-Python command-line llamafile:++```sh+./wizardcoder-python-13b-main.llamafile --temp 0 -r '\n' -p '\nvoid *memcpy_sse2(char *dst, const char *src, size_t size) {\n'+```++As before, macOS, Linux, and BSD users will need to use the "chmod"+command to grant execution permissions to the file before running+these llamafiles for the first time.++Unfortunately, Windows users cannot make use of these example llamafiles+because Windows has a maximum executable file size of 4GB, and all of+these examples exceed that size. (The LLaVA llamafile works on Windows because it is 30MB shy of the size limit.) But don't lose heart: llamafile allows+you to use external weights; this is described later in this document.++**Having trouble? See the "Gotchas" section below.**++## How llamafile works++A llamafile is an executable LLM that you can run on your own+computer. It contains the weights for a given open source LLM, as well+as everything needed to actually run that model on your computer.+There's nothing to install or configure (with a few caveats, discussed+in subsequent sections of this document).++This is all accomplished by combining llama.cpp with Cosmopolitan Libc,+which provides some useful capabilities:++1. llamafiles can run on multiple CPU microarchitectures. Weadded runtime dispatching to llama.cpp that lets new Intel systems usemodern CPU features without trading away support for older computers.-Secondly, your llamafiles can run on multiple CPU architectures. We do+2. llamafiles can run on multiple CPU architectures. We dothat by concatenating AMD64 and ARM64 builds with a shell script thatlaunches the appropriate one. Our file format is compatible with WIN32and most UNIX shells. It's also able to be easily converted (by eitheryou or your users) to the platform-native format, whenever required.-Thirdly, your llamafiles can run on six OSes (macOS, Windows, Linux,-FreeBSD, OpenBSD, and NetBSD). You'll only need to build your code once,-using a Linux-style toolchain. The GCC-based compiler we provide is-itself an Actually Portable Executable, so you can build your software-for all six OSes from the comfort of whichever one you prefer most for-development.+3. llamafiles can run on six OSes (macOS, Windows, Linux,+FreeBSD, OpenBSD, and NetBSD). If you make your own llama files, you'll+only need to build your code once, using a Linux-style toolchain. The+GCC-based compiler we provide is itself an Actually Portable Executable,+so you can build your software for all six OSes from the comfort of+whichever one you prefer most for development.-Lastly, the weights for your LLM can be embedded within your llamafile.+4. The weights for an LLM can be embedded within the llamafile.We added support for PKZIP to the GGML library. This lets uncompressedweights be mapped directly into memory, similar to a self-extractingarchive. It enables quantized weights distributed online to be prefixedwith a compatible version of the llama.cpp software, thereby ensuringits originally observed behaviors can be reproduced indefinitely.-## Binary Instructions+5. Finally, with the tools included in this project you can create your+*own* llamafiles, using any compatible model weights you want. You can+then distribute these llamafiles to other people, who can easily make+use of them regardless of what kind of computer they have.-We provide example binaries that embed several different models. You can-download these from Hugging Face via the links below. "Command-line-binaries" run from the command line, just as if you were invoking-llama.cpp's "main" function manually. "Server binaries" launch a local-web server (at 127.0.0.1:8080) that provides a web-based chatbot.+## Using llamafile with external weights-| Model | Command-line binary | Server binary |-| --- | --- | --- |-| Mistral-7B-Instruct | [mistral-7b-instruct-v0.1-Q4_K_M-main.llamafile (4.07 GB)](https://huggingface.co/jartine/mistral-7b.llamafile/resolve/main/mistral-7b-instruct-v0.1-Q4_K_M-main.llamafile?download=true) | [mistral-7b-instruct-v0.1-Q4_K_M-server.llamafile (4.07 GB)](https://huggingface.co/jartine/mistral-7b.llamafile/resolve/main/mistral-7b-instruct-v0.1-Q4_K_M-server.llamafile?download=true) |-| LLaVA 1.5 | (Not provided because this model's features are best utilized via the web UI) | **[llava-v1.5-7b-q4-server.llamafile (3.97 GB)](https://huggingface.co/jartine/llava-v1.5-7B-GGUF/resolve/main/llava-v1.5-7b-q4-server.llamafile?download=true)** |-| WizardCoder-Python-13B | [wizardcoder-python-13b-main.llamafile (7.33 GB)](https://huggingface.co/jartine/wizardcoder-13b-python/resolve/main/wizardcoder-python-13b-main.llamafile?download=true) | [wizardcoder-python-13b-server.llamafile (7.33GB)](https://huggingface.co/jartine/wizardcoder-13b-python/resolve/main/wizardcoder-python-13b-server.llamafile?download=true) |+Even though our example llamafiles have the weights built-in, you don't+*have* to use llamafile that way. Instead, you can download *just* the+llamafile software (without any weights included) from our releases page.+You can then use it alongside any external weights you may have on hand.+External weights are particularly useful for Windows users because they+enable you to work around Windows' 4GB executable file size limit.-You can also also download *just* the llamafile software (without any-weights included) from our releases page, or directly in your terminal-or command prompt. This is mandatory currently on Windows.+For Windows users, here's an example for the Mistral LLM:++```sh+curl -o llamafile.exe https://github.com/Mozilla-Ocho/llamafile/releases/download/0.2.1/llamafile-server-0.2.1+curl -o mistral.gguf https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q4_K_M.gguf+.\llamafile.exe -m mistral.gguf+```++Here's the same example, but for macOS, Linux, and BSD users:```shcurl -L https://github.com/Mozilla-Ocho/llamafile/releases/download/0.2.1/llamafile-server-0.2.1 >llamafile+curl -L https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q4_K_M.gguf >mistral.ggufchmod +x llamafile-./llamafile --help-./llamafile -m ~/weights/foo.gguf+./llamafile -m mistral.gguf```-### Gotchas+++## GotchasOn macOS with Apple Silicon you need to have Xcode installed forllamafile to be able to bootstrap itself.@@ -80,19 +179,14 @@ sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/regissudo sh -c "echo ':APE-jart:M::jartsr::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"```-On Windows, you may need to rename `llamafile` to `llamafile.exe` in-order for it to run. Windows also has a maximum file size limit of 4GB+As mentioned above, on Windows you may need to rename your llamafile by+adding `.exe` to the filename.++Also as mentioned above, Windows also has a maximum file size limit of 4GBfor executables. The LLaVA server executable above is just 30MB shy ofthat limit, so it'll work on Windows, but with larger models like-WizardCoder 13B, you need to store the weights in a separate file.-Here's an example of how to do that. Let's say you want to try Mistral.-In that case you can open PowerShell and run these commands:--```-curl -o llamafile.exe https://github.com/Mozilla-Ocho/llamafile/releases/download/0.2.1/llamafile-server-0.2.1-curl -o mistral.gguf https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/resolve/main/mistral-7b-instruct-v0.1.Q4_K_M.gguf-.\llamafile.exe -m mistral.gguf-```+WizardCoder 13B, you need to store the weights in a separate file. An+example is provided above; see "Using llamafile with external weights."On WSL, it's recommended that the WIN32 interop feature be disabled:@@ -103,7 +197,7 @@ sudo sh -c "echo -1 > /proc/sys/fs/binfmt_misc/WSLInterop"On any platform, if your llamafile process is immediately killed, checkif you have CrowdStrike and then ask to be whitelisted.-### GPU Support+## GPU supportOn Apple Silicon, everything should just work if Xcode is installed.@@ -123,7 +217,7 @@ In the event that GPU support couldn't be compiled and dynamicallylinked on the fly for any reason, llamafile will fall back to CPUinference.-## Source Instructions+## Source instructionsHere's how to build llamafile from source. First, you need the cosmocctoolchain, which is a fat portable binary version of GCC. Here's how you@@ -145,9 +239,7 @@ make -j8```Here's an example of how to generate code for a libc function using the-llama.cpp command line interface, utilizing [WizardCoder-Python-13B](https://huggingface.co/TheBloke/WizardCoder-Python-13B-V1.0-GGUF/tree/main)-(license: [LLaMA 2](https://ai.meta.com/resources/models-and-libraries/llama-downloads/))-weights.+llama.cpp command line interface, utilizing WizardCoder-Python-13B weights:```shmake -j8 o//llama.cpp/main/main@@ -158,8 +250,7 @@ o//llama.cpp/main/main \-p $'```c\nvoid *memcpy_sse2(char *dst, const char *src, size_t size) {\n'```-Here's a similar example that instead utilizes [Mistral-7B-Instruct](https://huggingface.co/TheBloke/Mistral-7B-Instruct-v0.1-GGUF/tree/main)-(license: [Apache 2.0](https://choosealicense.com/licenses/apache-2.0/)) weights.+Here's a similar example that instead utilizes Mistral-7B-Instruct weights:```shmake -j8 o//llama.cpp/main/main@@ -170,13 +261,10 @@ o//llama.cpp/main/main \-p $'### Instruction: Write a story about llamas\n### Response:\n'```-Here's an example of how to run llama.cpp's built-in HTTP server in sucha way that the weights are embedded inside the executable. This example-uses [LLaVA v1.5-7B](https://huggingface.co/jartine/llava-v1.5-7B-GGUF/tree/main) (license: [LLaMA](https://github.com/facebookresearch/llama/blob/main/LICENSE),-[OpenAI](https://openai.com/policies/terms-of-use)),-a multimodal LLM that works with llama.cpp's recently-added support for-image inputs.+uses LLaVA v1.5-7B, a multimodal LLM that works with llama.cpp's+recently-added support for image inputs.```shmake -j8@@ -236,11 +324,7 @@ mv server.com serverCongratulations. You've just made your own LLM executable that's easy toshare with your friends.-(Note that the examples provided above are not endorsements or-recommendations of specific models, licenses, or data sets on the part-of Mozilla.)--### Security+## Securityllamafile adds pledge() and SECCOMP sandboxing to llama.cpp. This isenabled by default. It can be turned off by passing the `--unsecure`@@ -396,6 +480,12 @@ avoid these tradeoffs entirely. See[cosmopolitan/dlopen.c](https://github.com/jart/cosmopolitan/blob/master/libc/dlopen/dlopen.c)for further details.+## A note about models++The example llamafiles provided above should not be interpreted as+endorsements or recommendations of specific models, licenses, or data+sets on the part of Mozilla.+## LicensingWhile the llamafile project is Apache 2.0-licensed, our changes@@ -404,10 +494,3 @@ itself) so as to remain compatible and upstreamable in the future,should that be desired.The llamafile logo on this page was generated with the assistance of DALL·E 3.--## Known Issues--- The 64-bit version of Windows has a 4GB file size limit. While- llamafile will work fine on 64-bit Windows with the weights as a- separate file, you'll get an error if you load them into the- executable itself and try to run it.