loan ladder: tier_for helper and test
This commit is contained in:
@@ -207,6 +207,11 @@ struct LoanTier {
|
||||
/// Chunk sizes (rows) that get their own, smaller loan below the configured capacity.
|
||||
const LOAN_TIER_ROWS: [usize; 2] = [512, 2048];
|
||||
|
||||
/// The smallest rung of the ladder that holds a chunk of `count` rows (`None`: the full loan).
|
||||
fn tier_for(tiers: &[LoanTier], count: usize) -> Option<&LoanTier> {
|
||||
tiers.iter().find(|t| count <= t.rows)
|
||||
}
|
||||
|
||||
fn loan_tiers_enabled() -> bool {
|
||||
std::env::var("LELEKA_PREFILL_LOAN_TIERS").map_or(true, |v| v != "0")
|
||||
}
|
||||
@@ -1390,7 +1395,7 @@ impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> {
|
||||
(Some(slots), Some(cache), _) => match {
|
||||
let _span = super::prefill_profile::span(super::prefill_profile::Stage::Lend, None);
|
||||
// the smallest rung of the ladder that holds the chunk
|
||||
let (slots, options) = loan_tiers.iter().find(|t| count <= t.rows).map_or((slots, *layout), |t| (t.slots, t.layout));
|
||||
let (slots, options) = tier_for(loan_tiers, count).map_or((slots, *layout), |t| (t.slots, t.layout));
|
||||
cache.lend_prefill_tail(slots, options)
|
||||
} {
|
||||
Ok(mut lent) => chunk.run(count, &mut lent, cancel),
|
||||
@@ -1845,6 +1850,25 @@ impl<'a, 'ctx> RequestOwners for OriginalServeStack<'a, 'ctx> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_chunk_borrows_the_smallest_rung_that_holds_it() {
|
||||
let blobs = ExpertBlobSizes::from_layer_bytes(std::array::from_fn(|l| 700_000 + 4096 * l), [700_000; 48], [900_000; 48]).unwrap();
|
||||
let layout = prefill_layout_options(8192, 262_144, &blobs);
|
||||
let tiers: Vec<LoanTier> = [(512usize, 600usize), (2048, 900)]
|
||||
.into_iter()
|
||||
.map(|(rows, slots)| LoanTier { rows, layout: PrefillLayoutOptions { capacity: rows, ..layout }, slots })
|
||||
.collect();
|
||||
assert_eq!(tier_for(&tiers, 1).map(|t| t.rows), Some(512));
|
||||
assert_eq!(tier_for(&tiers, 512).map(|t| t.rows), Some(512));
|
||||
assert_eq!(tier_for(&tiers, 513).map(|t| t.rows), Some(2048));
|
||||
assert_eq!(tier_for(&tiers, 2048).map(|t| t.slots), Some(900));
|
||||
assert!(tier_for(&tiers, 2049).is_none(), "above the ladder the chunk borrows the full loan");
|
||||
assert!(tier_for(&[], 100).is_none());
|
||||
// the arena of a smaller rung is smaller
|
||||
assert!(prefill_bytes(tiers[0].layout).unwrap() < prefill_bytes(tiers[1].layout).unwrap());
|
||||
assert!(prefill_bytes(tiers[1].layout).unwrap() < prefill_bytes(layout).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_default_chunk_is_an_admitted_capacity_and_validation_follows_the_prefill_rules() {
|
||||
let config = StackConfig::new(4096);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# claude/perf3 task 2: the prompt loan ladder against the full-capacity loan, same chunk 8192 / grid 8192, the live CRM session 9e3 (first 30 requests, teacher forced), arms T N N T inside one
|
||||
# claude/perf3 task 2: the prompt loan ladder against the full-capacity loan, same chunk 8192 / grid 8192, the live CRM session 9e3 (first 24 requests, teacher forced), arms T N N T inside one
|
||||
# process (T = ladder, N = `!notiers`: every chunk borrows the full 1.9 GB loan and refills it). Tier = the live one (auto-sized per-layer cache, adaptation and seed at their defaults).
|
||||
export BIN=$HOME/work/leleka-perf3/bin/rt-a4
|
||||
export LELEKA_BRINGUP_TRACE=1
|
||||
source ~/work/ttft-jobs/ttft-common.sh
|
||||
export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=auto
|
||||
run_ttft loan-tiers-ab original_serve_replay::original_serve_replay_smoke LELEKA_REPLAY_DIR=$CAP/9e3-crm-tail-reply LELEKA_REPLAY_COUNT=${COUNT:-30} LELEKA_REPLAY_PREFIX_MIB=20000 \
|
||||
run_ttft loan-tiers-ab original_serve_replay::original_serve_replay_smoke LELEKA_REPLAY_DIR=$CAP/9e3-crm-tail-reply LELEKA_REPLAY_COUNT=${COUNT:-24} LELEKA_REPLAY_PREFIX_MIB=20000 \
|
||||
LELEKA_PREFIX_TRACE=1 \
|
||||
LELEKA_REPLAY_ARMS=T1=reply@8192,N1=reply@8192!notiers,N2=reply@8192!notiers,T2=reply@8192 LELEKA_REPLAY_FORCE=1
|
||||
date -u +%FT%TZ
|
||||
|
||||
Reference in New Issue
Block a user