gotzmann/llama.go

★ 1,402⑂ 73

llama.go is like llama.cpp in pure Golang!

About gotzmann/llama.go

gotzmann/llama.go is an open-source project on GitHub, mainly written in Go. llama.go is like llama.cpp in pure Golang! It currently holds 1,402 stars and 73 forks with 0 open issues, and was last pushed on an unknown date (repository created unknown).

Project Overview

AI Homed tracks it on the Local & On-Device AI board.

GitHub Repository Details

Repository gotzmann/llama.go · default branch - · size 0 KB · watchers 0 · source: GitHub REST API and repository README

README

FINALLY - GOOD NEWS!

I've started to work on reimplementation of the library here: FastTensors

Please star it if you'd like to see GGML-compatible implementation in pure Go.

Looking for LLM Debug and Inference with Golang?

Please check out my related project Booster

Motivation

We dream of a world where fellow ML hackers are grokking REALLY BIG GPT models in their homelabs without having GPU clusters consuming a shit tons of $$$.

The code of the project is based on the legendary ggml.cpp framework of Georgi Gerganov written in C++ with the same attitude to performance and elegance.

We hope using Golang instead of soo-powerful but too-low-level language will allow much greater adoption.

V0 Roadmap

V1 Roadmap - Spring'23

V2 Roadmap - Winter'23

V3 Roadmap - Spring'23

How to Run?

First, obtain and convert original LLaMA models on your own, or just download ready-to-rock ones:

LLaMA-7B: llama-7b-fp32.bin

LLaMA-13B: llama-13b-fp32.bin

Both models store FP32 weights, so you'll needs at least 32Gb of RAM (not VRAM or GPU RAM) for LLaMA-7B. Double to 64Gb for LLaMA-13B.

Next, build app binary from sources (see instructions below), or just download already built one:

Windows: llama-go-v1.4.0.exe

MacOS: llama-go-v1.4.0-macos

Linux: llama-go-v1.4.0-linux

So now you have both executable and model, go try it for yourself:

llama-go-v1.4.0-macos \
    --model ~/models/llama-7b-fp32.bin \
    --prompt "Why Golang is so popular?" \

Useful command line flags:

--prompt   Text prompt from user to feed the model input
--model    Path and file name of converted .bin LLaMA model [ llama-7b-fp32.bin, etc ]
--server   Start in Server Mode acting as REST API endpoint
--host     Host to allow requests from in Server Mode [ localhost by default ]
--port     Port listen to in Server Mode [ 8080 by default ]
--pods     Maximum pods or units of parallel execution allowed in Server Mode [ 1 by default ]
--threads  Adjust to the number of CPU cores you want to use [ all cores by default ]
--context  Context size in tokens [ 1024 by default ]
--predict  Number of tokens to predict [ 512 by default ]
--temp     Model temperature hyper parameter [ 0.5 by default ]
--silent   Hide welcome logo and other output [ shown by default ]
--chat     Chat with user in interactive mode instead of compute over static prompt
--profile  Profe CPU performance while running and store results to cpu.pprof file
--avx      Enable x64 AVX2 optimizations for Intel and AMD machines
--neon     Enable ARM NEON optimizations for Apple Macs and ARM server

Going Production

LLaMA.go embeds standalone HTTP server exposing REST API. To enable it, run app with special flags:

llama-go-v1.4.0-macos \
    --model ~/models/llama-7b-fp32.bin \
    --server \
    --host 127.0.0.1 \
    --port 8080 \
    --pods 4 \
    --threads 4

Depending on the model size, how many CPU cores available there, how many requests you want to process in parallel, how fast you'd like to get answers, choose pods and threads parameters wisely.

Pods is a number of inference instances that might run in parallel.

Threads parameter sets how many cores will be used for tensor math within a pod.

So for example if you have machine with 16 hardware cores capable running 32 hyper-threads in parallel, you might end up with something like that:

--server --pods 4 --threads 8

When there is no free pod to handle arriving request, it will be placed into the waiting queue and started when some pod gets job finished.

REST API examples

Place new job

Send POST request (with Postman) to your server address with JSON containing unique UUID v4 and prompt:

{
    "id": "5fb8ebd0-e0c9-4759-8f7d-35590f6c9fc3",
    "prompt": "Why Golang is so popular?"
}

Check job status

Send GET request (with Postman or browser) to URL like http://host:port/jobs/status/:id

GET http://localhost:8080/jobs/status/5fb8ebd0-e0c9-4759-8f7d-35590f6c9fcb

Get the results

Send GET request (with Postman or browser) to URL like http://host:port/jobs/:id

GET http://localhost:8080/jobs/5fb8ebd0-e0c9-4759-8f7d-35590f6c9fcb

How to build

First, install Golang and git (you'll need to download installers in case of Windows).

brew install git
brew install golang

Then clone the repo and enter the project folder:

git clone https://github.com/gotzmann/llama.go.git
cd llama.go

Some Go magic to install external dependencies:

go mod tidy
go mod vendor

Now we are ready to build the binary from the source code:

go build -o llama-go-v1.exe -ldflags "-s -w" main.go

FAQ

1) From where I might obtain original LLaMA models?

Contact Meta directly or just look around for some torrent alternatives.

2) How to convert original LLaMA files into supported format?

Place original PyTorch FP16 files into models directory, then convert with command:

python3 ./scripts/convert.py ~/models/LLaMA/7B/ 0

GitHub Stars & Activity

1,402Stars
73Forks
0Open issues
GoLanguage

GitHub Popularity

GitHub stars1,402
Forks73
Open issues0
Primary languageGo
License-
Stars gained today0
Created-
Last pushed-

Trending History

Trending statusnot on today's boards

Related AI Projects

1

ollama / ollama

Go★ 181,337⑂ 17,947
2

ArvinLovegood / go-stock

Go★ 7,573⑂ 1,320
3

sammcj / gollama

Go★ 1,837⑂ 113
4

open-webui / open-webui

Python★ 152,659⑂ 22,336
5

HKUDS / nanobot

Python★ 48,435⑂ 8,555
6

chatchat-space / Langchain-Chatchat

Python★ 38,654⑂ 6,265
7

Zackriya-Solutions / meetily

Rust★ 30,978⑂ 3,365
8

mozilla-ai / llamafile

C++★ 26,010⑂ 1,600

More AI Rankings