pub struct ResourceBudget {
pub max_ram_bytes: Option<usize>,
pub max_resident_experts: Option<usize>,
}Expand description
How much a model may hold resident. None fields mean “unbounded / derive”.
Fields§
§max_ram_bytes: Option<usize>Max resident weight RAM (bytes). None → the physical-RAM-derived soft
budget (soft_memory_budget_bytes).
max_resident_experts: Option<usize>Max MoE experts resident PER LAYER. None → derive from max_ram_bytes
(or all experts if RAM is unbounded).
Implementations§
Source§impl ResourceBudget
impl ResourceBudget
Sourcepub fn from_env() -> Self
pub fn from_env() -> Self
Read from the environment. RLX_MAX_RAM_BYTES and RLX_MAX_RESIDENT_EXPERTS
override; absent fields fall back to derivation at query time.
Sourcepub fn effective_ram_bytes(&self) -> Option<usize>
pub fn effective_ram_bytes(&self) -> Option<usize>
The effective RAM ceiling: explicit max_ram_bytes, else the soft
physical-RAM budget (None only when RAM is unknown and unset).
Sourcepub fn resident_experts(
&self,
num_experts: usize,
bytes_per_expert: usize,
backbone_bytes: usize,
) -> usize
pub fn resident_experts( &self, num_experts: usize, bytes_per_expert: usize, backbone_bytes: usize, ) -> usize
How many experts to keep resident PER LAYER: honor an explicit
max_resident_experts, else derive from the RAM ceiling by reserving
backbone_bytes (attention/norms/embed) and dividing the remainder by
bytes_per_expert. Always in 1..=num_experts.
Sourcepub fn expert_pool_config(
&self,
num_experts: usize,
bytes_per_expert: usize,
backbone_bytes: usize,
refresh: ExpertRefreshPolicy,
) -> ExpertPoolConfig
pub fn expert_pool_config( &self, num_experts: usize, bytes_per_expert: usize, backbone_bytes: usize, refresh: ExpertRefreshPolicy, ) -> ExpertPoolConfig
Build an ExpertPoolConfig honoring this budget (offload kicks in when the
resident count is below num_experts).
Sourcepub fn needs_offload(&self, model_bytes: usize, num_experts: usize) -> bool
pub fn needs_offload(&self, model_bytes: usize, num_experts: usize) -> bool
Whether weight offload/streaming should engage: the model doesn’t fit the RAM ceiling, or an explicit expert cap is below the expert count.
Trait Implementations§
Source§impl Clone for ResourceBudget
impl Clone for ResourceBudget
Source§fn clone(&self) -> ResourceBudget
fn clone(&self) -> ResourceBudget
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ResourceBudget
Source§impl Debug for ResourceBudget
impl Debug for ResourceBudget
Source§impl Default for ResourceBudget
impl Default for ResourceBudget
Source§fn default() -> ResourceBudget
fn default() -> ResourceBudget
impl Eq for ResourceBudget
Source§impl PartialEq for ResourceBudget
impl PartialEq for ResourceBudget
impl StructuralPartialEq for ResourceBudget
Auto Trait Implementations§
impl Freeze for ResourceBudget
impl RefUnwindSafe for ResourceBudget
impl Send for ResourceBudget
impl Sync for ResourceBudget
impl Unpin for ResourceBudget
impl UnsafeUnpin for ResourceBudget
impl UnwindSafe for ResourceBudget
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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