Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Ggml org Llama cpp GGUF Example

From Leeroopedia
Revision as of 12:39, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Ggml_org_Llama_cpp_GGUF_Example.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains GGUF, Example
Last Updated 2026-02-15 00:00 GMT

Overview

Demonstrates GGUF file format read and write operations using the low-level gguf API.

Description

This example creates a GGUF context, writes various key-value metadata types (uint8, int8, uint16, float32, string, arrays of int16/float32/string, etc.), creates 10 random tensors with random dimensions and float32 data, and writes everything to a file. It then reads the file back, prints all KV pairs and tensor info, and verifies the data round-trips correctly by comparing tensor values.

Usage

Use this example as a reference and test for the GGUF file format API, demonstrating the full lifecycle of creating, writing, reading, and verifying GGUF files with metadata and tensor data.

Code Reference

Source Location

Signature

static bool gguf_ex_write(const std::string & fname);
static bool gguf_ex_read_0(const std::string & fname);
static bool gguf_ex_read_1(const std::string & fname, bool check_data);
int main(int argc, char ** argv);

Import

#include "ggml.h"
#include "gguf.h"

#include <cstdio>
#include <string>
#include <sstream>
#include <vector>

I/O Contract

Inputs

Name Type Required Description
fname std::string Yes Output/input filename for the GGUF file (default "test.gguf")

Outputs

Name Type Description
return int Exit code: 0 on success, 1 on failure
test.gguf file Written GGUF file containing metadata KV pairs and 10 random tensors

Usage Examples

# Build and run the GGUF example
cmake --build build --target llama-gguf

# Run with default filename "test.gguf"
./build/bin/llama-gguf

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment