model

package
v0.32.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InferAffineQuantParamsFromShapes

func InferAffineQuantParamsFromShapes(weight, scales *mlx.Array, hintBits int) (groupSize, bits int, ok bool)

InferAffineQuantParamsFromShapes infers (groupSize,bits) for affine quantized tensors from packed weight and scale shapes.

func MakeEmbeddingLayer added in v0.18.2

func MakeEmbeddingLayer(
	tensors map[string]*mlx.Array,
	path string,
	defaultGroupSize, defaultBits int,
	defaultMode string,
	tensorQuant map[string]*TensorQuantInfo,
) nn.EmbeddingLayer

MakeEmbeddingLayer constructs an embedding layer from a tensor map.

For quantized tensors (path.weight + path.weight_scale), it returns a QuantizedEmbedding using the same quant metadata path that linear layers use. For non-quantized tensors, it returns a standard dense embedding.

func MakeLinearLayer

func MakeLinearLayer(
	tensors map[string]*mlx.Array,
	path string,
	defaultGroupSize, defaultBits int,
	defaultMode string,
	tensorQuant map[string]*TensorQuantInfo,
) nn.LinearLayer

MakeLinearLayer constructs a linear layer from a tensor map.

For quantized tensors (path.weight + path.weight_scale), it resolves per-tensor quant params via TensorQuant metadata (with shape-based affine fallback). For non-quantized tensors, it returns a standard nn.Linear.

func QuantizationParams

func QuantizationParams(quantization string) (groupSize, bits int, mode string)

QuantizationParams returns default groupSize, bits, and mode for a quantization type. The values live in the shared x/quant package so the importer, the runtime loader, and `ollama show` agree on them.

func ResolveLinearQuantParams

func ResolveLinearQuantParams(
	defaultGroupSize, defaultBits int,
	defaultMode string,
	tensorQuant map[string]*TensorQuantInfo,
	tensorName string,
	weight, scales *mlx.Array,
) (groupSize, bits int, mode string)

ResolveLinearQuantParams resolves quantization params for a quantized linear tensor, preferring per-tensor metadata and falling back to shape-based inference for affine packed tensors.

func TensorQuantParams

func TensorQuantParams(
	defaultGroupSize, defaultBits int,
	defaultMode string,
	tensorQuant map[string]*TensorQuantInfo,
	tensorName string,
) (groupSize, bits int, mode string, fromTensor bool)

TensorQuantParams resolves quant params for a tensor using per-tensor metadata when available, otherwise falling back to the provided model defaults.

Types

type LinearFactory

type LinearFactory struct {
	// contains filtered or unexported fields
}

LinearFactory builds linear layers using shared tensor maps and quant defaults.

func NewLinearFactory

func NewLinearFactory(
	tensors map[string]*mlx.Array,
	defaultGroupSize, defaultBits int,
	defaultMode string,
	tensorQuant map[string]*TensorQuantInfo,
) LinearFactory

NewLinearFactory creates a reusable constructor for model linear layers.

func (LinearFactory) Make

func (f LinearFactory) Make(path string) nn.LinearLayer

Make constructs a linear layer at path.

type Root

type Root struct {
	Manifest *manifest.ModelManifest
	Draft    *modeltypes.Draft
	// contains filtered or unexported fields
}

Root wraps a ModelManifest with pre-scanned quantization metadata.

func Open

func Open(modelName string) (*Root, error)

Open loads a manifest for the given model name and scans tensor blobs for quantization metadata.

func (*Root) AllTensorQuant

func (r *Root) AllTensorQuant() map[string]*TensorQuantInfo

AllTensorQuant returns a copy of the per-tensor quantization metadata.

func (*Root) Close

func (r *Root) Close()

Close is a no-op for now (future: release resources).

func (*Root) GroupSize

func (r *Root) GroupSize() int

GroupSize returns the quantization group size detected from the first tensor blob metadata.

func (*Root) QuantType

func (r *Root) QuantType() string

QuantType returns the quantization type detected from the first tensor blob metadata.

func (*Root) TensorQuant

func (r *Root) TensorQuant(name string) *TensorQuantInfo

TensorQuant returns per-tensor quantization metadata if available.

type TensorQuantInfo

type TensorQuantInfo struct {
	QuantType string
	GroupSize int
}

TensorQuantInfo describes per-tensor quantization metadata.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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