ホーム 暮らし What exactly is llama.cpp?

What exactly is llama.cpp?

雨宮 千夏 雨宮 千夏 • 更新: • 公開: • 読了約 8 分
目次

It is an excellent tool that allows you to run LLMs on a Mac just by following the README without knowing what is going on under the hood, but what exactly is llama.cpp?

GGML is PyTorch in C/C++

n076231811729

To understand llama.cpp, you first need to know about GGML.

GGML is a machine learning library created by llama.cpp author Georgi Gerganov, and it is fair to say it is the library equivalent to PyTorch in C/C++. You can build models in C/C++. llama.cpp is written in GGML.

This rough image of "GGML = PyTorch" is useful for understanding llama.cpp.

1. The beginning of llama.cpp

As you can see from the llama.cpp description:

llama.cpp started as a project to "rewrite" LLaMA, which was written in Python, in GGML (C/C++) (ref). The "Port" in "Port of ..." refers to "rewriting in another language."

Because LLaMA, which was written in PyTorch, is being rewritten in GGML (C/C++), it becomes possible to use features not supported in the original implementation, such as Mac GPU support (Metal) and CPU optimization.

Here is an implementation written in the early stages of llama.cpp, but as an image:

  • Convert the weights of the original implementation into the GGML file format

  • Implement the model that assigns the weights using the GGML library

Based on a quick skim, it seems to be structured roughly as described above.
Various LLaMA architecture portings were implemented using GGML.

② The emergence of GGUF

GGUF is the model output file format for the GGML library (similar in concept to .pth files).
Initially, the file format shared the same name as the library, GGML, but GGUF was born in August 2023 to align with the evolution of the GGML library.
In addition to improved expressive power as a file format, it also became possible to support models other than LLaMA.

③ As an LLM runtime

(Similar to how PyTorch can load and execute models with torch.load()) It became possible to convert pre-trained models uploaded to HuggingFace and elsewhere into GGUF and load and run them with llama.cpp.
The official GGUF conversion tool itself has also been available from the start.

In other words, its use as an LLM runtime (converted to GGUF) is also increasing.
It plays a role similar to the ONNX runtime.
Moreover, it is very good because it runs on various architectures, including Mac.

Summary

  • Georgi Gerganov created GGML (ggml.ai).

  • He created llama.cpp as an application using GGML.

  • Initially, it was just a port of LLaMA.

  • It developed into a project to run various LLMs on various architectures.

That is perhaps the historical perspective. Georgi Gerganov is amazing.
(I summarized this while researching, so I welcome corrections from those who are more knowledgeable.)

Aside: What is "GG"?

The prefix "GG" in GGML and GGUF stands for the initials of the author (Georgi Gerganov).

Aside: Diving into the implementation of llama.cpp

For details on how llama.cpp is implemented in GGML, the following blog provides in-depth information.

同じカテゴリの記事

雨宮 千夏
デジタルマーケター 雨宮 千夏
プロフィールを見る →

アイドルと音楽シーンの取材を担当。公式サイトの公演情報、リリース告知、公開チャートを照合してから構成しています。

おすすめの関連記事