memory

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package memory is the daemon's model-memory accounting: the budget loaded models may use, the footprint estimate for a model before it is loaded, and the measured physical footprint of a running runtime process.

Measurement is deliberately *not* RSS. llama.cpp mmaps GGUF weights, so RSS counts clean file-backed pages the kernel can drop at will and double counts the page cache; the numbers that matter are what macOS calls the physical footprint (proc_pid_rusage ri_phys_footprint, the figure Activity Monitor's "Memory" column and `footprint` show) and what Linux calls the proportional set size (/proc/<pid>/smaps_rollup Pss).

Index

Constants

View Source
const (

	// DefaultContext is the context length assumed when neither the catalog
	// nor the operator sets one. llama-server's own default is 4096; the
	// larger figure errs on the side of not overfilling the machine.
	DefaultContext = 8192
)

Estimate parameters.

View Source
const MiB = 1024 * 1024

MiB is one mebibyte in bytes.

Variables

View Source
var ErrUnsupported = errors.New("memory: footprint measurement not supported on this platform")

ErrUnsupported means footprint measurement is not implemented on this platform; callers keep the pre-load estimate.

Functions

func AutoBudgetMB

func AutoBudgetMB(hw *typesv1.CapabilityProfile, maxVRAMPercent int) int64

AutoBudgetMB derives the model-memory budget when budget.max_ram_mb is 0: half of physical RAM on unified-memory (and CPU-only) machines, and vram × max_vram_percent on discrete GPUs, where the weights live on the card and host RAM is not the constraint.

func BudgetMB

func BudgetMB(configured int64, hw *typesv1.CapabilityProfile, maxVRAMPercent int) int64

BudgetMB resolves the configured budget: configured > 0 wins, else auto.

func Discrete

func Discrete(hw *typesv1.CapabilityProfile) bool

Discrete reports whether the node has a discrete (non-unified) GPU, where weights live in VRAM that host-side footprint measurement cannot see.

func EstimateMB

func EstimateMB(fileBytes int64, minRAMMB int64, ctx, parallel int) int64

func ProcessFootprintMB

func ProcessFootprintMB(pid int) (int64, error)

ProcessFootprintMB measures the physical footprint of a process in MiB. Returns ErrUnsupported where no implementation exists; callers then keep their estimate.

func ResolveContext added in v0.4.1

func ResolveContext(override, model, maxCtx int) int

EstimateMB predicts the physical footprint of loading a model before it is loaded:

estimate = file_bytes × 1.15 + ctx × parallel × (file_bytes / 65536) + 256 MB

When the catalog states min_ram_mb the larger of the two wins: the catalog value is authoritative for the weights but was written for a specific context, so a much larger operator-configured context still raises the estimate. ctx <= 0 uses DefaultContext; parallel < 1 is 1. ResolveContext is the context window a runtime is launched with: the operator's explicit override if set, else the model's own length, then capped by maxCtx (0 = no cap). Both the llama.cpp adapter and the admission estimate go through it so they agree on the KV-cache size.

func Unified

func Unified(hw *typesv1.CapabilityProfile) bool

Unified reports whether the node's GPU shares system memory (Apple Silicon). On such machines the RAM budget is the whole story: there is no separate VRAM to fill.

Types

This section is empty.

Jump to

Keyboard shortcuts

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