engine: the memory tier, the CPU expert pool and the residency state read the memory settings of their binding (STRA-338)
The tail skip rank, the PCIe share controllers, the span cache, the refill, the swap wait, the tie order, the locked-only split, the expert pool path/fence/admission/prefetch-off file and the routing dump take the settings from ModelBinding::settings() or the MemorySettings handed to ResidencyState::new. ExpertTierConfig is read from the settings' captured environment (from_environment stays for the tools, under cfg(test)). The TAIL_SKIP_RANK arm cell stays.
This commit is contained in:
@@ -91,13 +91,15 @@ fn options_config(
|
||||
if let Some(prefix) = options.prefix_cache.as_ref() {
|
||||
config.prefix = Some(prefix_config(prefix, &settings.serve));
|
||||
}
|
||||
config.expert_tier = expert_tier_config()?;
|
||||
config.expert_tier = expert_tier_config(settings)?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
/// The VRAM expert tier (off unless LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS / _EXPERT_PROFILE select it).
|
||||
fn expert_tier_config() -> Result<crate::qwen_forward::original_serve_residency::ExpertTierConfig, BackendError> {
|
||||
crate::qwen_forward::original_serve_residency::ExpertTierConfig::from_environment().map_err(|_| {
|
||||
fn expert_tier_config(
|
||||
settings: &crate::settings::Settings,
|
||||
) -> Result<crate::qwen_forward::original_serve_residency::ExpertTierConfig, BackendError> {
|
||||
crate::qwen_forward::original_serve_residency::ExpertTierConfig::from_source(settings.env()).map_err(|_| {
|
||||
load_failure(LoadPhase::OriginalStack, invalid("invalid LELEKA_ORIGINAL_SERVE_EXPERT_* / PCIE / ADAPT setting"))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -209,7 +209,6 @@ mod pool_layer_trace;
|
||||
use pool_layer_trace::GroupTraceInfo;
|
||||
mod direct_tier;
|
||||
mod direct_tier_drop;
|
||||
use direct_tier_drop::admit_eager;
|
||||
use direct_tier_drop::native_cpu_error;
|
||||
use direct_tier_drop::selection;
|
||||
use direct_tier_drop::sink_result;
|
||||
|
||||
+1
-1
@@ -181,7 +181,7 @@ impl DirectTier {
|
||||
let mut open = GroupOpen {
|
||||
fetch_ms: 0.0,
|
||||
any_mapped: false,
|
||||
use_pass: self.prefetch.decide(prefetch_off_file_exists()),
|
||||
use_pass: self.prefetch.decide(prefetch_off_file_exists(binding.settings())),
|
||||
started: std::time::Instant::now(),
|
||||
};
|
||||
let open_span = super::super::original_serve_profile::span("cpu.open");
|
||||
|
||||
@@ -6,8 +6,7 @@ use super::{
|
||||
ComputeSample, CpuExpertPool, CpuMissWorkspace, CrosscheckCounts, DirectCpuPool, DirectTier, EXPERTS, Error,
|
||||
LayerLayout, ModelBinding, MoeExpertWeights, MoeMatrixRole, MoeRoutedSourceScope, Opened, OriginalGpuStream,
|
||||
OriginalServePool, OriginalVerifyCpuRows, OriginalVerifyCpuSink, PoolPath, ResidentExpertBankSpan, Result,
|
||||
RouterLookahead, TOP_K, admit_eager, admit_job, binding_error, native_cpu_error, open_job, runtime_error,
|
||||
same_spans,
|
||||
RouterLookahead, TOP_K, admit_job, binding_error, native_cpu_error, open_job, runtime_error, same_spans,
|
||||
};
|
||||
|
||||
impl DirectTier {
|
||||
@@ -274,8 +273,8 @@ impl DirectTier {
|
||||
let table = 48 * EXPERTS as usize;
|
||||
let held = none_table(table)?;
|
||||
let routes = none_table(table)?;
|
||||
let mut tier = Self::assemble(pool, held, routes)?;
|
||||
if admit_eager() {
|
||||
let mut tier = Self::assemble(pool, held, routes, &binding.settings().memory.pool)?;
|
||||
if binding.settings().memory.pool.admit_eager {
|
||||
let started = std::time::Instant::now();
|
||||
let n = tier.admit_all(binding)?;
|
||||
eprintln!(
|
||||
@@ -290,8 +289,8 @@ impl DirectTier {
|
||||
pool: DirectCpuPool,
|
||||
held: Vec<Option<[ResidentExpertBankSpan; 3]>>,
|
||||
routes: Vec<Option<MoeExpertWeights>>,
|
||||
pool_settings: &crate::settings::CpuPoolSettings,
|
||||
) -> Result<Self> {
|
||||
let pool_settings = &crate::settings::process().memory.pool;
|
||||
let group_fence = pool_settings.group_fence;
|
||||
if !group_fence {
|
||||
eprintln!("leleka-serve cpu expert pool: one source fence per job (LELEKA_CPU_POOL_FENCE=job)");
|
||||
@@ -318,7 +317,7 @@ impl DirectTier {
|
||||
}
|
||||
impl<'a> CpuExpertPool<'a> {
|
||||
pub(in crate::qwen_forward) fn new(binding: &'a ModelBinding, workers: i32) -> Result<Self> {
|
||||
Self::with_path(binding, workers, PoolPath::from_env())
|
||||
Self::with_path(binding, workers, PoolPath::from_settings(binding.settings()))
|
||||
}
|
||||
pub(in crate::qwen_forward) fn with_path(binding: &'a ModelBinding, workers: i32, path: PoolPath) -> Result<Self> {
|
||||
if binding.expert_count() != EXPERTS as u32 || binding.expert_used_count() != TOP_K as u32 {
|
||||
|
||||
@@ -19,11 +19,6 @@ impl Drop for DirectTier {
|
||||
}
|
||||
}
|
||||
|
||||
/// `LELEKA_CPU_ADMIT_EAGER=off` keeps admission at an expert's first use (A/B control); default: every expert at open.
|
||||
pub(super) fn admit_eager() -> bool {
|
||||
crate::settings::process().memory.pool.admit_eager
|
||||
}
|
||||
|
||||
pub(super) fn sink_result(written: leleka_cuda_driver::Result<()>, failure: Option<Error>) -> Result<()> {
|
||||
match (written, failure) {
|
||||
(Ok(()), None) => Ok(()),
|
||||
|
||||
+4
-4
@@ -9,8 +9,8 @@ use super::{
|
||||
|
||||
/// A bring-up file (`LELEKA_CPU_PREFETCH_OFF_FILE`, A/B inside one engine): while it exists the page-touch pass is
|
||||
/// skipped, whatever the policy says.
|
||||
pub(super) fn prefetch_off_file_exists() -> bool {
|
||||
let file = crate::settings::process().memory.pool.prefetch_off_file.as_ref();
|
||||
pub(super) fn prefetch_off_file_exists(settings: &crate::settings::Settings) -> bool {
|
||||
let file = settings.memory.pool.prefetch_off_file.as_ref();
|
||||
file.is_some_and(|f| std::path::Path::new(f).exists())
|
||||
}
|
||||
|
||||
@@ -88,8 +88,8 @@ pub(in crate::qwen_forward) fn scatter(out: &mut [f32], job: &ExpertJob, values:
|
||||
Ok(())
|
||||
}
|
||||
impl PoolPath {
|
||||
pub(in crate::qwen_forward) fn from_env() -> Self {
|
||||
match crate::settings::process().memory.pool.path.as_deref() {
|
||||
pub(in crate::qwen_forward) fn from_settings(settings: &crate::settings::Settings) -> Self {
|
||||
match settings.memory.pool.path.as_deref() {
|
||||
Some("legacy") => Self::Legacy,
|
||||
Some("crosscheck") => Self::Crosscheck,
|
||||
_ => Self::Direct,
|
||||
|
||||
@@ -289,7 +289,6 @@ pub(in crate::qwen_forward) use adapt_tuning::SwapCap;
|
||||
use adapt_tuning::adapt_decay;
|
||||
#[cfg(test)]
|
||||
use split_group_pcie::choose_swaps_reference;
|
||||
pub(in crate::qwen_forward) use split_group_pcie::pcie_locked_only;
|
||||
pub(in crate::qwen_forward) use split_group_pcie::split_group_pcie;
|
||||
pub(in crate::qwen_forward) use split_group_pcie::{PcieSplitPolicy, RoutedGroup};
|
||||
pub(in crate::qwen_forward) use split_group_pcie::{choose_swaps, choose_swaps_by};
|
||||
@@ -300,14 +299,12 @@ mod strata_pcie_auto;
|
||||
use strata_pcie_auto::StrataPcieAuto;
|
||||
mod pcie_auto_on_window_pool;
|
||||
mod pcie_share_controllers;
|
||||
mod source_spans;
|
||||
#[cfg(test)]
|
||||
mod strata_pcie_auto_tests;
|
||||
use pcie_share_controllers::span_cache_enabled;
|
||||
mod source_spans;
|
||||
pub(super) use source_spans::source_spans;
|
||||
mod open_tier;
|
||||
pub(in crate::qwen_forward) use open_tier::loan_slots;
|
||||
pub(in crate::qwen_forward) use open_tier::open_tier;
|
||||
pub(in crate::qwen_forward) use open_tier::refill_defer_enabled;
|
||||
pub(in crate::qwen_forward) use open_tier::refill_lent;
|
||||
pub(in crate::qwen_forward) use open_tier::settle_refill;
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::MappedExpertBank;
|
||||
use super::{
|
||||
Context, Error, ExpertTierConfig, LOAN_FLOOR, ModelBinding, MoeWeightCache, OriginalCacheOptions,
|
||||
OriginalExpertCache, OriginalRankedExperts, Rc, ResidentExpertBankSpan, Result, SpanCache, VANILLA_FREE_FLOOR_MIB,
|
||||
VERIFIER_ASSEMBLY_MIB, driver_error, original_cache_startup, span_cache_enabled,
|
||||
VERIFIER_ASSEMBLY_MIB, driver_error, original_cache_startup,
|
||||
};
|
||||
use leleka_cuda_driver::RefillBatchOptions;
|
||||
use leleka_memory::MemoryServices;
|
||||
@@ -212,7 +212,7 @@ pub(in crate::qwen_forward) fn refill_lent<'ctx>(
|
||||
defer_wait: bool,
|
||||
) -> Result<usize> {
|
||||
let bank = moe.original_expert_bank().ok_or(Error::IdentityMismatch)?;
|
||||
let refilled = if refill_batch_enabled() {
|
||||
let refilled = if binding.settings().memory.refill_batch {
|
||||
refill_lent_batched(binding, moe, cache, known, (&bank, defer_wait))?
|
||||
} else {
|
||||
refill_lent_per_copy(binding, moe, cache, known, (&bank, defer_wait))?
|
||||
@@ -233,7 +233,7 @@ fn refill_lent_per_copy<'ctx>(
|
||||
known: &mut SpanCache,
|
||||
(bank, defer_wait): (&Rc<leleka_cuda_driver::MappedExpertBank<'ctx>>, bool),
|
||||
) -> Result<usize> {
|
||||
let cached = span_cache_enabled();
|
||||
let cached = binding.settings().memory.span_cache;
|
||||
let mut refilled = 0usize;
|
||||
for slot in 0..cache.slots() {
|
||||
let Some((layer, expert)) = cache.needs_refill(slot).map_err(|e| driver_error(&e))? else { continue };
|
||||
@@ -255,7 +255,7 @@ fn refill_lent_batched<'ctx>(
|
||||
known: &mut SpanCache,
|
||||
(bank, defer_wait): (&Rc<leleka_cuda_driver::MappedExpertBank<'ctx>>, bool),
|
||||
) -> Result<usize> {
|
||||
let cached = span_cache_enabled();
|
||||
let cached = binding.settings().memory.span_cache;
|
||||
let mut fills = Vec::new();
|
||||
for slot in 0..cache.slots() {
|
||||
let Some((layer, expert)) = cache.needs_refill(slot).map_err(|e| driver_error(&e))? else { continue };
|
||||
@@ -304,21 +304,5 @@ pub(in crate::qwen_forward) fn settle_refill(cache: &mut OriginalExpertCache<'_>
|
||||
cache.sync_queued().map_err(|e| driver_error(&e))
|
||||
}
|
||||
|
||||
/// `LELEKA_REFILL_DEFER=on` (EXPERIMENTAL, off by default): queue the lent-slot refill inside the decode phase's
|
||||
/// assembly, after
|
||||
/// its intake uploads and before the graph capture, instead of waiting for it at the end of the prompt phase. Job 902
|
||||
/// measured
|
||||
/// the earlier variant (queued at the end of the prompt phase, waited later) as no gain: the PLE seed upload waited
|
||||
/// for the same
|
||||
/// DMA. The current variant has no GPU result yet (job 904), so it stays opt-in.
|
||||
pub(in crate::qwen_forward) fn refill_defer_enabled() -> bool {
|
||||
crate::settings::process().memory.refill_defer
|
||||
}
|
||||
|
||||
/// Copies per `cuMemcpyBatchAsync_v2` call of the batched refill (about 170 slots of three pieces).
|
||||
const REFILL_BATCH_COPIES: usize = 512;
|
||||
/// `LELEKA_REFILL_BATCH=on` (EXPERIMENTAL, off by default): batch the lent-slot refill's copies; the slot bytes are the
|
||||
/// per-copy path's, only the host's issue cost changes.
|
||||
fn refill_batch_enabled() -> bool {
|
||||
crate::settings::process().memory.refill_batch
|
||||
}
|
||||
|
||||
+8
-14
@@ -5,15 +5,13 @@ use super::{
|
||||
EXPERTS, ExpertTierConfig, GpuExpertPool, LAYERS, PcieAuto, PcieLag, ResidencyState, ResidencyStats,
|
||||
ResidentExpertBankSpan, Result, SpanCache, SwapSources, TOP_K, source_spans,
|
||||
};
|
||||
use crate::settings::MemorySettings;
|
||||
|
||||
impl std::fmt::Debug for SpanCache {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "SpanCache({} sets)", self.sets.len())
|
||||
}
|
||||
}
|
||||
pub(super) fn span_cache_enabled() -> bool {
|
||||
crate::settings::process().memory.span_cache
|
||||
}
|
||||
impl SpanCache {
|
||||
pub(super) fn key(layer: usize, expert: u32) -> u32 {
|
||||
(layer * EXPERTS) as u32 + expert
|
||||
@@ -32,8 +30,8 @@ impl PcieLag {
|
||||
pub(super) const MIN: u32 = 32;
|
||||
pub(super) const MAX: u32 = 176;
|
||||
pub(super) const WAIT: std::time::Duration = std::time::Duration::from_millis(3);
|
||||
pub(crate) fn from_environment(start_num: u32) -> Option<Self> {
|
||||
if !crate::settings::process().memory.pcie_auto_lag || start_num == 0 {
|
||||
pub(crate) fn from_settings(start_num: u32, memory: &MemorySettings) -> Option<Self> {
|
||||
if !memory.pcie_auto_lag || start_num == 0 {
|
||||
return None;
|
||||
}
|
||||
Some(Self {
|
||||
@@ -81,8 +79,8 @@ impl PcieLag {
|
||||
impl PcieAuto {
|
||||
pub(super) const TRIAL: u32 = 6;
|
||||
pub(super) const EXPLORE_EVERY: u32 = 30;
|
||||
pub(crate) fn from_environment(start_num: u32) -> Option<Self> {
|
||||
if !crate::settings::process().memory.pcie_auto_on || start_num == 0 {
|
||||
pub(crate) fn from_settings(start_num: u32, memory: &MemorySettings) -> Option<Self> {
|
||||
if !memory.pcie_auto_on || start_num == 0 {
|
||||
return None;
|
||||
}
|
||||
let levels: Vec<u32> = (2..=10).map(|i| i * 16).collect(); // 0.125 .. 0.625
|
||||
@@ -148,13 +146,9 @@ impl PcieAuto {
|
||||
}
|
||||
}
|
||||
impl ResidencyState {
|
||||
pub(crate) fn new(config: &ExpertTierConfig) -> Self {
|
||||
let routing = crate::settings::process()
|
||||
.memory
|
||||
.dump_routing
|
||||
.as_ref()
|
||||
.and_then(|path| std::fs::File::create(path).ok())
|
||||
.map(std::io::BufWriter::new);
|
||||
pub(crate) fn new(config: &ExpertTierConfig, memory: &MemorySettings) -> Self {
|
||||
let routing =
|
||||
memory.dump_routing.as_ref().and_then(|path| std::fs::File::create(path).ok()).map(std::io::BufWriter::new);
|
||||
Self {
|
||||
usage: if config.adaptive() { vec![0.0; LAYERS * EXPERTS] } else { Vec::new() },
|
||||
stats: ResidencyStats::default(),
|
||||
|
||||
+7
-11
@@ -5,7 +5,7 @@ use super::{
|
||||
CpuExpertPool, EXPERTS, Error, GpuExpertPool, GroupSplit, LAYERS, MappedExpertBank, ModelBinding, MoeWeightCache,
|
||||
OriginalGpuStream, OriginalServePool, OriginalVerifyCpuRows, OriginalVerifyCpuSink, OriginalVerifyPcieSource,
|
||||
PcieAuto, PcieLag, PcieSplitPolicy, Rc, ResidentExpertBankSpan, Result, RoutedGroup, SpanCache, StrataPcieAuto,
|
||||
Swap, SwapCap, SwapSources, TOP_K, TieOrder, choose_swaps_by, driver_error, span_cache_enabled, split_group_pcie,
|
||||
Swap, SwapCap, SwapSources, TOP_K, TieOrder, choose_swaps_by, driver_error, split_group_pcie,
|
||||
};
|
||||
|
||||
/// The source spans of `experts` of `layer`, in order: from the cache when seen before, else through the CPU
|
||||
@@ -16,7 +16,7 @@ pub(in super::super) fn source_spans(
|
||||
layer: usize,
|
||||
experts: &[u32],
|
||||
) -> Result<Vec<[ResidentExpertBankSpan; 3]>> {
|
||||
let cached = span_cache_enabled();
|
||||
let cached = sources.binding.settings().memory.span_cache;
|
||||
let fetch = experts_to_fetch(sources.known, layer, experts, cached);
|
||||
let mut fetched: Vec<[ResidentExpertBankSpan; 3]> = Vec::new();
|
||||
fetched.try_reserve_exact(fetch.len()).map_err(|_| Error::InputAllocation)?;
|
||||
@@ -94,8 +94,9 @@ impl<'ctx> OriginalServePool<'ctx> for GpuExpertPool<'_, '_, 'ctx> {
|
||||
fn apply_pending(&mut self) -> Result<()> {
|
||||
if !self.state.pcie_auto_checked {
|
||||
self.state.pcie_auto_checked = true;
|
||||
self.state.pcie_auto = PcieAuto::from_environment(self.pcie_num);
|
||||
self.state.pcie_lag = PcieLag::from_environment(self.pcie_num);
|
||||
let memory = &self.binding.settings().memory;
|
||||
self.state.pcie_auto = PcieAuto::from_settings(self.pcie_num, memory);
|
||||
self.state.pcie_lag = PcieLag::from_settings(self.pcie_num, memory);
|
||||
self.start_strata_pcie_auto();
|
||||
}
|
||||
if let Some(auto) = self.state.pcie_auto.as_mut() {
|
||||
@@ -109,7 +110,7 @@ impl<'ctx> OriginalServePool<'ctx> for GpuExpertPool<'_, '_, 'ctx> {
|
||||
// would otherwise read host memory while the CPU pool streams its experts (job 803: the overlap costs the CPU
|
||||
// share more than the wait), and the resident set no longer depends on when the copies finished.
|
||||
// LELEKA_SERVE_SWAP_WAIT=off polls instead (generate.cpp `apply_pending(false)`).
|
||||
if swap_wait() {
|
||||
if self.binding.settings().memory.swap_wait {
|
||||
return self.cache.wait_swaps().map_err(|e| driver_error(&e));
|
||||
}
|
||||
note_swap_poll();
|
||||
@@ -149,11 +150,6 @@ fn note_swap_poll() {
|
||||
ONCE.call_once(|| eprintln!("leleka-serve swap-wait: off (the adaptive swaps are polled at a round start)"));
|
||||
}
|
||||
|
||||
/// `LELEKA_SERVE_SWAP_WAIT=off`: poll the adaptive swaps at a round start instead of waiting for them.
|
||||
pub(super) fn swap_wait() -> bool {
|
||||
crate::settings::process().memory.swap_wait
|
||||
}
|
||||
|
||||
impl<'ctx> GpuExpertPool<'_, '_, 'ctx> {
|
||||
fn admit_group(rows: &OriginalVerifyCpuRows<'_>) -> Result<usize> {
|
||||
let layer = rows.layer;
|
||||
@@ -279,7 +275,7 @@ impl<'ctx> GpuExpertPool<'_, '_, 'ctx> {
|
||||
}
|
||||
/// How equal-gain swaps compete for the cap: the port's low-layer-first order unless `LELEKA_ADAPT_TIE_SPREAD`.
|
||||
fn tie_order(&self) -> TieOrder {
|
||||
if crate::settings::process().memory.adapt_tie_spread {
|
||||
if self.binding.settings().memory.adapt_tie_spread {
|
||||
TieOrder::SpreadLayers { round: self.state.stats.adaptations }
|
||||
} else {
|
||||
TieOrder::LowLayerFirst
|
||||
|
||||
-3
@@ -199,9 +199,6 @@ fn assign_kinds(
|
||||
/// `LELEKA_PCIE_LOCKED_ONLY=on|1` (read once): over a pageable file-mapped bank only the experts whose pages
|
||||
/// `pin_resident` locked may
|
||||
/// take the PCIe share; every other miss stays with the CPU pool. Off by default (the unrestricted split).
|
||||
pub(in crate::qwen_forward) fn pcie_locked_only() -> bool {
|
||||
crate::settings::process().memory.pcie_locked_only
|
||||
}
|
||||
|
||||
/// generate.cpp `adapt`'s ranking over `usage[l * 512 + e]`: per layer the non-resident experts routed at
|
||||
/// least twice (most first) against the resident ones (least first), pairwise while
|
||||
|
||||
+13
-11
@@ -9,12 +9,12 @@ use super::{
|
||||
use crate::settings::MemorySettings;
|
||||
|
||||
/// The tail-skip rank in force (0 = off): the environment, read once, unless a replay arm set it.
|
||||
pub(crate) fn tail_skip_rank() -> u32 {
|
||||
pub(crate) fn tail_skip_rank(memory: &MemorySettings) -> u32 {
|
||||
let rank = TAIL_SKIP_RANK.load(Ordering::Relaxed);
|
||||
if rank != TAIL_UNRESOLVED {
|
||||
return rank;
|
||||
}
|
||||
let rank = crate::settings::process().memory.route_tail_skip.filter(|r| (1..TOP_K as u32).contains(r)).unwrap_or(0);
|
||||
let rank = memory.route_tail_skip.filter(|r| (1..TOP_K as u32).contains(r)).unwrap_or(0);
|
||||
TAIL_SKIP_RANK.store(rank, Ordering::Relaxed);
|
||||
rank
|
||||
}
|
||||
@@ -26,15 +26,15 @@ pub(crate) fn set_tail_skip_arm(rank: Option<u32>) {
|
||||
}
|
||||
/// The rank this decode phase uses: `tail_skip_rank()` unless the cache holds at least the configured share of all
|
||||
/// experts.
|
||||
pub(crate) fn effective_tail_rank(cache: &OriginalExpertCache<'_>) -> u32 {
|
||||
let rank = tail_skip_rank();
|
||||
pub(crate) fn effective_tail_rank(cache: &OriginalExpertCache<'_>, memory: &MemorySettings) -> u32 {
|
||||
let rank = tail_skip_rank(memory);
|
||||
if rank == 0 {
|
||||
return 0;
|
||||
}
|
||||
let cached: usize =
|
||||
(0..LAYERS).map(|l| (0..EXPERTS).filter(|&e| cache.resident_slot(l, e).is_some()).count()).sum();
|
||||
let percent = 100.0 * cached as f64 / (LAYERS * EXPERTS) as f64;
|
||||
let limit = crate::settings::process().memory.route_tail_skip_max_cached;
|
||||
let limit = memory.route_tail_skip_max_cached;
|
||||
let effective = if percent >= limit { 0 } else { rank };
|
||||
static ANNOUNCED: AtomicU32 = AtomicU32::new(TAIL_UNRESOLVED);
|
||||
if ANNOUNCED.swap(effective, Ordering::Relaxed) != effective {
|
||||
@@ -137,14 +137,16 @@ impl ExpertTierConfig {
|
||||
pub(crate) fn adaptive(&self) -> bool {
|
||||
self.adapt_every > 0 && self.adapt_swaps > 0
|
||||
}
|
||||
/// The serve stack's environment switches (also the smoke's): `LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS`
|
||||
/// The serve stack's environment switches (also the smoke's), read from the real environment: the tools and tests
|
||||
/// that are their own composition root. The engine reads them from its settings with `from_source`.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn from_environment() -> Result<Self> {
|
||||
Self::from_source(crate::settings::Settings::from_environment().env())
|
||||
}
|
||||
/// The serve stack's environment switches: `LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS`
|
||||
/// (`auto` | N), `_EXPERT_PROFILE` (path), `_EXPERT_PER_LAYER` (`yes`), `_VRAM_RESERVE_MIB`,
|
||||
/// `_DECODE_RESERVE_MIB`, `_PCIE_FRAC`, `_ADAPT_EVERY`, `_ADAPT_SWAPS`, `_PREFILL_BORROW` (`no`).
|
||||
/// A value that does not parse is refused, never ignored.
|
||||
pub(crate) fn from_environment() -> Result<Self> {
|
||||
Self::from_source(crate::settings::process().env())
|
||||
}
|
||||
/// The same switches read from `env`.
|
||||
/// A value that does not parse is refused, never ignored. Read from `env`.
|
||||
pub(crate) fn from_source(env: &impl EnvSource) -> Result<Self> {
|
||||
let mut config = Self::off();
|
||||
config.read_placement(env)?;
|
||||
|
||||
@@ -352,6 +352,7 @@ fn the_configuration_is_off_by_default_and_refuses_what_it_cannot_honour() {
|
||||
assert!(ExpertTierConfig { pcie_frac: 1.5, ..off.clone() }.validate().is_err());
|
||||
assert!(ExpertTierConfig { pcie_frac: f64::NAN, ..off.clone() }.validate().is_err());
|
||||
assert!(!ExpertTierConfig { adapt_every: 0, ..off.clone() }.adaptive());
|
||||
assert!(ResidencyState::new(&ExpertTierConfig { adapt_swaps: 0, ..off.clone() }).usage.is_empty());
|
||||
assert_eq!(ResidencyState::new(&off).usage.len(), LAYERS * EXPERTS);
|
||||
let memory = crate::settings::Settings::from_environment().memory;
|
||||
assert!(ResidencyState::new(&ExpertTierConfig { adapt_swaps: 0, ..off.clone() }, &memory).usage.is_empty());
|
||||
assert_eq!(ResidencyState::new(&off, &memory).usage.len(), LAYERS * EXPERTS);
|
||||
}
|
||||
|
||||
+9
-2
@@ -137,9 +137,16 @@ fn the_pcie_link_is_a_positive_bandwidth_up_to_a_thousand() {
|
||||
#[test]
|
||||
fn the_controller_exists_only_for_the_switch_and_the_fixed_share_is_untouched() {
|
||||
let off = ExpertTierConfig::off();
|
||||
assert!(ResidencyState::new(&off).strata_pcie_link_gbps.is_none());
|
||||
assert!(
|
||||
ResidencyState::new(&off, &crate::settings::Settings::from_environment().memory)
|
||||
.strata_pcie_link_gbps
|
||||
.is_none()
|
||||
);
|
||||
let on = ExpertTierConfig { strata_pcie_auto: Some(30.0), ..off.clone() };
|
||||
assert_eq!(ResidencyState::new(&on).strata_pcie_link_gbps, Some(30.0));
|
||||
assert_eq!(
|
||||
ResidencyState::new(&on, &crate::settings::Settings::from_environment().memory).strata_pcie_link_gbps,
|
||||
Some(30.0)
|
||||
);
|
||||
assert_eq!(on.pcie_num(), off.pcie_num(), "the start share is the configured one");
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -209,9 +209,9 @@ pub(super) fn gpu_expert_pool<'p, 'a, 'ctx>(
|
||||
let TierResources { moe, cache, cpu, state } = resources;
|
||||
let bank = moe.original_expert_bank().ok_or(Error::IdentityMismatch)?;
|
||||
let pcie_num = tier.pcie_num_for(bank.pageable());
|
||||
let tail_rank = original_serve_residency::effective_tail_rank(&*cache);
|
||||
let tail_rank = original_serve_residency::effective_tail_rank(&*cache, &binding.settings().memory);
|
||||
let pcie_locked =
|
||||
if pcie_num > 0 && original_serve_residency::pcie_locked_only() { bank.locked_experts() } else { Vec::new() };
|
||||
if pcie_num > 0 && binding.settings().memory.pcie_locked_only { bank.locked_experts() } else { Vec::new() };
|
||||
Ok(GpuExpertPool {
|
||||
binding,
|
||||
moe,
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ pub(super) fn open_tier<'ctx>(
|
||||
let (binding, context, config, layout) = (ctx.binding, ctx.context, ctx.config, ctx.layout);
|
||||
let prefix = open_prefix(config);
|
||||
let conversation = if prefix.is_some() { None } else { config.conversation.clone().map(ServeConversation::new) };
|
||||
let residency = ResidencyState::new(&config.expert_tier);
|
||||
let residency = ResidencyState::new(&config.expert_tier, &binding.settings().memory);
|
||||
report_kernel_selection();
|
||||
vram_note(context, "before expert tier");
|
||||
let (expert_cache, loan) = open_expert_cache(binding, context, moe, config, layout)?;
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> {
|
||||
fn refill_deferred(&self, read_ok: bool, seeding: bool) -> bool {
|
||||
read_ok
|
||||
&& !seeding
|
||||
&& original_serve_residency::refill_defer_enabled()
|
||||
&& self.binding.settings().memory.refill_defer
|
||||
&& self.tier.loan.is_some()
|
||||
&& self.expert_cache.is_some()
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ pub(crate) use diagnostics::DiagnosticsSettings;
|
||||
pub(crate) use kv::KvSettings;
|
||||
#[cfg(test)]
|
||||
pub(crate) use kv::{FOOTPRINT_LEGACY_ON, PROMPT_EMBED_ALIAS_ON};
|
||||
pub(crate) use memory::MemorySettings;
|
||||
pub(crate) use memory::{CpuPoolSettings, MemorySettings};
|
||||
#[cfg(test)]
|
||||
pub(crate) use parse::{text_is_one_of, trimmed_text_is_one_of};
|
||||
pub(crate) use serve::ServeSettings;
|
||||
|
||||
Reference in New Issue
Block a user