convert

package
v0.9.22 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 13, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const BundledConverterLLamacppRef = "b9158"

BundledConverterLLamacppRef documents the llama.cpp release tag the bundled script was taken from.

Variables

This section is empty.

Functions

func AllowedDTypes

func AllowedDTypes() []string

AllowedDTypes returns the converter output dtypes accepted by csghub-lite.

func Convert

func Convert(modelDir string, progress ProgressFunc, dtype string) (string, error)

Convert converts HuggingFace model files in modelDir to a GGUF file. It runs the llama.cpp convert_hf_to_gguf.py bundled in the binary (or from CSGHUB_LITE_CONVERTER_URL when set); see convert_python.go.

func ConvertPython

func ConvertPython(modelDir string, progress ProgressFunc, dtype string) (string, error)

ConvertPython uses the official llama.cpp convert_hf_to_gguf.py to convert a HuggingFace model directory to GGUF format. Returns the path to the generated GGUF file. Requires python3 with torch, safetensors, and transformers.

func FindGGUFForDType

func FindGGUFForDType(modelDir, dtype string) (string, bool, error)

FindGGUFForDType returns an existing GGUF path that matches the requested dtype. When dtype is empty or auto, it returns the highest precision GGUF chosen by model.FindModelFile.

func FindMMProjForDType

func FindMMProjForDType(modelDir, dtype string) (string, bool, error)

FindMMProjForDType returns an existing mmproj GGUF path that matches the requested dtype. When dtype is empty or auto, it returns the highest precision mmproj GGUF if present.

func HasConvertibleHFWeights

func HasConvertibleHFWeights(modelDir string) bool

func HasGGUF

func HasGGUF(modelDir string) (string, bool)

HasGGUF checks if a GGUF file already exists in the model directory.

func HasPyTorchWeights

func HasPyTorchWeights(modelDir string) bool

HasPyTorchWeights reports whether modelDir contains legacy PyTorch .bin weights that llama.cpp's HuggingFace converter can read.

func HasSafeTensors

func HasSafeTensors(modelDir string) bool

HasSafeTensors reports whether modelDir contains SafeTensors files.

func IsSupportedHFArchitecture

func IsSupportedHFArchitecture(hfArch string) bool

IsSupportedHFArchitecture reports whether csghub-lite can convert the HuggingFace architecture to GGUF via the bundled llama.cpp converter.

func NeedsConversion

func NeedsConversion(modelDir string) bool

NeedsConversion checks if the model directory contains HuggingFace weights but no GGUF files.

func NeedsConversionForDType

func NeedsConversionForDType(modelDir, dtype string) (bool, error)

NeedsConversionForDType reports whether SafeTensors conversion is needed for the requested output dtype. When dtype is unset, it preserves the legacy behavior of accepting any existing GGUF.

func NormalizeDType

func NormalizeDType(value string) (string, error)

NormalizeDType returns a lower-case converter dtype or "" when unset.

func NormalizeRuntimeDType added in v0.9.6

func NormalizeRuntimeDType(value string) (string, error)

NormalizeRuntimeDType returns a lower-case converter dtype or GGUF quant label, or "" when unset.

func PythonConverterAvailable

func PythonConverterAvailable() bool

PythonConverterAvailable returns true if python3 and the required dependencies are available for running the official converter.

func ResolveDType

func ResolveDType(value string) (string, error)

ResolveDType returns the effective converter dtype, falling back to the project default when the flag is unset.

func SupportedHFArchitecture

func SupportedHFArchitecture(hfArch string) (string, bool)

SupportedHFArchitecture maps a HuggingFace architecture name to the llama.cpp GGUF runtime architecture it converts into.

Types

type ArchConverter

type ArchConverter interface {
	Arch() string
	WriteKV(w *ggufWriter, cfg *modelConfig)
	ConvertTensors(w *ggufWriter, sources []tensorSource, cfg *modelConfig, progress ProgressFunc) error
}

ArchConverter handles architecture-specific GGUF conversion logic.

type GGMLType

type GGMLType uint32

GGML tensor data types.

const (
	GGMLTypeF32  GGMLType = 0
	GGMLTypeF16  GGMLType = 1
	GGMLTypeI8   GGMLType = 24
	GGMLTypeI16  GGMLType = 25
	GGMLTypeI32  GGMLType = 26
	GGMLTypeI64  GGMLType = 27
	GGMLTypeF64  GGMLType = 28
	GGMLTypeBF16 GGMLType = 30
)

func (GGMLType) ElementSize

func (t GGMLType) ElementSize() uint64

Bytes per element for each GGML type.

type ProgressFunc

type ProgressFunc func(step string, current, total int)

ProgressFunc reports conversion progress.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL