1use crate::tier::StorageTier;
8use crate::write::PackedWeight;
9use std::collections::HashSet;
10
11#[derive(Debug, Clone)]
13pub struct AutoTierOptions {
14 pub hot_names: HashSet<String>,
16 pub warm_substrings: Vec<String>,
18 pub warm_min_bytes: usize,
20}
21
22impl Default for AutoTierOptions {
23 fn default() -> Self {
24 Self {
25 hot_names: HashSet::new(),
26 warm_substrings: vec![
27 "expert".into(),
28 "experts".into(),
29 "lora".into(),
30 "ffn_gate_exps".into(),
31 "ffn_up_exps".into(),
32 "ffn_down_exps".into(),
33 ],
34 warm_min_bytes: 16 << 20, }
36 }
37}
38
39pub fn apply_auto_tier(weights: &mut [PackedWeight], opts: &AutoTierOptions) {
44 for w in weights.iter_mut() {
45 if opts.hot_names.contains(&w.name) {
46 w.tier = StorageTier::Hot;
47 continue;
48 }
49 let lower = w.name.to_ascii_lowercase();
50 if opts
51 .warm_substrings
52 .iter()
53 .any(|s| lower.contains(&s.to_ascii_lowercase()))
54 {
55 w.tier = StorageTier::Warm;
56 continue;
57 }
58 if w.data.len() >= opts.warm_min_bytes && w.tier == StorageTier::Hot {
59 w.tier = StorageTier::Warm;
60 }
61 }
62}