Skip to content

dev notes

brian khuu edited this page Jun 12, 2024 · 5 revisions

Dev Notes

These are general free form note with pointers to good jumping to point to under stand the llama.cpp codebase.

(@<symbol> is a vscode jump to symbol code for your convenience. Also making a feature request to vscode to be able to jump to file and symbol via <file>:@<symbol>)

Where are the definitions for GGUF in llama.cpp?

GGUF file structure spec (WARN: As of 2024-06-11 the llama.cpp implementation is the canonical source for now)

All of the gguf structure can be found in gguf.c unless stated otherwise

GGUF Structure Of Interest gguf.c reference vscode search line
Overall File Structure struct gguf_context @gguf_context
File Header Structure struct gguf_header @gguf_header
Key Value Structure struct gguf_kv @gguf_kv
Tensor Info Structure struct gguf_tensor_info @gguf_tensor_info

Element of Interest (Think of this as an index lookup reference)

Please use this as an index not as canonical reference. The purpose of this table is to allow you to quickly locate major elements of the gguf file standard.

Header Name GGUF Elements Of Interest c name c type vscode search line
GGUF Header Magic magic uint8_t[4] gguf.c:@gguf_header
GGUF Header Version version uint32_t gguf.c:@gguf_header
GGUF Header Tensor Count n_tensors uint64_t gguf.c:@gguf_header
GGUF Header Key Value Count n_kv uint64_t gguf.c:@gguf_header
GGUF Context Key Value Linked List kv gguf_kv * gguf.c:@gguf_context
GGUF Context Tensor Info Linked List infos gguf_tensor_info * gguf.c:@gguf_context
Key Value Entry Key gguf_kv.key gguf_str gguf.c:@gguf_kv
Key Value Entry Type gguf_kv.type gguf_type gguf.c:@gguf_kv
Key Value Entry Type gguf_kv.value gguf_value gguf.c:@gguf_kv
Tensor Info Entry Name gguf_tensor_info.name gguf_str gguf.c:@gguf_tensor_info
Tensor Info Entry Tensor shape dimension count gguf_tensor_info.n_dim uint32_t gguf.c:@gguf_tensor_info
Tensor Info Entry Tensor shape sizing array gguf_tensor_info.ne uint64_t[GGML_MAX_DIMS] gguf.c:@gguf_tensor_info
Tensor Info Entry Tensor Encoding Scheme / Strategy gguf_tensor_info.type ggml_type gguf.c:@gguf_tensor_info
Tensor Info Entry Offset from start of 'data' gguf_tensor_info.offset uint64_t gguf.c:@gguf_tensor_info

Also just note that these values are not actually part of gguf but is there for internal usage and is calculated during model loading. Aka it's for the writing/reading api.

Header Name GGML Elements Of Interest c name c type vscode search line
GGUF Context Alignment alignment size_t gguf.c:@gguf_context
GGUF Context Offset Of 'Data' From Beginning Of File offset size_t gguf.c:@gguf_context
GGUF Context Size Of 'Data' In Bytes size size_t gguf.c:@gguf_context
Tensor Info Entry Tensor memory mapped pointer location in computer data void * gguf.c:@gguf_tensor_info
Tensor Info Entry Tensor memory mapped size of layer data in computer size size_t gguf.c:@gguf_tensor_info

Is there a simple example of gguf being used?

There is this cpp example program that will write a test gguf write/read

Users Guide

Useful information for users that doesn't fit into Readme.

Technical Details

These are information useful for Maintainers and Developers which does not fit into code comments

Github Actions Main Branch Status

Click on a badge to jump to workflow. This is here as a useful general view of all the actions so that we may notice quicker if main branch automation is broken and where.

  • bench action status
  • build action status
  • close-issue action status
  • code-coverage action status
  • docker action status
  • editorconfig action status
  • gguf-publish action status
  • labeler action status
  • nix-ci-aarch64 action status
  • nix-ci action status
  • nix-flake-update action status
  • nix-publish-flake action status
  • python-check-requirements action status
  • python-lint action status
  • server action status
Clone this wiki locally