safetensors

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: Apache-2.0, Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QuantizationUnknown = "unknown"
	QuantizationMixed   = "mixed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Header struct {
	Metadata map[string]interface{}
	Tensors  map[string]TensorInfo
}

Header represents the JSON header in a safetensors file

func ParseSafetensorsHeader

func ParseSafetensorsHeader(path string) (*Header, error)

ParseSafetensorsHeader reads only the header from a safetensors file without loading the entire file. This is memory-efficient for large model files (which can be many GB).

Safetensors format:

[8 bytes: header length (uint64, little-endian)]
[N bytes: JSON header]
[remaining: tensor data]

func (*Header) CalculateParameters

func (h *Header) CalculateParameters() int64

CalculateParameters sums up all tensor parameters

func (*Header) ExtractMetadata

func (h *Header) ExtractMetadata() map[string]string

ExtractMetadata converts header to string map (similar to GGUF)

func (*Header) GetQuantization

func (h *Header) GetQuantization() string

GetQuantization determines the quantization type from tensor dtypes

type Model

type Model struct {
	mdpartial.BaseModel
}

Model represents a Safetensors model and embeds BaseModel for common functionality

func NewModel

func NewModel(paths []string) (*Model, error)

NewModel creates a new safetensors model from one or more safetensors files. It delegates to the unified builder package for model creation.

type TensorInfo

type TensorInfo struct {
	Dtype       string
	Shape       []int64
	DataOffsets [2]int64
}

TensorInfo contains information about a tensor

Jump to

Keyboard shortcuts

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