hostneed

package
v0.209.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 14 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 hostneed decides how much host RAM a GPU lease DECLARES (gpulease.Options.HostRAMGiB), the number the grant admits against the available memory (and, taken as the commit unless the caller states one, against physical RAM less the headroom; a commit the caller states is held to the commit limit): gpuprobe.HostRAMAdmitsLoad.

THE PRINCIPLE (AGENTS.md): the cards do the inference; RAM is overflow only. A render whose weights all sit on the card needs no host RAM worth declaring. One whose weights do not fit the card streams them from RAM: ComfyUI's dynamic VRAM stages the whole file in host memory ("Model Krea2 prepared for dynamic VRAM loading. 24449MB Staged" in the log of the incident's lane), next to the text encoder ("8463MB Staged"), so what the host pays is the FULL size of the files that do not fit, not the overflow. The incident lanes were exactly that: a 24.5 GiB bf16 UNet and an 8.3 GiB text encoder on a 16 GiB card, 32.7 GiB each, two at once.

WHERE THE NUMBER COMES FROM, in order:

  1. `gpu reserve --ram <GiB>`, the operator's word (0 is allowed: "needs no host RAM").
  2. A recognised render helper call (render/comfy-generate.mjs, comfy-render, comfy-edit, comfy-inpaint, comfy-video): the sizes of the UNet/checkpoint and text-encoder files the family loads, resolved through the configured ComfyUI model paths (mediacap.ModelRoots), and counted in full when together they do not fit the card (largest card of the lease, less the runner's --reserve-vram); 0 when they do. A file whose size cannot be read takes the documented per-family size in familySizes; a family with neither is unknown, and the call takes the class default. A helper run with `--graph <file>` posts the caller's own workflow and is sized by the weight files that graph's own loaders name (graph.go ForGraphFile): their sizes summed, by the same fit rule, when the graph can be read and every file it names resolves; any other graph takes the class default below. A graph that names NO weight file is the ComfyUI process floor (ProcessFloor: 3 GiB touched, 4 GiB of commit stated, measured), not the class default. render/comfy-run-graph.mjs is read the same way: its `--graph FILE`, or its `--template NAME --manifest FILE` (manifest.go).
  3. The media class default: the largest of the ComfyUI render families THIS BOX has bound (an sd.cpp binding counts nothing here, the pipeline's sd.cpp lanes add the weights they park themselves, ForSdcpp; its own imagegen_*, gen_edit_*, videogen_* bindings), so a 32 GiB node is not held to the numbers of a 128 GiB one; 0 when nothing is bound. It is never clamped to fit the box: a default that cannot be admitted here is refused with the reason and the way out (--ram), because quietly lowering it would defeat the guard.
  4. Text and seat leases: 0.

The pipeline's media admission (internal/pipeline) asks the same estimate per route from the binding it is about to render with.

Index

Constants

View Source
const DefaultSeatHostGiB = 21.0

DefaultSeatHostGiB is the host RAM an agent seat is assumed to hold when the node's config does not say (agent_seat_host_ram_gib). An unknown seat is not "fits": 0 would let a warm-back load a seat the host may not have room for, which is how a seat's host footprint went uncounted on 2026-09-10. The figure is CHOSEN, not measured on any node and NOT the largest on record: it is a vLLM pair seat's ~13 GiB of process plus 8 GiB of staged KV cache (from the project notes of 2026-09-10, not re-measured here), against ~12 GiB resident for a 35B-class MoE seat with spilled experts. The 2026-09-10 incident itself recorded a LARGER figure, 44 GB of host RAM for a seat; the note that carries the 44 GB attributes it to LMCache staging plus page cache, and whether the page-cache part is memory the OS can drop is not verified here, so which of the two a warm-back should be held to is not settled. What is: with the key unset the warm-back is admitted against 21 GiB, below the incident's figure, so a node that runs a seat must state its own measured footprint before it relies on that check. A seat smaller than the default costs a warm-back that waits for room it did not need; a larger one that is not configured is the gap.

View Source
const OffloadToCPUFlag = "--offload-to-cpu"

OffloadToCPUFlag is the sd.cpp flag that parks the weights in host RAM and stages them to the device as they are needed (sanctioned spill: all compute stays on the device, config.sanctionedSpillFlags).

View Source
const PlacementMulticard = "multicard"

PlacementMulticard is the value of --placement (and of imagegen_placement / gen_edit_placement) that asks for the card-only placement.

Variables

This section is empty.

Functions

func LargestCardGiB

func LargestCardGiB(cards []gpuprobe.Card, ids []string) float64

LargestCardGiB is the total VRAM of the largest card among ids (lease ids; none = every card).

func LeasedCardsGiB

func LeasedCardsGiB(cards []gpuprobe.Card, ids []string) []float64

LeasedCardsGiB is the total VRAM of each card among ids (lease ids; none = every card), in the table's order.

func RenderHelpers

func RenderHelpers() []string

RenderHelpers is the file name of every render helper a lease's wrapped command is recognised by (ParseRenderCall), sorted. A message that names them (the line `gpu reserve` prints when it declares the media class default, F71) reads this list, so it cannot drift from the rule that recognises them.

func UseStat

func UseStat(fn func(path string) (size int64, ok bool)) (restore func())

UseStat makes every estimate that leaves Facts.Stat nil size files through fn until restore is called. It exists so a test of the media admission can say a bf16 transformer is 39 GiB without writing one.

Types

type CardOnly

type CardOnly struct {
	// LTX is true for the LTX-2.5 graph: one DiT (not two experts) split over the pair with the compute card first, sized by ltx* above.
	LTX bool
	// ResidentGiB is --wan-resident-gb: the share of each expert (of the DiT, for LTX) kept on the compute card; 0 is the family's default.
	ResidentGiB float64
	// SageAttention is true when COMFY_EXTRA_ARGS carries --use-sage-attention (or an argparse prefix of it): the runner then sizes the compute card's
	// activations at wanActivationsSageGiB. Read from the process environment only (Facts.Env): an `env COMFY_EXTRA_ARGS=...` prefix inside the wrapped
	// command is not seen here, while the runner sees it.
	SageAttention bool
}

CardOnly is the card-only placement a call asked for (--wan-placement multicard on the Wan 2.2 graph, or on the LTX-2.5 one), and what the call says about it.

type Facts

type Facts struct {
	// Cfg is the machine's config: ComfyDir (the model roots) and the video/animate bindings.
	Cfg config.Config
	// VRAMGiB is the total VRAM of the card the job runs on: the LARGEST single card of the leased
	// set (a job runs on one card, so the smaller cards of a multi-card lease do not constrain it).
	// 0 = unknown, and then nothing is assumed to fit.
	VRAMGiB float64
	// ReserveVRAMGiB is VRAM the runner holds back for the display (its --reserve-vram); 0 = the
	// cfg's imagegen_reserve_vram, else the runners' own 1.0.
	ReserveVRAMGiB float64
	// CardsGiB is the total VRAM of EACH card of the leased set (none = unknown). Only the card-only placements read it.
	CardsGiB []float64
	// Placement is the placement the call asked for: "" is the single placement (today's), PlacementMulticard the card-only recipe of the image and edit
	// routes (--placement multicard, imagegen_placement / gen_edit_placement). Only those two routes read it; ClassDefault never does.
	Placement string
	// ResidentGiB overrides a split recipe's share of the DiT kept on the compute card (--resident-gb); nil = the recipe's own.
	ResidentGiB *float64
	// Megapixels is the edit canvas the call pins (--megapixels, gen_edit_megapixels); 0 = the runner's own (the source's size, capped at 2.0 MP).
	Megapixels float64
	// Stat reports a file's size; nil = os.Stat. A table in tests, because a 24 GiB fixture is not an option.
	Stat func(path string) (size int64, ok bool)
	// Env reads an environment variable (COMFY_CKPT and friends); nil = none set.
	Env func(string) string
}

Facts are the readings an estimate needs besides the binding.

type Need

type Need struct {
	GiB    float64
	Source Source
	// Detail is one sentence for the line the CLI prints and the docs quote.
	Detail string
	// Unsized names, comma-separated by their binding keys, the weight files an sd.cpp estimate (ForSdcpp) could not size. Set
	// together with a figure that is then a LOWER BOUND, or alone when nothing could be sized; the caller says so once.
	// A string, not a slice, so a Need stays comparable.
	Unsized string
	// CardOnly marks the 0 a measured card-only recipe earns (the image and edit placement, estimatePlaced). A 0 is otherwise the silent default of a
	// declaration; this one is said wherever a figure is, with its Detail, because nothing can correct it afterwards (calibratedRAM leaves 0 alone).
	CardOnly bool
	// CommitGiB is the commit the need is charged, beside the working set GiB, and CommitStated says it is a figure the estimate stands behind
	// (the ComfyUI process floor, ProcessFloor): it is then admitted against the OS commit limit like a stated --ram-commit, not against
	// physical RAM as the working set standing in for it is. Not stated, CommitGiB is 0 and the commit is the working set (gpu_hostram.go).
	CommitGiB    float64
	CommitStated bool
}

Need is a declared host-RAM need and where it came from.

func ClassDefault

func ClassDefault(f Facts) Need

ClassDefault is the media class default: the largest estimate over the render families this box binds (config), so it describes what THIS box can be asked to run. A route whose script is unset, or whose files cannot be sized, is not counted; a box that binds nothing declares 0.

A binding on the "sdcpp" engine is left out ON PURPOSE: its weights are not in a ComfyUI model tree, and "does it fit the card" means nothing on a unified-memory iGPU. That is the image, animate and music routes by their engine keys and a video family by its binding's engine (the box's default family included); the edit route has no engine key and is always ComfyUI. So the class default of an sd.cpp-only node (and of the audio.cpp lanes, which take it too) is the largest COMFYUI family the box binds, an upper bound that is not its own size, and on a box that binds no ComfyUI family it is 0 (TestAnSdcppOnlyBoxDeclaresNothing pins that the CLASS DEFAULT is nothing there). The sd.cpp lanes do not stop at it (F60): they declare the larger of it and the weights they park themselves (ForSdcpp, wired in internal/pipeline sdcppDeclared), so on that box the `--offload-to-cpu` spill is inside the guard, as an estimate.

func ForGraph

func ForGraph(graph []byte, f Facts) (Need, bool)

ForGraph sizes a ComfyUI API-format graph by the weight files its own loaders name: the SUM of their sizes, each file once. Every file counts, a VAE and a LoRA with the checkpoint, because the graph names them. The sum goes through the family estimate's own rule (fitToCard): in full when together the files do not fit the card (or the card is not known), and 0 when they fit, because a set that fits streams nothing from RAM. The figure is an estimate from the files' sizes, not a measurement.

A graph that names no weight file is the ProcessFloor, ok true. ok is false, and the caller keeps the media class default, when graph is not a JSON object (or holds no node), or names a weight file that does not resolve under the box's model roots (or is empty), or when the document holds a weight-like name the sizing did not cover (unsizedWeight: another extension, a nested widget object, a list). Facts.Stat sizes the files when set, as for every estimate.

LIMIT: a weight is recognised by its extension (the scan's six and otherWeightExts) and a graph can name one by another, or load a file whose name is built at run time; such a graph is sized by the files that were seen, an estimate that can be low.

func ForGraphFile

func ForGraphFile(path string, f Facts) (Need, bool)

ForGraphFile is ForGraph for the graph at path (`--graph <file>`). A path that is empty, not a regular file, larger than maxGraphBytes or unreadable is not sized: ok is false, as for a graph ForGraph cannot size. Only a regular file is opened, so a `--graph` that names a pipe or a device cannot block the verb that resolved it.

func ForManifestFile

func ForManifestFile(path string, f Facts) (Need, bool)

ForManifestFile is ForManifestModels for the runtime manifest at path (`--manifest <file>`, the run's `manifest_path`): a JSON object with a `models` list whose entries carry a `path`. A path that is empty, not a regular file, larger than maxGraphBytes or unreadable, a document that is not that shape, or an entry with no path is not sized: ok is false, as for a manifest ForManifestModels cannot size.

func ForManifestModels

func ForManifestModels(paths []string, f Facts) (Need, bool)

ForManifestModels sizes a template by the model files its runtime manifest names, given as the manifest writes them (`models/<class>/<name>`, the name possibly nested): the SUM of their sizes, each file once, fitted to the card by the family estimate's rule (in full when together they do not fit, or the card is not known; 0 when they fit). The figure is an estimate from the files' sizes, not a measurement. ok is false, and the caller keeps the media class default, as for ForGraph.

func ForRoute

func ForRoute(route Route, cfg config.Config, f Facts) (Need, bool)

ForRoute is the estimate for one route of the pipeline, from the EFFECTIVE binding of the call (the config after any named-family overlay). ok=false means the binding gave nothing to size.

func ForSdcpp

func ForSdcpp(family string, files []SdcppFile, extraArgs []string, f Facts) (Need, bool)

ForSdcpp is the host RAM an sd.cpp call parks (F60): with --offload-to-cpu among its extra args, every distinct weight file its binding names, in full (the diffusion model, a high-noise expert, the text encoders, the VAE); without it the weights go straight to the device and nothing is parked. A file whose size cannot be read (missing, or empty) does not take the whole estimate with it: the files that can be sized are summed, Need.Unsized names the rest and the detail says the figure is a lower bound, because the class default is 0 on an sd.cpp-only box and dropping the estimate over one mistyped path put the whole spill back outside the brake in silence (0.180 hardening). ok is false when the binding names no file or none of them can be sized: there is no number to declare, and the caller keeps the class default it had (Unsized still names the files, so the caller can say why).

It is an ESTIMATE, from the files' sizes, and says so: sd.cpp may hold a little more (compute buffers) or stage lazily, and nothing here has been measured on a node. The footprint store raises the declaration to what the lane's runs were measured to hold once three exist (internal/pipeline calibratedRAM), as it does for a ComfyUI family.

func ForVideo

func ForVideo(cfg config.Config, renderFamily string, f Facts) (Need, bool)

ForVideo is the video route's estimate for the family that will render: renderFamily is the config-namespace family the pipeline resolved for the request ("" = this box's default family), and the files are the binding that family renders with (config.ResolveVideoFamilyBinding).

func ForVideoCardOnly

func ForVideoCardOnly(cfg config.Config, renderFamily string, over VideoOverrides, residentGiB float64, extraArgs string, f Facts) (Need, bool)

ForVideoCardOnly is ForVideoWith for a Wan 2.2 or LTX-2.5 call that asked for the card-only placement (videogen_placement: multicard, which passes --wan-placement multicard): the same stage rule command.go applies to the runner's own flags (estimateWith). residentGiB is --wan-resident-gb (0 = the runner's default share for the family: 3 for Wan, 9 for LTX), extraArgs the COMFY_EXTRA_ARGS the runner will see (sage attention, Wan only). Any other family is sized as ForVideoWith does.

func ForVideoWith

func ForVideoWith(cfg config.Config, renderFamily string, over VideoOverrides, f Facts) (Need, bool)

ForVideoWith is ForVideo for a call that names weight files of its own: the family's binding with those files put over it.

func ProcessFloor

func ProcessFloor(what string) Need

ProcessFloor is the need of a graph that names no weight file: the ComfyUI process alone (Python, torch and the node packs), measured and not derived from any file. The commit is stated, so it is judged against the commit limit and not against the physical RAM a working set is. what names the document ("the graph", "the template's manifest") in the detail.

func Resolve

func Resolve(r Request, f Facts) Need

Resolve is the order in the package comment: explicit, a recognised render call, the media class default, nothing.

func SeatNeed

func SeatNeed(cfg config.Config) Need

SeatNeed is the host RAM the agent seat needs once loaded: the node's own figure when its config states one (agent_seat_host_ram_gib), else DefaultSeatHostGiB. It is never 0: a seat whose footprint is unknown is held to the chosen default (fail closed, though below the 44 GB the 2026-09-10 incident recorded), because a load the guard cannot size is the one it must not wave through.

func (Need) String

func (n Need) String() string

type RenderCall

type RenderCall struct {
	Script string // the helper's lower-cased file name
	Route  Route
	Flags  map[string]string
}

RenderCall is a recognised render-helper invocation: `node render/comfy-generate.mjs ... --family krea2 --ckpt <file> ...`. Only the flags that select weights are read.

func ParseRenderCall

func ParseRenderCall(args []string) (RenderCall, bool)

ParseRenderCall finds a known helper in a wrapped command and reads its flags. The helper may sit behind an interpreter and its path in either separator style (`node D:\x\render\comfy-edit.mjs`).

func (RenderCall) Estimate

func (c RenderCall) Estimate(f Facts) (Need, bool)

Estimate sizes the call's weights. A helper selects its weights by flag (or the environment the harness gave it), not by this machine's config, so the binding is built from the flags; the machine's config supplies only where the model files are (ComfyDir) and, for video, the family bindings the runner receives from the harness.

func (RenderCall) RunsOwnGraph

func (c RenderCall) RunsOwnGraph() bool

RunsOwnGraph says the call POSTS THE CALLER'S OWN WORKFLOW (`--graph <file>`): what such a call loads is whatever the graph names, so it is sized by the weight files the graph's own loaders name when the lease can read the graph and size every one (ForGraphFile), else by the media class default, and never as the helper's default family (Estimate). The hint `gpu reserve` prints when it declares that default reads this same rule, so the two cannot disagree about which calls are graph calls.

type Request

type Request struct {
	// Explicit is `gpu reserve --ram` when it was given (a pointer, because 0 is a value).
	Explicit *float64
	Class    gpulease.Class
	// Args is the wrapped command (nil for a detached reservation).
	Args []string
}

Request is what the CLI knows about a reservation when it resolves the need.

type Route

type Route string

Route is one of the render routes whose model files are known.

const (
	RouteImage   Route = "image"
	RouteEdit    Route = "edit"
	RouteInpaint Route = "inpaint"
	RouteVideo   Route = "video"
	RouteAnimate Route = "animate"
	RouteMusic   Route = "music"
	// RouteRunGraph is render/comfy-run-graph.mjs, which runs a graph or a template and is sized by what that document names (ForGraphFile, ForManifestFile).
	RouteRunGraph Route = "run-graph"
)

type SdcppFile

type SdcppFile struct{ Label, Path string }

SdcppFile is one weight file an sd.cpp call loads: where the binding names it (Label, a config key) and the full path.

type Source

type Source string

Source says where a declared need came from.

const (
	// SourceExplicit: the operator's `--ram`.
	SourceExplicit Source = "explicit"
	// SourceEstimate: the sizes of the model files of a recognised render call.
	SourceEstimate Source = "estimate"
	// SourceFamilyDefault: a recognised render call whose file sizes could not be read, so the
	// documented per-family sizes stand in for at least one of them.
	SourceFamilyDefault Source = "family default"
	// SourceGraphLoaders: the weight files a ComfyUI graph's own loaders name, summed and fitted to the card as a family's are (ForGraph): a graph the lease
	// could read, whose every named file it could size. A template run's model files, as its runtime manifest names them, are the same
	// kind of figure (ForManifestModels).
	SourceGraphLoaders Source = "graph loaders"
	// SourceClassDefault: the media class default, the largest family this box binds.
	SourceClassDefault Source = "class default"
	// SourceNone: a text or seat lease, or a box that binds no render family: nothing declared.
	SourceNone Source = "none"
	// SourceMeasured: the estimate raised to what renders of this binding were measured to hold on the host
	// (the footprint store's host peaks, once enough runs exist).
	SourceMeasured Source = "measured"
	// SourceSeat: the agent seat's footprint, as the node's config states it (agent_seat_host_ram_gib).
	SourceSeat Source = "seat"
	// SourceSeatDefault: an agent seat whose footprint nobody stated: the fail-closed default.
	SourceSeatDefault Source = "seat default"
)

type VideoOverrides

type VideoOverrides struct {
	Transformer, UnetHigh, UnetLow, TextEncoder string
}

VideoOverrides are the weight files ONE video call names over its family's binding. The pipeline takes a per-request `transformer` (a caller can pick the bf16 LTX transformer for one hero render without a config edit, and the runner loads exactly that file), so the estimate has to size the file the render loads and not the one the config binds: a bf16 LTX-2.5 transformer is 39 GiB where the int8 default is 20, 19 GiB of under-declaration, more than twice the headroom, which let a second lane in while the first was still loading (the incident again; review of 2026-10-10). A field left empty keeps the binding's.

Jump to

Keyboard shortcuts

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