TinyLlama.cpp 1.0
A lightweight C++ implementation of the TinyLlama language model
Loading...
Searching...
No Matches
gguf_parser.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <fstream>
5#include <map>
6#include <string>
7#include <vector>
8
9#include "gguf_structs.h"
10
24constexpr uint32_t GGUF_MAGIC = 0x46554747;
25
29constexpr uint64_t GGUF_DEFAULT_ALIGNMENT = 32;
30constexpr uint32_t GGUF_MAX_TENSOR_DIMS = 4;
31constexpr uint64_t GGUF_STRING_MAX_LENGTH = 1ull << 30;
36constexpr float GGUF_EPSILON = 1e-10f;
37constexpr float GGUF_SMALL_VAL = 1e-6f;
42constexpr size_t GGML_QK_K = 256;
43constexpr size_t GGML_QK8_0 = 32;
44constexpr size_t GGML_Q4K_BLOCK_SIZE = 32;
45constexpr size_t GGML_Q6K_BLOCK_SIZE = 256;
50constexpr float TENSOR_SCALE_MAX = 1000.0f;
51constexpr float TENSOR_SCALE_MIN = -1000.0f;
56constexpr float Q4K_SCALE_FACTOR = 15.0f;
57constexpr float Q6K_SCALE_FACTOR = 31.0f;
58constexpr float Q8K_SCALE_FACTOR = 127.0f;
63constexpr int8_t Q4K_OFFSET = 8;
64constexpr int8_t Q6K_OFFSET = 32;
72template <typename T>
73void read_raw(std::ifstream& file, T& dest);
74
81std::string read_gguf_string(std::ifstream& file);
82
94GGUFData load_gguf_meta(const std::string& filename, bool use_mmap);
constexpr uint32_t GGUF_MAGIC
GGUF magic number that identifies the file format Spells "GGUF" in ASCII (0x47475546)
Definition gguf_parser.h:24
constexpr float TENSOR_SCALE_MAX
Constants for tensor value validation.
Definition gguf_parser.h:50
constexpr int8_t Q4K_OFFSET
Offset values for quantization methods.
Definition gguf_parser.h:63
constexpr int8_t Q6K_OFFSET
Definition gguf_parser.h:64
constexpr size_t GGML_Q4K_BLOCK_SIZE
Definition gguf_parser.h:44
constexpr float Q8K_SCALE_FACTOR
Definition gguf_parser.h:58
constexpr size_t GGML_Q6K_BLOCK_SIZE
Definition gguf_parser.h:45
constexpr float Q4K_SCALE_FACTOR
Scale factors for different quantization methods.
Definition gguf_parser.h:56
void read_raw(std::ifstream &file, T &dest)
Reads raw binary data from a file stream.
constexpr uint32_t GGUF_MAX_TENSOR_DIMS
Definition gguf_parser.h:30
constexpr float TENSOR_SCALE_MIN
Definition gguf_parser.h:51
constexpr float Q6K_SCALE_FACTOR
Definition gguf_parser.h:57
constexpr float GGUF_EPSILON
Constants for numeric stability in calculations.
Definition gguf_parser.h:36
constexpr uint64_t GGUF_STRING_MAX_LENGTH
Definition gguf_parser.h:31
constexpr size_t GGML_QK8_0
Definition gguf_parser.h:43
constexpr size_t GGML_QK_K
Block size constants for different quantization formats.
Definition gguf_parser.h:42
constexpr float GGUF_SMALL_VAL
Definition gguf_parser.h:37
constexpr uint64_t GGUF_DEFAULT_ALIGNMENT
Constants for GGUF file parsing and validation.
Definition gguf_parser.h:29
GGUFData load_gguf_meta(const std::string &filename, bool use_mmap)
Loads GGUF metadata and optionally memory-maps tensor data.
std::string read_gguf_string(std::ifstream &file)
Reads a string from a GGUF format file.
Data structures for GGUF (GPT-Generated Unified Format) file format.
Complete representation of a GGUF file's contents.