GGUF (GGML Universal File): Go parsing library

GGUF is the file format of the ggml tensor library for storing machine learning models, used for example by llama.cpp for inference. It replaced the older GGML, GGMF and GGJT formats.

A GGUF file consists of a header with metadata as key-value pairs (model architecture, hyperparameters, tokenizer, etc.), a description of each tensor (name, dimensions, type and offset), and finally the tensor data.

File extension

gguf

KS implementation details

License: CC0-1.0
Minimal Kaitai Struct required: 0.11

References

This page hosts a formal specification of GGUF (GGML Universal File) using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Go source code to parse GGUF (GGML Universal File)

gguf.go

// Code generated by kaitai-struct-compiler from a .ksy source file. DO NOT EDIT.

import (
	"github.com/kaitai-io/kaitai_struct_go_runtime/kaitai"
	"bytes"
	"io"
	"strconv"
)


/**
 * GGUF is the file format of the [ggml](https://github.com/ggml-org/ggml)
 * tensor library for storing machine learning models, used for example by
 * [llama.cpp](https://github.com/ggml-org/llama.cpp) for inference. It
 * replaced the older GGML, GGMF and GGJT formats.
 * 
 * A GGUF file consists of a header with metadata as key-value pairs (model
 * architecture, hyperparameters, tokenizer, etc.), a description of each
 * tensor (name, dimensions, type and offset), and finally the tensor data.
 * @see <a href="https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/docs/gguf.md">Git tag "v0.27.0"</a>
 */

type Gguf_GgmlType int
const (
	Gguf_GgmlType__F32 Gguf_GgmlType = 0
	Gguf_GgmlType__F16 Gguf_GgmlType = 1
	Gguf_GgmlType__Q40 Gguf_GgmlType = 2
	Gguf_GgmlType__Q41 Gguf_GgmlType = 3
	Gguf_GgmlType__Q42 Gguf_GgmlType = 4
	Gguf_GgmlType__Q43 Gguf_GgmlType = 5
	Gguf_GgmlType__Q50 Gguf_GgmlType = 6
	Gguf_GgmlType__Q51 Gguf_GgmlType = 7
	Gguf_GgmlType__Q80 Gguf_GgmlType = 8
	Gguf_GgmlType__Q81 Gguf_GgmlType = 9
	Gguf_GgmlType__Q2K Gguf_GgmlType = 10
	Gguf_GgmlType__Q3K Gguf_GgmlType = 11
	Gguf_GgmlType__Q4K Gguf_GgmlType = 12
	Gguf_GgmlType__Q5K Gguf_GgmlType = 13
	Gguf_GgmlType__Q6K Gguf_GgmlType = 14
	Gguf_GgmlType__Q8K Gguf_GgmlType = 15
	Gguf_GgmlType__Iq2Xxs Gguf_GgmlType = 16
	Gguf_GgmlType__Iq2Xs Gguf_GgmlType = 17
	Gguf_GgmlType__Iq3Xxs Gguf_GgmlType = 18
	Gguf_GgmlType__Iq1S Gguf_GgmlType = 19
	Gguf_GgmlType__Iq4Nl Gguf_GgmlType = 20
	Gguf_GgmlType__Iq3S Gguf_GgmlType = 21
	Gguf_GgmlType__Iq2S Gguf_GgmlType = 22
	Gguf_GgmlType__Iq4Xs Gguf_GgmlType = 23
	Gguf_GgmlType__I8 Gguf_GgmlType = 24
	Gguf_GgmlType__I16 Gguf_GgmlType = 25
	Gguf_GgmlType__I32 Gguf_GgmlType = 26
	Gguf_GgmlType__I64 Gguf_GgmlType = 27
	Gguf_GgmlType__F64 Gguf_GgmlType = 28
	Gguf_GgmlType__Iq1M Gguf_GgmlType = 29
	Gguf_GgmlType__Bf16 Gguf_GgmlType = 30
	Gguf_GgmlType__Q4044 Gguf_GgmlType = 31
	Gguf_GgmlType__Q4048 Gguf_GgmlType = 32
	Gguf_GgmlType__Q4088 Gguf_GgmlType = 33
	Gguf_GgmlType__Tq10 Gguf_GgmlType = 34
	Gguf_GgmlType__Tq20 Gguf_GgmlType = 35
	Gguf_GgmlType__Iq4Nl44 Gguf_GgmlType = 36
	Gguf_GgmlType__Iq4Nl48 Gguf_GgmlType = 37
	Gguf_GgmlType__Iq4Nl88 Gguf_GgmlType = 38
	Gguf_GgmlType__Mxfp4 Gguf_GgmlType = 39
	Gguf_GgmlType__Nvfp4 Gguf_GgmlType = 40
	Gguf_GgmlType__Q10 Gguf_GgmlType = 41
	Gguf_GgmlType__Q20 Gguf_GgmlType = 42
)
var values_Gguf_GgmlType = map[Gguf_GgmlType]struct{}{0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {}, 7: {}, 8: {}, 9: {}, 10: {}, 11: {}, 12: {}, 13: {}, 14: {}, 15: {}, 16: {}, 17: {}, 18: {}, 19: {}, 20: {}, 21: {}, 22: {}, 23: {}, 24: {}, 25: {}, 26: {}, 27: {}, 28: {}, 29: {}, 30: {}, 31: {}, 32: {}, 33: {}, 34: {}, 35: {}, 36: {}, 37: {}, 38: {}, 39: {}, 40: {}, 41: {}, 42: {}}
func (v Gguf_GgmlType) isDefined() bool {
	_, ok := values_Gguf_GgmlType[v]
	return ok
}

type Gguf_GgufType int
const (
	Gguf_GgufType__Uint8 Gguf_GgufType = 0
	Gguf_GgufType__Int8 Gguf_GgufType = 1
	Gguf_GgufType__Uint16 Gguf_GgufType = 2
	Gguf_GgufType__Int16 Gguf_GgufType = 3
	Gguf_GgufType__Uint32 Gguf_GgufType = 4
	Gguf_GgufType__Int32 Gguf_GgufType = 5
	Gguf_GgufType__Float32 Gguf_GgufType = 6
	Gguf_GgufType__Bool Gguf_GgufType = 7
	Gguf_GgufType__String Gguf_GgufType = 8
	Gguf_GgufType__Array Gguf_GgufType = 9
	Gguf_GgufType__Uint64 Gguf_GgufType = 10
	Gguf_GgufType__Int64 Gguf_GgufType = 11
	Gguf_GgufType__Float64 Gguf_GgufType = 12
)
var values_Gguf_GgufType = map[Gguf_GgufType]struct{}{0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {}, 7: {}, 8: {}, 9: {}, 10: {}, 11: {}, 12: {}}
func (v Gguf_GgufType) isDefined() bool {
	_, ok := values_Gguf_GgufType[v]
	return ok
}
type Gguf struct {
	Magic []byte
	Body *Gguf_GgufBody
	_io *kaitai.Stream
	_root *Gguf
	_parent kaitai.Struct
	_f_isBigEndian bool
	isBigEndian bool
	_f_lenFile bool
	lenFile uint64
	_f_versionLe bool
	versionLe uint32
}
func NewGguf() *Gguf {
	return &Gguf{
	}
}

func (this Gguf) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf) Read(io *kaitai.Stream, parent kaitai.Struct, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root

	tmp1, err := this._io.ReadBytes(int(4))
	if err != nil {
		return err
	}
	tmp1 = tmp1
	this.Magic = tmp1
	if !(bytes.Equal(this.Magic, []uint8{71, 71, 85, 70})) {
		return kaitai.NewValidationNotEqualError([]uint8{71, 71, 85, 70}, this.Magic, this._io, "/seq/0")
	}
	tmp2 := NewGguf_GgufBody()
	err = tmp2.Read(this._io, this, this._root)
	if err != nil {
		return err
	}
	this.Body = tmp2
	return err
}
func (this *Gguf) IsBigEndian() (v bool, err error) {
	if (this._f_isBigEndian) {
		return this.isBigEndian, nil
	}
	this._f_isBigEndian = true
	tmp3, err := this.VersionLe()
	if err != nil {
		return false, err
	}
	this.isBigEndian = bool(tmp3 & 65535 == 0)
	return this.isBigEndian, nil
}

/**
 * Length of the file (computed from the header), including the padding after
 * the last tensor's data.
 * 
 * This Kaitai Struct implementation stops parsing where the tensor data
 * starts (which is read lazily, i.e. only on demand). Without reading the
 * tensor data, you can use this expected file size to check whether the file
 * has been truncated, to carve the file out of a larger one, etc.
 */
func (this *Gguf) LenFile() (v uint64, err error) {
	if (this._f_lenFile) {
		return this.lenFile, nil
	}
	this._f_lenFile = true
	tmp4, err := this.Body.OfsTensorData()
	if err != nil {
		return 0, err
	}
	var tmp5 uint64;
	if (this.Body.NumTensorInfos != 0) {
		tmp6 := this.Body.TensorInfos
		tmp7, err := tmp6[len(tmp6) - 1].ExpectedNextOffset()
		if err != nil {
			return 0, err
		}
		tmp5 = tmp7
	} else {
		tmp5 = 0
	}
	this.lenFile = uint64(uint64(tmp4 + tmp5))
	return this.lenFile, nil
}
func (this *Gguf) VersionLe() (v uint32, err error) {
	if (this._f_versionLe) {
		return this.versionLe, nil
	}
	this._f_versionLe = true
	_pos, err := this._io.Pos()
	if err != nil {
		return 0, err
	}
	_, err = this._io.Seek(int64(4), io.SeekStart)
	if err != nil {
		return 0, err
	}
	tmp8, err := this._io.ReadU4le()
	if err != nil {
		return 0, err
	}
	this.versionLe = tmp8
	_, err = this._io.Seek(_pos, io.SeekStart)
	if err != nil {
		return 0, err
	}
	return this.versionLe, nil
}

/**
 * GGUF file magic
 */
type Gguf_GgufBody struct {
	Version uint32
	NumTensorInfos uint64
	NumKvPairs uint64
	KvPairs []*Gguf_GgufBody_GgufKv
	TensorInfos []*Gguf_GgufBody_GgufTensorInfo
	Padding []byte
	_unnamed6 []byte
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf
	_f_alignment bool
	alignment uint32
	_f_ofsTensorData bool
	ofsTensorData uint64
	_is_le int
}
func NewGguf_GgufBody() *Gguf_GgufBody {
	return &Gguf_GgufBody{
	}
}

func (this Gguf_GgufBody) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody) Read(io *kaitai.Stream, parent *Gguf, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = -1

	tmp9, err := this._root.IsBigEndian()
	if err != nil {
		return err
	}
	switch (tmp9) {
	case true:
		this._is_le = int(0)
	case false:
		this._is_le = int(1)
	}

	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody) _read_le() (err error) {
	tmp10, err := this._io.ReadU4le()
	if err != nil {
		return err
	}
	this.Version = uint32(tmp10)
	if !(this.Version >= 2) {
		return kaitai.NewValidationLessThanError(2, this.Version, this._io, "/types/gguf_body/seq/0")
	}
	if !(this.Version <= 3) {
		return kaitai.NewValidationGreaterThanError(3, this.Version, this._io, "/types/gguf_body/seq/0")
	}
	tmp11, err := this._io.ReadU8le()
	if err != nil {
		return err
	}
	this.NumTensorInfos = uint64(tmp11)
	tmp12, err := this._io.ReadU8le()
	if err != nil {
		return err
	}
	this.NumKvPairs = uint64(tmp12)
	for i := 0; i < int(this.NumKvPairs); i++ {
		_ = i
		var tmp13 uint32;
		if (i != 0) {
			tmp14, err := this.KvPairs[i - 1].Alignment()
			if err != nil {
				return err
			}
			tmp13 = tmp14
		} else {
			tmp13 = 32
		}
		tmp15 := NewGguf_GgufBody_GgufKv(tmp13)
		err = tmp15.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.KvPairs = append(this.KvPairs, tmp15)
	}
	for i := 0; i < int(this.NumTensorInfos); i++ {
		_ = i
		var tmp16 uint64;
		if (i != 0) {
			tmp17, err := this.TensorInfos[i - 1].ExpectedNextOffset()
			if err != nil {
				return err
			}
			tmp16 = tmp17
		} else {
			tmp16 = 0
		}
		tmp18 := NewGguf_GgufBody_GgufTensorInfo(tmp16)
		err = tmp18.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.TensorInfos = append(this.TensorInfos, tmp18)
	}
	if (this.NumTensorInfos != 0) {
		tmp20, err := this.Alignment()
		if err != nil {
			return err
		}
		tmp22, err := this._io.Pos()
		if err != nil {
			return err
		}
		tmp23, err := this.Alignment()
		if err != nil {
			return err
		}
		tmp21 := tmp22 % tmp23
		if tmp21 < 0 {
			tmp24, err := this.Alignment()
			if err != nil {
				return err
			}
			tmp21 += tmp24
		}
		tmp25, err := this.Alignment()
		if err != nil {
			return err
		}
		tmp19 := (tmp20 - tmp21) % tmp25
		if tmp19 < 0 {
			tmp26, err := this.Alignment()
			if err != nil {
				return err
			}
			tmp19 += tmp26
		}
		tmp27, err := this._io.ReadBytes(int(tmp19))
		if err != nil {
			return err
		}
		tmp27 = tmp27
		this.Padding = tmp27
	}
	tmp28, err := this.OfsTensorData()
	if err != nil {
		return err
	}
	if (tmp28 < 0) {
		tmp29, err := this._io.ReadBytes(int(0))
		if err != nil {
			return err
		}
		tmp29 = tmp29
		this._unnamed6 = tmp29
	}
	return err
}

func (this *Gguf_GgufBody) _read_be() (err error) {
	tmp30, err := this._io.ReadU4be()
	if err != nil {
		return err
	}
	this.Version = uint32(tmp30)
	if !(this.Version >= 2) {
		return kaitai.NewValidationLessThanError(2, this.Version, this._io, "/types/gguf_body/seq/0")
	}
	if !(this.Version <= 3) {
		return kaitai.NewValidationGreaterThanError(3, this.Version, this._io, "/types/gguf_body/seq/0")
	}
	tmp31, err := this._io.ReadU8be()
	if err != nil {
		return err
	}
	this.NumTensorInfos = uint64(tmp31)
	tmp32, err := this._io.ReadU8be()
	if err != nil {
		return err
	}
	this.NumKvPairs = uint64(tmp32)
	for i := 0; i < int(this.NumKvPairs); i++ {
		_ = i
		var tmp33 uint32;
		if (i != 0) {
			tmp34, err := this.KvPairs[i - 1].Alignment()
			if err != nil {
				return err
			}
			tmp33 = tmp34
		} else {
			tmp33 = 32
		}
		tmp35 := NewGguf_GgufBody_GgufKv(tmp33)
		err = tmp35.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.KvPairs = append(this.KvPairs, tmp35)
	}
	for i := 0; i < int(this.NumTensorInfos); i++ {
		_ = i
		var tmp36 uint64;
		if (i != 0) {
			tmp37, err := this.TensorInfos[i - 1].ExpectedNextOffset()
			if err != nil {
				return err
			}
			tmp36 = tmp37
		} else {
			tmp36 = 0
		}
		tmp38 := NewGguf_GgufBody_GgufTensorInfo(tmp36)
		err = tmp38.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.TensorInfos = append(this.TensorInfos, tmp38)
	}
	if (this.NumTensorInfos != 0) {
		tmp40, err := this.Alignment()
		if err != nil {
			return err
		}
		tmp42, err := this._io.Pos()
		if err != nil {
			return err
		}
		tmp43, err := this.Alignment()
		if err != nil {
			return err
		}
		tmp41 := tmp42 % tmp43
		if tmp41 < 0 {
			tmp44, err := this.Alignment()
			if err != nil {
				return err
			}
			tmp41 += tmp44
		}
		tmp45, err := this.Alignment()
		if err != nil {
			return err
		}
		tmp39 := (tmp40 - tmp41) % tmp45
		if tmp39 < 0 {
			tmp46, err := this.Alignment()
			if err != nil {
				return err
			}
			tmp39 += tmp46
		}
		tmp47, err := this._io.ReadBytes(int(tmp39))
		if err != nil {
			return err
		}
		tmp47 = tmp47
		this.Padding = tmp47
	}
	tmp48, err := this.OfsTensorData()
	if err != nil {
		return err
	}
	if (tmp48 < 0) {
		tmp49, err := this._io.ReadBytes(int(0))
		if err != nil {
			return err
		}
		tmp49 = tmp49
		this._unnamed6 = tmp49
	}
	return err
}

/**
 * Global alignment - from the `general.alignment` key, or 32 if there's no
 * such key.
 * @see <a href="https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/src/gguf.cpp#L622-L630">Git tag "v0.27.0"</a>
 */
func (this *Gguf_GgufBody) Alignment() (v uint32, err error) {
	if (this._f_alignment) {
		return this.alignment, nil
	}
	this._f_alignment = true
	var tmp50 uint32;
	if (len(this.KvPairs) != 0) {
		tmp51 := this.KvPairs
		tmp52, err := tmp51[len(tmp51) - 1].Alignment()
		if err != nil {
			return 0, err
		}
		tmp50 = tmp52
	} else {
		tmp50 = 32
	}
	this.alignment = uint32(tmp50)
	return this.alignment, nil
}

/**
 * Offset of the tensor data. Each tensor's `offset` is relative to this
 * position.
 */
func (this *Gguf_GgufBody) OfsTensorData() (v uint64, err error) {
	if (this._f_ofsTensorData) {
		return this.ofsTensorData, nil
	}
	this._f_ofsTensorData = true
	tmp53, err := this._io.Pos()
	if err != nil {
		return 0, err
	}
	this.ofsTensorData = uint64(uint64(tmp53))
	return this.ofsTensorData, nil
}

/**
 * File format version. Version 1 used 32-bit counts and lengths, which
 * this Kaitai Struct implementation doesn't support, and neither does
 * ggml.
 */

/**
 * The number of tensors in the file
 */

/**
 * The number of key-value pairs in the file header
 */

/**
 * Key-value pairs. ggml (v0.27.0)
 * [rejects](https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/src/gguf.cpp#L575-L578)
 * duplicate keys, but this Kaitai Struct implementation can't detect
 * them. If there are multiple `general.alignment` keys, the last one is
 * used for the `alignment` value instance.
 */

/**
 * Tensor metadata. ggml (v0.27.0)
 * [rejects](https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/src/gguf.cpp#L664-L669)
 * duplicate tensor names, but this Kaitai Struct implementation can't
 * detect them.
 */

/**
 * @see <a href="https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/src/gguf.cpp#L780-L785">Git tag "v0.27.0"</a>
 */

/**
 * Nested arrays are supported. Although ggml (v0.27.0) doesn't support them,
 * they are explicitly allowed by `gguf.md` - see
 * <https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/docs/gguf.md?plain=1#L221>.
 */
type Gguf_GgufBody_GgufArray struct {
	Type Gguf_GgufType
	NumElems uint64
	Elems []*Gguf_GgufBody_GgufValue
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_is_le int
}
func NewGguf_GgufBody_GgufArray() *Gguf_GgufBody_GgufArray {
	return &Gguf_GgufBody_GgufArray{
	}
}

func (this Gguf_GgufBody_GgufArray) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufArray) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufArray) _read_le() (err error) {
	tmp54, err := this._io.ReadU4le()
	if err != nil {
		return err
	}
	this.Type = Gguf_GgufType(tmp54)
	if !this.Type.isDefined() {
		return kaitai.NewValidationNotInEnumError(this.Type, this._io, "/types/gguf_body/types/gguf_array/seq/0")
	}
	tmp55, err := this._io.ReadU8le()
	if err != nil {
		return err
	}
	this.NumElems = uint64(tmp55)
	for i := 0; i < int(this.NumElems); i++ {
		_ = i
		tmp56 := NewGguf_GgufBody_GgufValue(this.Type)
		err = tmp56.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Elems = append(this.Elems, tmp56)
	}
	return err
}

func (this *Gguf_GgufBody_GgufArray) _read_be() (err error) {
	tmp57, err := this._io.ReadU4be()
	if err != nil {
		return err
	}
	this.Type = Gguf_GgufType(tmp57)
	if !this.Type.isDefined() {
		return kaitai.NewValidationNotInEnumError(this.Type, this._io, "/types/gguf_body/types/gguf_array/seq/0")
	}
	tmp58, err := this._io.ReadU8be()
	if err != nil {
		return err
	}
	this.NumElems = uint64(tmp58)
	for i := 0; i < int(this.NumElems); i++ {
		_ = i
		tmp59 := NewGguf_GgufBody_GgufValue(this.Type)
		err = tmp59.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Elems = append(this.Elems, tmp59)
	}
	return err
}
type Gguf_GgufBody_GgufBool struct {
	ValueRaw uint8
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_f_value bool
	value bool
	_is_le int
}
func NewGguf_GgufBody_GgufBool() *Gguf_GgufBody_GgufBool {
	return &Gguf_GgufBody_GgufBool{
	}
}

func (this Gguf_GgufBody_GgufBool) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufBool) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufBool) _read_le() (err error) {
	tmp60, err := this._io.ReadU1()
	if err != nil {
		return err
	}
	this.ValueRaw = tmp60
	if !(this.ValueRaw <= 1) {
		return kaitai.NewValidationGreaterThanError(1, this.ValueRaw, this._io, "/types/gguf_body/types/gguf_bool/seq/0")
	}
	return err
}

func (this *Gguf_GgufBody_GgufBool) _read_be() (err error) {
	tmp61, err := this._io.ReadU1()
	if err != nil {
		return err
	}
	this.ValueRaw = tmp61
	if !(this.ValueRaw <= 1) {
		return kaitai.NewValidationGreaterThanError(1, this.ValueRaw, this._io, "/types/gguf_body/types/gguf_bool/seq/0")
	}
	return err
}

/**
 * @see <a href="https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/src/gguf.cpp#L321">Git tag "v0.27.0"</a>
 */
func (this *Gguf_GgufBody_GgufBool) Value() (v bool, err error) {
	if (this._f_value) {
		return this.value, nil
	}
	this._f_value = true
	this.value = bool(this.ValueRaw != 0)
	return this.value, nil
}
type Gguf_GgufBody_GgufFloat32 struct {
	Value float32
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_is_le int
}
func NewGguf_GgufBody_GgufFloat32() *Gguf_GgufBody_GgufFloat32 {
	return &Gguf_GgufBody_GgufFloat32{
	}
}

func (this Gguf_GgufBody_GgufFloat32) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufFloat32) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufFloat32) _read_le() (err error) {
	tmp62, err := this._io.ReadF4le()
	if err != nil {
		return err
	}
	this.Value = float32(tmp62)
	return err
}

func (this *Gguf_GgufBody_GgufFloat32) _read_be() (err error) {
	tmp63, err := this._io.ReadF4be()
	if err != nil {
		return err
	}
	this.Value = float32(tmp63)
	return err
}
type Gguf_GgufBody_GgufFloat64 struct {
	Value float64
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_is_le int
}
func NewGguf_GgufBody_GgufFloat64() *Gguf_GgufBody_GgufFloat64 {
	return &Gguf_GgufBody_GgufFloat64{
	}
}

func (this Gguf_GgufBody_GgufFloat64) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufFloat64) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufFloat64) _read_le() (err error) {
	tmp64, err := this._io.ReadF8le()
	if err != nil {
		return err
	}
	this.Value = float64(tmp64)
	return err
}

func (this *Gguf_GgufBody_GgufFloat64) _read_be() (err error) {
	tmp65, err := this._io.ReadF8be()
	if err != nil {
		return err
	}
	this.Value = float64(tmp65)
	return err
}
type Gguf_GgufBody_GgufInt16 struct {
	Value int16
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_is_le int
}
func NewGguf_GgufBody_GgufInt16() *Gguf_GgufBody_GgufInt16 {
	return &Gguf_GgufBody_GgufInt16{
	}
}

func (this Gguf_GgufBody_GgufInt16) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufInt16) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufInt16) _read_le() (err error) {
	tmp66, err := this._io.ReadS2le()
	if err != nil {
		return err
	}
	this.Value = int16(tmp66)
	return err
}

func (this *Gguf_GgufBody_GgufInt16) _read_be() (err error) {
	tmp67, err := this._io.ReadS2be()
	if err != nil {
		return err
	}
	this.Value = int16(tmp67)
	return err
}
type Gguf_GgufBody_GgufInt32 struct {
	Value int32
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_is_le int
}
func NewGguf_GgufBody_GgufInt32() *Gguf_GgufBody_GgufInt32 {
	return &Gguf_GgufBody_GgufInt32{
	}
}

func (this Gguf_GgufBody_GgufInt32) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufInt32) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufInt32) _read_le() (err error) {
	tmp68, err := this._io.ReadS4le()
	if err != nil {
		return err
	}
	this.Value = int32(tmp68)
	return err
}

func (this *Gguf_GgufBody_GgufInt32) _read_be() (err error) {
	tmp69, err := this._io.ReadS4be()
	if err != nil {
		return err
	}
	this.Value = int32(tmp69)
	return err
}
type Gguf_GgufBody_GgufInt64 struct {
	Value int64
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_is_le int
}
func NewGguf_GgufBody_GgufInt64() *Gguf_GgufBody_GgufInt64 {
	return &Gguf_GgufBody_GgufInt64{
	}
}

func (this Gguf_GgufBody_GgufInt64) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufInt64) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufInt64) _read_le() (err error) {
	tmp70, err := this._io.ReadS8le()
	if err != nil {
		return err
	}
	this.Value = int64(tmp70)
	return err
}

func (this *Gguf_GgufBody_GgufInt64) _read_be() (err error) {
	tmp71, err := this._io.ReadS8be()
	if err != nil {
		return err
	}
	this.Value = int64(tmp71)
	return err
}
type Gguf_GgufBody_GgufInt8 struct {
	Value int8
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_is_le int
}
func NewGguf_GgufBody_GgufInt8() *Gguf_GgufBody_GgufInt8 {
	return &Gguf_GgufBody_GgufInt8{
	}
}

func (this Gguf_GgufBody_GgufInt8) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufInt8) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufInt8) _read_le() (err error) {
	tmp72, err := this._io.ReadS1()
	if err != nil {
		return err
	}
	this.Value = tmp72
	return err
}

func (this *Gguf_GgufBody_GgufInt8) _read_be() (err error) {
	tmp73, err := this._io.ReadS1()
	if err != nil {
		return err
	}
	this.Value = tmp73
	return err
}

/**
 * @see <a href="https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/docs/gguf.md?plain=1#L262-L275">Git tag "v0.27.0"</a>
 */
type Gguf_GgufBody_GgufKv struct {
	Key *Gguf_GgufBody_GgufStr
	Type Gguf_GgufType
	Value *Gguf_GgufBody_GgufValue
	PrevAlignment uint32
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody
	_f_alignment bool
	alignment uint32
	_is_le int
}
func NewGguf_GgufBody_GgufKv(prevAlignment uint32) *Gguf_GgufBody_GgufKv {
	return &Gguf_GgufBody_GgufKv{
		PrevAlignment: prevAlignment,
	}
}

func (this Gguf_GgufBody_GgufKv) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufKv) Read(io *kaitai.Stream, parent *Gguf_GgufBody, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufKv) _read_le() (err error) {
	tmp74 := NewGguf_GgufBody_GgufStr()
	err = tmp74.Read(this._io, this, this._root)
	if err != nil {
		return err
	}
	this.Key = tmp74
	{
		_it := this.Key
		if !(_it.LenValue != 0) {
			return kaitai.NewValidationExprError(this.Key, this._io, "/types/gguf_body/types/gguf_kv/seq/0")
		}
	}
	tmp75, err := this._io.ReadU4le()
	if err != nil {
		return err
	}
	this.Type = Gguf_GgufType(tmp75)
	if !this.Type.isDefined() {
		return kaitai.NewValidationNotInEnumError(this.Type, this._io, "/types/gguf_body/types/gguf_kv/seq/1")
	}
	tmp76 := NewGguf_GgufBody_GgufValue(this.Type)
	err = tmp76.Read(this._io, this, this._root)
	if err != nil {
		return err
	}
	this.Value = tmp76
	{
		_it := this.Value
		var tmp77 bool;
		if (this.Key.Value == "general.alignment") {
			tmp77 =  ((this.Type == Gguf_GgufType__Uint32) && (_it.Value.(*Gguf_GgufBody_GgufUint32).Value != 0) && (_it.Value.(*Gguf_GgufBody_GgufUint32).Value & (_it.Value.(*Gguf_GgufBody_GgufUint32).Value - 1) == 0)) 
		} else {
			tmp77 = true
		}
		if !(tmp77) {
			return kaitai.NewValidationExprError(this.Value, this._io, "/types/gguf_body/types/gguf_kv/seq/2")
		}
	}
	return err
}

func (this *Gguf_GgufBody_GgufKv) _read_be() (err error) {
	tmp78 := NewGguf_GgufBody_GgufStr()
	err = tmp78.Read(this._io, this, this._root)
	if err != nil {
		return err
	}
	this.Key = tmp78
	{
		_it := this.Key
		if !(_it.LenValue != 0) {
			return kaitai.NewValidationExprError(this.Key, this._io, "/types/gguf_body/types/gguf_kv/seq/0")
		}
	}
	tmp79, err := this._io.ReadU4be()
	if err != nil {
		return err
	}
	this.Type = Gguf_GgufType(tmp79)
	if !this.Type.isDefined() {
		return kaitai.NewValidationNotInEnumError(this.Type, this._io, "/types/gguf_body/types/gguf_kv/seq/1")
	}
	tmp80 := NewGguf_GgufBody_GgufValue(this.Type)
	err = tmp80.Read(this._io, this, this._root)
	if err != nil {
		return err
	}
	this.Value = tmp80
	{
		_it := this.Value
		var tmp81 bool;
		if (this.Key.Value == "general.alignment") {
			tmp81 =  ((this.Type == Gguf_GgufType__Uint32) && (_it.Value.(*Gguf_GgufBody_GgufUint32).Value != 0) && (_it.Value.(*Gguf_GgufBody_GgufUint32).Value & (_it.Value.(*Gguf_GgufBody_GgufUint32).Value - 1) == 0)) 
		} else {
			tmp81 = true
		}
		if !(tmp81) {
			return kaitai.NewValidationExprError(this.Value, this._io, "/types/gguf_body/types/gguf_kv/seq/2")
		}
	}
	return err
}
func (this *Gguf_GgufBody_GgufKv) Alignment() (v uint32, err error) {
	if (this._f_alignment) {
		return this.alignment, nil
	}
	this._f_alignment = true
	var tmp82 uint32;
	if (this.Key.Value == "general.alignment") {
		tmp82 = this.Value.Value.(*Gguf_GgufBody_GgufUint32).Value
	} else {
		tmp82 = this.PrevAlignment
	}
	this.alignment = uint32(tmp82)
	return this.alignment, nil
}

/**
 * @see <a href="https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/docs/gguf.md?plain=1#L232-L237">Git tag "v0.27.0"</a>
 */
type Gguf_GgufBody_GgufStr struct {
	LenValue uint64
	Value string
	_io *kaitai.Stream
	_root *Gguf
	_parent kaitai.Struct
	_is_le int
}
func NewGguf_GgufBody_GgufStr() *Gguf_GgufBody_GgufStr {
	return &Gguf_GgufBody_GgufStr{
	}
}

func (this Gguf_GgufBody_GgufStr) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufStr) Read(io *kaitai.Stream, parent kaitai.Struct, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufStr) _read_le() (err error) {
	tmp83, err := this._io.ReadU8le()
	if err != nil {
		return err
	}
	this.LenValue = uint64(tmp83)
	tmp84, err := this._io.ReadBytes(int(this.LenValue))
	if err != nil {
		return err
	}
	tmp84 = tmp84
	this.Value = string(tmp84)
	return err
}

func (this *Gguf_GgufBody_GgufStr) _read_be() (err error) {
	tmp85, err := this._io.ReadU8be()
	if err != nil {
		return err
	}
	this.LenValue = uint64(tmp85)
	tmp86, err := this._io.ReadBytes(int(this.LenValue))
	if err != nil {
		return err
	}
	tmp86 = tmp86
	this.Value = string(tmp86)
	return err
}

/**
 * @see <a href="https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/docs/gguf.md?plain=1#L305-L325">Git tag "v0.27.0"</a>
 */
type Gguf_GgufBody_GgufTensorInfo struct {
	Name *Gguf_GgufBody_GgufStr
	NumDims uint32
	Dims []int64
	Type Gguf_GgmlType
	Offset uint64
	ExpectedOffset uint64
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody
	_f_data bool
	data []byte
	_f_dumpDims bool
	dumpDims string
	_f_expectedNextOffset bool
	expectedNextOffset uint64
	_f_lenBlock bool
	lenBlock int
	_f_lenData bool
	lenData uint64
	_f_lenPadding bool
	lenPadding int
	_f_numBlocks bool
	numBlocks int64
	_f_numElements bool
	numElements int64
	_f_numElementsPerBlock bool
	numElementsPerBlock int
	_f_padding bool
	padding []byte
	_is_le int
}
func NewGguf_GgufBody_GgufTensorInfo(expectedOffset uint64) *Gguf_GgufBody_GgufTensorInfo {
	return &Gguf_GgufBody_GgufTensorInfo{
		ExpectedOffset: expectedOffset,
	}
}

func (this Gguf_GgufBody_GgufTensorInfo) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufTensorInfo) Read(io *kaitai.Stream, parent *Gguf_GgufBody, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufTensorInfo) _read_le() (err error) {
	tmp87 := NewGguf_GgufBody_GgufStr()
	err = tmp87.Read(this._io, this, this._root)
	if err != nil {
		return err
	}
	this.Name = tmp87
	{
		_it := this.Name
		if !(_it.LenValue < 64) {
			return kaitai.NewValidationExprError(this.Name, this._io, "/types/gguf_body/types/gguf_tensor_info/seq/0")
		}
	}
	tmp88, err := this._io.ReadU4le()
	if err != nil {
		return err
	}
	this.NumDims = uint32(tmp88)
	if !(this.NumDims <= 4) {
		return kaitai.NewValidationGreaterThanError(4, this.NumDims, this._io, "/types/gguf_body/types/gguf_tensor_info/seq/1")
	}
	for i := 0; i < int(this.NumDims); i++ {
		_ = i
		tmp89, err := this._io.ReadS8le()
		if err != nil {
			return err
		}
		this.Dims = append(this.Dims, tmp89)
		if !(this.Dims[i] >= 0) {
			return kaitai.NewValidationLessThanError(0, this.Dims[i], this._io, "/types/gguf_body/types/gguf_tensor_info/seq/2")
		}
	}
	tmp90, err := this._io.ReadU4le()
	if err != nil {
		return err
	}
	this.Type = Gguf_GgmlType(tmp90)
	{
		_it := this.Type
		tmp91, err := this.NumElementsPerBlock()
		if err != nil {
			return err
		}
		var tmp93 int64;
		if (this.NumDims > 0) {
			tmp93 = this.Dims[0]
		} else {
			tmp93 = 1
		}
		tmp94, err := this.NumElementsPerBlock()
		if err != nil {
			return err
		}
		tmp92 := tmp93 % tmp94
		if tmp92 < 0 {
			tmp95, err := this.NumElementsPerBlock()
			if err != nil {
				return err
			}
			tmp92 += tmp95
		}
		if !( ((_it < 43) && (tmp91 != 0) && (tmp92 == 0)) ) {
			return kaitai.NewValidationExprError(this.Type, this._io, "/types/gguf_body/types/gguf_tensor_info/seq/3")
		}
	}
	tmp96, err := this._io.ReadU8le()
	if err != nil {
		return err
	}
	this.Offset = uint64(tmp96)
	if !(this.Offset == this.ExpectedOffset) {
		return kaitai.NewValidationNotEqualError(this.ExpectedOffset, this.Offset, this._io, "/types/gguf_body/types/gguf_tensor_info/seq/4")
	}
	return err
}

func (this *Gguf_GgufBody_GgufTensorInfo) _read_be() (err error) {
	tmp97 := NewGguf_GgufBody_GgufStr()
	err = tmp97.Read(this._io, this, this._root)
	if err != nil {
		return err
	}
	this.Name = tmp97
	{
		_it := this.Name
		if !(_it.LenValue < 64) {
			return kaitai.NewValidationExprError(this.Name, this._io, "/types/gguf_body/types/gguf_tensor_info/seq/0")
		}
	}
	tmp98, err := this._io.ReadU4be()
	if err != nil {
		return err
	}
	this.NumDims = uint32(tmp98)
	if !(this.NumDims <= 4) {
		return kaitai.NewValidationGreaterThanError(4, this.NumDims, this._io, "/types/gguf_body/types/gguf_tensor_info/seq/1")
	}
	for i := 0; i < int(this.NumDims); i++ {
		_ = i
		tmp99, err := this._io.ReadS8be()
		if err != nil {
			return err
		}
		this.Dims = append(this.Dims, tmp99)
		if !(this.Dims[i] >= 0) {
			return kaitai.NewValidationLessThanError(0, this.Dims[i], this._io, "/types/gguf_body/types/gguf_tensor_info/seq/2")
		}
	}
	tmp100, err := this._io.ReadU4be()
	if err != nil {
		return err
	}
	this.Type = Gguf_GgmlType(tmp100)
	{
		_it := this.Type
		tmp101, err := this.NumElementsPerBlock()
		if err != nil {
			return err
		}
		var tmp103 int64;
		if (this.NumDims > 0) {
			tmp103 = this.Dims[0]
		} else {
			tmp103 = 1
		}
		tmp104, err := this.NumElementsPerBlock()
		if err != nil {
			return err
		}
		tmp102 := tmp103 % tmp104
		if tmp102 < 0 {
			tmp105, err := this.NumElementsPerBlock()
			if err != nil {
				return err
			}
			tmp102 += tmp105
		}
		if !( ((_it < 43) && (tmp101 != 0) && (tmp102 == 0)) ) {
			return kaitai.NewValidationExprError(this.Type, this._io, "/types/gguf_body/types/gguf_tensor_info/seq/3")
		}
	}
	tmp106, err := this._io.ReadU8be()
	if err != nil {
		return err
	}
	this.Offset = uint64(tmp106)
	if !(this.Offset == this.ExpectedOffset) {
		return kaitai.NewValidationNotEqualError(this.ExpectedOffset, this.Offset, this._io, "/types/gguf_body/types/gguf_tensor_info/seq/4")
	}
	return err
}
func (this *Gguf_GgufBody_GgufTensorInfo) Data() (v []byte, err error) {
	if (this._f_data) {
		return this.data, nil
	}
	this._f_data = true
	_pos, err := this._io.Pos()
	if err != nil {
		return nil, err
	}
	tmp107, err := this._parent.OfsTensorData()
	if err != nil {
		return nil, err
	}
	_, err = this._io.Seek(int64(tmp107 + this.Offset), io.SeekStart)
	if err != nil {
		return nil, err
	}
	switch this._is_le {
	case 0:
		tmp108, err := this.LenData()
		if err != nil {
			return nil, err
		}
		tmp109, err := this._io.ReadBytes(int(tmp108))
		if err != nil {
			return nil, err
		}
		tmp109 = tmp109
		this.data = tmp109
	case 1:
		tmp110, err := this.LenData()
		if err != nil {
			return nil, err
		}
		tmp111, err := this._io.ReadBytes(int(tmp110))
		if err != nil {
			return nil, err
		}
		tmp111 = tmp111
		this.data = tmp111
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	_, err = this._io.Seek(_pos, io.SeekStart)
	if err != nil {
		return nil, err
	}
	return this.data, nil
}

/**
 * `dims` joined with the string `" x "`. This is necessary for
 * `-webide-representation`, which cannot format `dims` directly -
 * see <https://github.com/kaitai-io/kaitai_struct_webide/issues/160>.
 */
func (this *Gguf_GgufBody_GgufTensorInfo) DumpDims() (v string, err error) {
	if (this._f_dumpDims) {
		return this.dumpDims, nil
	}
	this._f_dumpDims = true
	var tmp112 string;
	if (this.NumDims > 0) {
		tmp112 = strconv.FormatInt(int64(this.Dims[0]), 10)
	} else {
		tmp112 = ""
	}
	var tmp113 string;
	if (this.NumDims > 1) {
		tmp113 = " x " + strconv.FormatInt(int64(this.Dims[1]), 10)
	} else {
		tmp113 = ""
	}
	var tmp114 string;
	if (this.NumDims > 2) {
		tmp114 = " x " + strconv.FormatInt(int64(this.Dims[2]), 10)
	} else {
		tmp114 = ""
	}
	var tmp115 string;
	if (this.NumDims > 3) {
		tmp115 = " x " + strconv.FormatInt(int64(this.Dims[3]), 10)
	} else {
		tmp115 = ""
	}
	this.dumpDims = string(((tmp112 + tmp113) + tmp114) + tmp115)
	return this.dumpDims, nil
}

/**
 * `offset` that the next tensor must have
 */
func (this *Gguf_GgufBody_GgufTensorInfo) ExpectedNextOffset() (v uint64, err error) {
	if (this._f_expectedNextOffset) {
		return this.expectedNextOffset, nil
	}
	this._f_expectedNextOffset = true
	tmp116, err := this.LenData()
	if err != nil {
		return 0, err
	}
	tmp117, err := this.LenPadding()
	if err != nil {
		return 0, err
	}
	this.expectedNextOffset = uint64(uint64((this.Offset + tmp116) + tmp117))
	return this.expectedNextOffset, nil
}

/**
 * Size of a block in bytes
 */
func (this *Gguf_GgufBody_GgufTensorInfo) LenBlock() (v int, err error) {
	if (this._f_lenBlock) {
		return this.lenBlock, nil
	}
	this._f_lenBlock = true
	this.lenBlock = int([]int{4, 2, 18, 20, 0, 0, 22, 24, 34, 36, 84, 110, 144, 176, 210, 292, 66, 74, 98, 50, 18, 110, 82, 136, 1, 2, 4, 8, 8, 56, 2, 0, 0, 0, 54, 66, 0, 0, 0, 17, 36, 18, 18}[this.Type])
	return this.lenBlock, nil
}
func (this *Gguf_GgufBody_GgufTensorInfo) LenData() (v uint64, err error) {
	if (this._f_lenData) {
		return this.lenData, nil
	}
	this._f_lenData = true
	tmp118, err := this.LenBlock()
	if err != nil {
		return 0, err
	}
	tmp119, err := this.NumBlocks()
	if err != nil {
		return 0, err
	}
	this.lenData = uint64(uint64(tmp118 * tmp119))
	return this.lenData, nil
}

/**
 * Number of padding bytes after the data
 */
func (this *Gguf_GgufBody_GgufTensorInfo) LenPadding() (v int, err error) {
	if (this._f_lenPadding) {
		return this.lenPadding, nil
	}
	this._f_lenPadding = true
	tmp121, err := this._parent.Alignment()
	if err != nil {
		return 0, err
	}
	tmp123, err := this.LenData()
	if err != nil {
		return 0, err
	}
	tmp124, err := this._parent.Alignment()
	if err != nil {
		return 0, err
	}
	tmp122 := tmp123 % tmp124
	if tmp122 < 0 {
		tmp125, err := this._parent.Alignment()
		if err != nil {
			return 0, err
		}
		tmp122 += tmp125
	}
	tmp126, err := this._parent.Alignment()
	if err != nil {
		return 0, err
	}
	tmp120 := (tmp121 - tmp122) % tmp126
	if tmp120 < 0 {
		tmp127, err := this._parent.Alignment()
		if err != nil {
			return 0, err
		}
		tmp120 += tmp127
	}
	this.lenPadding = int(tmp120)
	return this.lenPadding, nil
}
func (this *Gguf_GgufBody_GgufTensorInfo) NumBlocks() (v int64, err error) {
	if (this._f_numBlocks) {
		return this.numBlocks, nil
	}
	this._f_numBlocks = true
	tmp128, err := this.NumElements()
	if err != nil {
		return 0, err
	}
	tmp129, err := this.NumElementsPerBlock()
	if err != nil {
		return 0, err
	}
	this.numBlocks = int64(int64(tmp128 / tmp129))
	return this.numBlocks, nil
}
func (this *Gguf_GgufBody_GgufTensorInfo) NumElements() (v int64, err error) {
	if (this._f_numElements) {
		return this.numElements, nil
	}
	this._f_numElements = true
	var tmp130 int64;
	if (this.NumDims > 0) {
		tmp130 = this.Dims[0]
	} else {
		tmp130 = 1
	}
	var tmp131 int64;
	if (this.NumDims > 1) {
		tmp131 = this.Dims[1]
	} else {
		tmp131 = 1
	}
	var tmp132 int64;
	if (this.NumDims > 2) {
		tmp132 = this.Dims[2]
	} else {
		tmp132 = 1
	}
	var tmp133 int64;
	if (this.NumDims > 3) {
		tmp133 = this.Dims[3]
	} else {
		tmp133 = 1
	}
	this.numElements = int64(int64(((tmp130 * tmp131) * tmp132) * tmp133))
	return this.numElements, nil
}

/**
 * Number of elements in a block
 */
func (this *Gguf_GgufBody_GgufTensorInfo) NumElementsPerBlock() (v int, err error) {
	if (this._f_numElementsPerBlock) {
		return this.numElementsPerBlock, nil
	}
	this._f_numElementsPerBlock = true
	this.numElementsPerBlock = int([]int{1, 1, 32, 32, 0, 0, 32, 32, 32, 32, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 32, 256, 256, 256, 1, 1, 1, 1, 1, 256, 1, 0, 0, 0, 256, 256, 0, 0, 0, 32, 64, 128, 64}[this.Type])
	return this.numElementsPerBlock, nil
}

/**
 * Padding after the data. ggml requires it even after the last tensor
 * when reading the tensor data.
 * @see <a href="https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/src/gguf.cpp#L884-L893">Git tag "v0.27.0"</a>
 */
func (this *Gguf_GgufBody_GgufTensorInfo) Padding() (v []byte, err error) {
	if (this._f_padding) {
		return this.padding, nil
	}
	this._f_padding = true
	_pos, err := this._io.Pos()
	if err != nil {
		return nil, err
	}
	tmp134, err := this._parent.OfsTensorData()
	if err != nil {
		return nil, err
	}
	tmp135, err := this.LenData()
	if err != nil {
		return nil, err
	}
	_, err = this._io.Seek(int64((tmp134 + this.Offset) + tmp135), io.SeekStart)
	if err != nil {
		return nil, err
	}
	switch this._is_le {
	case 0:
		tmp136, err := this.LenPadding()
		if err != nil {
			return nil, err
		}
		tmp137, err := this._io.ReadBytes(int(tmp136))
		if err != nil {
			return nil, err
		}
		tmp137 = tmp137
		this.padding = tmp137
	case 1:
		tmp138, err := this.LenPadding()
		if err != nil {
			return nil, err
		}
		tmp139, err := this._io.ReadBytes(int(tmp138))
		if err != nil {
			return nil, err
		}
		tmp139 = tmp139
		this.padding = tmp139
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	_, err = this._io.Seek(_pos, io.SeekStart)
	if err != nil {
		return nil, err
	}
	return this.padding, nil
}

/**
 * Offset of the tensor's data, relative to `_parent.ofs_tensor_data`
 */
type Gguf_GgufBody_GgufUint16 struct {
	Value uint16
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_is_le int
}
func NewGguf_GgufBody_GgufUint16() *Gguf_GgufBody_GgufUint16 {
	return &Gguf_GgufBody_GgufUint16{
	}
}

func (this Gguf_GgufBody_GgufUint16) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufUint16) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufUint16) _read_le() (err error) {
	tmp140, err := this._io.ReadU2le()
	if err != nil {
		return err
	}
	this.Value = uint16(tmp140)
	return err
}

func (this *Gguf_GgufBody_GgufUint16) _read_be() (err error) {
	tmp141, err := this._io.ReadU2be()
	if err != nil {
		return err
	}
	this.Value = uint16(tmp141)
	return err
}
type Gguf_GgufBody_GgufUint32 struct {
	Value uint32
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_is_le int
}
func NewGguf_GgufBody_GgufUint32() *Gguf_GgufBody_GgufUint32 {
	return &Gguf_GgufBody_GgufUint32{
	}
}

func (this Gguf_GgufBody_GgufUint32) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufUint32) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufUint32) _read_le() (err error) {
	tmp142, err := this._io.ReadU4le()
	if err != nil {
		return err
	}
	this.Value = uint32(tmp142)
	return err
}

func (this *Gguf_GgufBody_GgufUint32) _read_be() (err error) {
	tmp143, err := this._io.ReadU4be()
	if err != nil {
		return err
	}
	this.Value = uint32(tmp143)
	return err
}
type Gguf_GgufBody_GgufUint64 struct {
	Value uint64
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_is_le int
}
func NewGguf_GgufBody_GgufUint64() *Gguf_GgufBody_GgufUint64 {
	return &Gguf_GgufBody_GgufUint64{
	}
}

func (this Gguf_GgufBody_GgufUint64) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufUint64) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufUint64) _read_le() (err error) {
	tmp144, err := this._io.ReadU8le()
	if err != nil {
		return err
	}
	this.Value = uint64(tmp144)
	return err
}

func (this *Gguf_GgufBody_GgufUint64) _read_be() (err error) {
	tmp145, err := this._io.ReadU8be()
	if err != nil {
		return err
	}
	this.Value = uint64(tmp145)
	return err
}
type Gguf_GgufBody_GgufUint8 struct {
	Value uint8
	_io *kaitai.Stream
	_root *Gguf
	_parent *Gguf_GgufBody_GgufValue
	_is_le int
}
func NewGguf_GgufBody_GgufUint8() *Gguf_GgufBody_GgufUint8 {
	return &Gguf_GgufBody_GgufUint8{
	}
}

func (this Gguf_GgufBody_GgufUint8) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufUint8) Read(io *kaitai.Stream, parent *Gguf_GgufBody_GgufValue, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufUint8) _read_le() (err error) {
	tmp146, err := this._io.ReadU1()
	if err != nil {
		return err
	}
	this.Value = tmp146
	return err
}

func (this *Gguf_GgufBody_GgufUint8) _read_be() (err error) {
	tmp147, err := this._io.ReadU1()
	if err != nil {
		return err
	}
	this.Value = tmp147
	return err
}

/**
 * @see <a href="https://github.com/ggml-org/ggml/blob/a05c9922613c6a2230dbb1d0de679519ecafb4f0/docs/gguf.md?plain=1#L239-L260">Git tag "v0.27.0"</a>
 */
type Gguf_GgufBody_GgufValue struct {
	Value kaitai.Struct
	Type Gguf_GgufType
	_io *kaitai.Stream
	_root *Gguf
	_parent kaitai.Struct
	_is_le int
}
func NewGguf_GgufBody_GgufValue(type Gguf_GgufType) *Gguf_GgufBody_GgufValue {
	return &Gguf_GgufBody_GgufValue{
		Type: type,
	}
}

func (this Gguf_GgufBody_GgufValue) IO_() *kaitai.Stream {
	return this._io
}

func (this *Gguf_GgufBody_GgufValue) Read(io *kaitai.Stream, parent kaitai.Struct, root *Gguf) (err error) {
	this._io = io
	this._parent = parent
	this._root = root
	this._is_le = this._parent._is_le


	switch this._is_le {
	case 0:
		err = this._read_be()
	case 1:
		err = this._read_le()
	default:
		err = kaitai.UndecidedEndiannessError{}
	}
	return err
}

func (this *Gguf_GgufBody_GgufValue) _read_le() (err error) {
	switch (this.Type) {
	case Gguf_GgufType__Array:
		tmp148 := NewGguf_GgufBody_GgufArray()
		err = tmp148.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp148
	case Gguf_GgufType__Bool:
		tmp149 := NewGguf_GgufBody_GgufBool()
		err = tmp149.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp149
	case Gguf_GgufType__Float32:
		tmp150 := NewGguf_GgufBody_GgufFloat32()
		err = tmp150.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp150
	case Gguf_GgufType__Float64:
		tmp151 := NewGguf_GgufBody_GgufFloat64()
		err = tmp151.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp151
	case Gguf_GgufType__Int16:
		tmp152 := NewGguf_GgufBody_GgufInt16()
		err = tmp152.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp152
	case Gguf_GgufType__Int32:
		tmp153 := NewGguf_GgufBody_GgufInt32()
		err = tmp153.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp153
	case Gguf_GgufType__Int64:
		tmp154 := NewGguf_GgufBody_GgufInt64()
		err = tmp154.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp154
	case Gguf_GgufType__Int8:
		tmp155 := NewGguf_GgufBody_GgufInt8()
		err = tmp155.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp155
	case Gguf_GgufType__String:
		tmp156 := NewGguf_GgufBody_GgufStr()
		err = tmp156.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp156
	case Gguf_GgufType__Uint16:
		tmp157 := NewGguf_GgufBody_GgufUint16()
		err = tmp157.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp157
	case Gguf_GgufType__Uint32:
		tmp158 := NewGguf_GgufBody_GgufUint32()
		err = tmp158.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp158
	case Gguf_GgufType__Uint64:
		tmp159 := NewGguf_GgufBody_GgufUint64()
		err = tmp159.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp159
	case Gguf_GgufType__Uint8:
		tmp160 := NewGguf_GgufBody_GgufUint8()
		err = tmp160.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp160
	}
	return err
}

func (this *Gguf_GgufBody_GgufValue) _read_be() (err error) {
	switch (this.Type) {
	case Gguf_GgufType__Array:
		tmp161 := NewGguf_GgufBody_GgufArray()
		err = tmp161.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp161
	case Gguf_GgufType__Bool:
		tmp162 := NewGguf_GgufBody_GgufBool()
		err = tmp162.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp162
	case Gguf_GgufType__Float32:
		tmp163 := NewGguf_GgufBody_GgufFloat32()
		err = tmp163.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp163
	case Gguf_GgufType__Float64:
		tmp164 := NewGguf_GgufBody_GgufFloat64()
		err = tmp164.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp164
	case Gguf_GgufType__Int16:
		tmp165 := NewGguf_GgufBody_GgufInt16()
		err = tmp165.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp165
	case Gguf_GgufType__Int32:
		tmp166 := NewGguf_GgufBody_GgufInt32()
		err = tmp166.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp166
	case Gguf_GgufType__Int64:
		tmp167 := NewGguf_GgufBody_GgufInt64()
		err = tmp167.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp167
	case Gguf_GgufType__Int8:
		tmp168 := NewGguf_GgufBody_GgufInt8()
		err = tmp168.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp168
	case Gguf_GgufType__String:
		tmp169 := NewGguf_GgufBody_GgufStr()
		err = tmp169.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp169
	case Gguf_GgufType__Uint16:
		tmp170 := NewGguf_GgufBody_GgufUint16()
		err = tmp170.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp170
	case Gguf_GgufType__Uint32:
		tmp171 := NewGguf_GgufBody_GgufUint32()
		err = tmp171.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp171
	case Gguf_GgufType__Uint64:
		tmp172 := NewGguf_GgufBody_GgufUint64()
		err = tmp172.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp172
	case Gguf_GgufType__Uint8:
		tmp173 := NewGguf_GgufBody_GgufUint8()
		err = tmp173.Read(this._io, this, this._root)
		if err != nil {
			return err
		}
		this.Value = tmp173
	}
	return err
}