Skip to main content

ModelCost

Struct ModelCost 

Source
pub struct ModelCost {
    pub n_layers: usize,
    pub per_layer_bytes: u64,
    pub per_layer_expert_bytes: u64,
    pub per_layer_expert_active_bytes: u64,
    pub embed_bytes: u64,
    pub head_bytes: u64,
    pub per_layer_flops: f64,
    pub kv: KvProfile,
    pub params: u64,
    pub hidden_size: usize,
}
Expand description

Resident-memory + compute cost model for a layer-stack model.

Bytes are the ACTUAL per-node footprint (packed weights as stored), so the planner’s budgets mean something. Build it with ModelCost::from_tensor_index rather than by hand.

Fields§

§n_layers: usize§per_layer_bytes: u64

Average resident bytes per layer, excluding routed experts.

§per_layer_expert_bytes: u64

Average routed-expert bytes per layer. These may live on disk.

§per_layer_expert_active_bytes: u64

Expert bytes actually read per token — per_layer_expert_bytes × expert_active_fraction. Drives the paging-bandwidth estimate.

§embed_bytes: u64

Extra bytes on the FIRST stage (token embedding).

§head_bytes: u64

Extra bytes on the LAST stage (final norm + LM head).

§per_layer_flops: f64

Relative FLOPs per layer (throughput policy; 1.0 = uniform).

§kv: KvProfile

What the attention cache costs, and whether that is known.

ModelCost::from_tensor_index infers it from tensor shapes where it can (see CostOptions::kv); otherwise it is KvSource::Unknown and the planner refuses to guess.

§params: u64

Total parameters, used to re-scale the model between precisions.

§hidden_size: usize

Model width, read from a rank-1 norm inside a block. 0 when unknown.

Worth carrying rather than re-deriving: the worst-case KV bound needs it, and inferring it from byte counts (sqrt(per_layer_bytes / 12)) is badly wrong for a quantized MoE, whose per-layer bytes are dominated by expert banks at ~2 bits per weight.

Implementations§

Source§

impl ModelCost

Source

pub fn from_gguf(paths: &[PathBuf], opts: &CostOptions) -> Result<Self>

Derive the cost model straight from GGUF shards.

Source§

impl ModelCost

Source

pub fn at_bits(&self, target_bits: f64) -> Option<Self>

The same model at a different weight precision.

Scales every byte figure by target_bits / current_bits, where the current width is inferred from the checkpoint (bytes × 8 / params). Approximate by construction — it assumes the whole model re-quantizes uniformly — but it is the right shape for answering “would this fit one step down?”, which is the question a precision ladder asks.

Returns None when the parameter count is unknown (nothing to scale by).

Source

pub fn kv_bytes(&self, layers: u64, context: usize) -> u64

KV bytes one node holds for layers at context tokens.

Source

pub fn total_bytes(&self) -> u64

Total bytes across the whole model, experts included.

Source

pub fn total_resident_bytes(&self) -> u64

Bytes that must be RESIDENT for the whole model (experts excluded).

Source

pub fn is_expert_dominated(&self) -> bool

True when routed experts dominate — the regime where disk and IO decide placement rather than RAM.

Source

pub fn from_tensor_index( entries: &[TensorEntry], opts: &CostOptions, ) -> Result<Self>

Derive the cost model from a checkpoint’s tensor index.

Layer count is max(block index) + 1; per-layer figures are averaged over the blocks actually present, so a model with a trailing MTP block or an uneven layer stack still gets a usable mean.

Source

pub fn summary(&self) -> String

One-line summary for logs.

Trait Implementations§

Source§

impl Clone for ModelCost

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ModelCost

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ModelCost

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.