Skip to content

Locally run an Instruction-Tuned Chat-Style LLM

License

Notifications You must be signed in to change notification settings

hjude/alpaca.cpp

 
 

Repository files navigation

Alpaca.cpp

Run a fast ChatGPT-like model locally on your device. The screencast below is not sped up and running on an M2 Macbook Air with 4GB of weights. Build instructions for MaC,Windows,Linux,Android are available.

asciicast

This combines the LLaMA foundation model with an open reproduction of Stanford Alpaca a fine-tuning of the base model to obey instructions (akin to the RLHF used to train ChatGPT) and a set of modifications to llama.cpp to add a chat interface.

Get started

git clone https://github.com/antimatter15/alpaca.cpp
cd alpaca.cpp

make chat
./chat

7B

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

Alternatively you can download them with IPFS.

# any of these will work(curl)
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

# any of these will work (wget)
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

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 and then quantized with llama.cpp the regular way.

Windows

  • Download and install CMake: https://cmake.org/download/
  • Download and install git. If you've never used git before, consider a GUI client like https://desktop.github.com/
  • 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)
  • Install Visual Studio 2022 or later with C++ support or install Visual C++ build tools 2022.
  • Open a Windows Terminal inside the folder you cloned the repository to
  • Run the following commands one by one:
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 the commands:
.\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!

Issues

for 'nmake' '-?' issue see antimatter15#35 (comment)

In this case for installation you should use it in Developer Command Prompt window (Developer Command Prompt for VS 2022), you can find it in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2022\Visual Studio Tools.

Remove old alpaca.cpp folder
Reinstall using Developer Command Prompt for VS 2022

Linux

Install the build-essentials and cmake.

To build run the following commands one by one:

mkdir build
cmake -B build .
cd build
cmake --build . --config Release

Android with termux (same as for linux plus several more steps)

You can easily run alpaca.cpp on Android device with termux.

Install termux on your device and run termux-setup-storage to get access to your SD card.

pkg install git
pkg install cmake

git clone https://github.com/antimatter15/alpaca.cpp
cd alpaca.cpp
mkdir build
cmake -B build .
cd build
cmake --build . --config Release

make chat

Save the ggml-alpaca-7b-q4.bin file in the same directory as your ./chat executable.

cd alpaca.cpp
./chat

Here is a screenshot of an interactive session running on Pixel 6 Android 13 phone:

Alpaca 7B running on Pixel 6 Alpaca running on Pixel 6

13B

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

30B

If you have than 32GB or more of RAM (and a beefy CPU), you can use the higher quality 30B alpaca-30B-ggml.bin model. To download the weights, you can use

git clone https://huggingface.co/Pi3141/alpaca-30B-ggml

to use this model add parameter

./chat -m ggml-model-q4_0.bin

You can actually take all other models from here https://huggingface.co/Pi3141

Credit

This combines alpaca.cpp Facebook's LLaMA, Stanford Alpaca, alpaca-lora and corresponding weights by Eric Wang (which uses Jason Phang's implementation of LLaMA on top of Hugging Face Transformers), and llama.cpp by Georgi Gerganov. The chat implementation is based on Matvey Soloviev's Interactive Mode for llama.cpp. Inspired by Simon Willison's getting started guide for LLaMA. Andy Matuschak's thread on adapting this to 13B, using fine tuning weights by Sam Witteveen.

Disclaimer

Note that the model weights are only to be used for research purposes, as they are derivative of LLaMA, and uses the published instruction data from the Stanford Alpaca project which is generated by OpenAI, which itself disallows the usage of its outputs to train competing models.

Additional might be useful Info

Cleaned Alpaca Dataset repository! This repository hosts a cleaned and curated version of a dataset used to train the Alpaca LLM (Large Language Model). The original dataset had several issues that are addressed in this cleaned version. https://github.com/gururise/AlpacaDataCleaned

About

Locally run an Instruction-Tuned Chat-Style LLM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 79.6%
  • C++ 16.9%
  • Python 1.2%
  • Makefile 1.2%
  • Other 1.1%