fix(serve): default --pcie-frac 0.55 only over a pinned expert bank

The 0.55 default (3e8e10e) also applied to the laptop's pageable low-RAM
mapped bank, whose PCIe share is DMA'd from pageable pages (the copy kernel
needs aliases): the coordinator's 3080 runs decoded at 6.66 tok/s against
~10-12 with 0. Unset, the share is now 0 for a pageable bank and 0.55 for a
registered one; an operator's LELEKA_ORIGINAL_SERVE_PCIE_FRAC applies as given.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-10-17 00:01:47 +02:00
co-authored by Claude Opus 5.5
parent c45bcaafd7
commit a9f67649ee
3 changed files with 18 additions and 3 deletions
@@ -82,6 +82,9 @@ pub(crate) struct ExpertTierConfig {
/// `--pcie-frac` (0.55, generate.cpp's default): the share of a group's missed experts staged over PCIe (by the
/// copy kernel or DMA, `pcie_mode`). Only used while the tier is on.
pub(crate) pcie_frac: f64,
/// `pcie_frac` was set by the operator. Unset, a pageable (low-RAM, file-mapped) bank stages nothing over PCIe:
/// its misses would be DMA'd from pageable pages (job report: 6.7 vs 10-12 tok/s on the 3080 laptop).
pub(crate) pcie_frac_set: bool,
/// `--pcie-mode` (auto).
pub(crate) pcie_mode: PcieMode,
/// `--adapt-every` (4) and `--adapt-swaps` (96); either 0 turns the adaptive tier off.
@@ -101,6 +104,7 @@ impl ExpertTierConfig {
reserve_mib: 700,
decode_reserve_mib: 1024,
pcie_frac: 0.55,
pcie_frac_set: false,
pcie_mode: PcieMode::Auto,
adapt_every: 4,
adapt_swaps: 96,
@@ -128,6 +132,11 @@ impl ExpertTierConfig {
pub(crate) fn pcie_num(&self) -> u32 {
(self.pcie_frac * 256.0 + 0.5).clamp(0.0, 256.0) as u32
}
/// `pcie_num` for the bank the tier reads: the default 0.55 needs a registered (pinned, aliased) source; a
/// pageable mapped bank takes 0 unless the operator set a share.
pub(crate) fn pcie_num_for(&self, pageable_source: bool) -> u32 {
if pageable_source && !self.pcie_frac_set { 0 } else { self.pcie_num() }
}
pub(crate) fn adaptive(&self) -> bool {
self.adapt_every > 0 && self.adapt_swaps > 0
}
@@ -155,6 +164,7 @@ impl ExpertTierConfig {
number("DECODE_RESERVE_MIB", &mut config.decode_reserve_mib)?;
if let Some(v) = var("PCIE_FRAC") {
config.pcie_frac = v.parse().map_err(|_| Error::InvalidDimension)?;
config.pcie_frac_set = true;
}
if let Some(v) = var("PCIE_MODE") {
config.pcie_mode = match v.as_str() {
@@ -759,6 +769,10 @@ mod tests {
assert_eq!(with_profile.effective_slots(), -1);
assert_eq!(ExpertTierConfig { slots: 2048, ..off.clone() }.effective_slots(), 2048);
assert_eq!(ExpertTierConfig { pcie_frac: 0.55, ..off.clone() }.pcie_num(), 141);
// the default share needs a pinned source; an operator's share applies to a pageable bank too
assert_eq!(off.pcie_num_for(false), 141);
assert_eq!(off.pcie_num_for(true), 0);
assert_eq!(ExpertTierConfig { pcie_frac: 0.3, pcie_frac_set: true, ..off.clone() }.pcie_num_for(true), 77);
assert_eq!(ExpertTierConfig { pcie_frac: 1.0, ..off.clone() }.pcie_num(), 256);
assert!(ExpertTierConfig { slots: -2, ..off.clone() }.validate().is_err());
assert!(ExpertTierConfig { pcie_frac: 1.5, ..off.clone() }.validate().is_err());
@@ -495,7 +495,7 @@ impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> {
}
// generate.cpp `ver.set_pcie_mode`: only a window that can stage anything over PCIe records the copy kernel.
let pcie_mode = match (expert_cache.as_ref(), moe.original_expert_bank()) {
(Some(_), Some(bank)) if config.expert_tier.pcie_num() > 0 => {
(Some(_), Some(bank)) if config.expert_tier.pcie_num_for(bank.pageable()) > 0 => {
config.expert_tier.pcie_mode.graph_mode(bank.pageable(), blobs.spans_tile_blobs()).ok_or(Error::Unsupported(
super::contract::Stage::Session,
))?
@@ -540,6 +540,7 @@ impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> {
let mut gpu_pool;
let pool: &mut dyn OriginalServePool<'ctx> = match (expert_cache.as_mut(), moe.original_expert_bank()) {
(Some(cache), Some(bank)) => {
let pcie_num = config.expert_tier.pcie_num_for(bank.pageable());
gpu_pool = GpuExpertPool {
binding,
moe: &*moe,
@@ -547,7 +548,7 @@ impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> {
bank,
cpu: &mut *pool,
state: &mut *residency,
pcie_num: config.expert_tier.pcie_num(),
pcie_num,
adapt_every: config.expert_tier.adapt_every,
adapt_swaps: config.expert_tier.adapt_swaps as usize,
};
+1 -1
View File
@@ -49,7 +49,7 @@ The load must be the explicit KAR PLE MTP load, as for the windowed256 modes.
| `LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS` = `auto` \| N | `--expert-cache` | off (a profile alone means auto) |
| `LELEKA_ORIGINAL_SERVE_EXPERT_PER_LAYER=yes` | `--expert-cache-per-layer` | global |
| `LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=P` | `--expert-profile` | none |
| `LELEKA_ORIGINAL_SERVE_PCIE_FRAC` | `--pcie-frac` | 0.55 (job 802) |
| `LELEKA_ORIGINAL_SERVE_PCIE_FRAC` | `--pcie-frac` | 0.55 over a pinned bank (job 802); 0 over the pageable low-RAM bank unless set |
| `LELEKA_ORIGINAL_SERVE_PCIE_MODE` = `auto` \| `dma` \| `kernel` | `--pcie-mode` | auto (the copy kernel when the bank has device aliases) |
| `LELEKA_ORIGINAL_SERVE_ADAPT_EVERY` / `_ADAPT_SWAPS` | `--adapt-every` / `--adapt-swaps` | 4 / 96 |
| `LELEKA_ORIGINAL_SERVE_VRAM_RESERVE_MIB` / `_DECODE_RESERVE_MIB` | `--vram-reserve-mib` / port only | 700 / 1024 (auto sizing) |