use rlx_core::config::BertConfig;
use rlx_core::weight_map::WeightMap;
use std::collections::HashMap;
pub(crate) fn tiny_bert_weights(cfg: &BertConfig) -> WeightMap {
let h = cfg.hidden_size;
let int = cfg.intermediate_size;
let mut tensors: HashMap<String, (Vec<f32>, Vec<usize>)> = HashMap::new();
let mut add = |key: String, shape: Vec<usize>| {
let n: usize = shape.iter().product();
tensors.insert(key, (vec![0.0f32; n], shape));
};
add(
"embeddings.word_embeddings.weight".into(),
vec![cfg.vocab_size, h],
);
add(
"embeddings.position_embeddings.weight".into(),
vec![cfg.max_position_embeddings, h],
);
add(
"embeddings.token_type_embeddings.weight".into(),
vec![cfg.type_vocab_size, h],
);
add("embeddings.LayerNorm.weight".into(), vec![h]);
add("embeddings.LayerNorm.bias".into(), vec![h]);
for i in 0..cfg.num_hidden_layers {
let lp = format!("encoder.layer.{i}");
for proj in ["query", "key", "value"] {
add(format!("{lp}.attention.self.{proj}.weight"), vec![h, h]);
add(format!("{lp}.attention.self.{proj}.bias"), vec![h]);
}
add(format!("{lp}.attention.output.dense.weight"), vec![h, h]);
add(format!("{lp}.attention.output.dense.bias"), vec![h]);
add(format!("{lp}.attention.output.LayerNorm.weight"), vec![h]);
add(format!("{lp}.attention.output.LayerNorm.bias"), vec![h]);
add(format!("{lp}.intermediate.dense.weight"), vec![int, h]);
add(format!("{lp}.intermediate.dense.bias"), vec![int]);
add(format!("{lp}.output.dense.weight"), vec![h, int]);
add(format!("{lp}.output.dense.bias"), vec![h]);
add(format!("{lp}.output.LayerNorm.weight"), vec![h]);
add(format!("{lp}.output.LayerNorm.bias"), vec![h]);
}
WeightMap::from_tensors(tensors)
}
pub(crate) fn weights_with_keys(keys: &[&str]) -> WeightMap {
let tensors: HashMap<String, (Vec<f32>, Vec<usize>)> = keys
.iter()
.map(|k| (k.to_string(), (Vec::new(), Vec::new())))
.collect();
WeightMap::from_tensors(tensors)
}