use cortiq_core::{CmfModel, TensorSpec};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut args = std::env::args().skip(1);
let (inp, out) = (args.next().expect("in.cmf"), args.next().expect("out.cmf"));
let m = CmfModel::open(&inp)?;
let tensors: Vec<TensorSpec> = m
.tensors
.iter()
.map(|t| TensorSpec {
name: t.name.clone(),
dtype: t.dtype,
shape: t.shape.clone(),
data: m.entry_bytes(t).to_vec(),
})
.collect();
let mut catalog = m.masks.clone();
let hb = m.header.arch.num_attention_heads.div_ceil(8);
let tail = m.header.arch.num_attention_heads % 8;
let mut row = vec![0xFFu8; hb];
if tail != 0 {
row[hb - 1] = (1u8 << tail) - 1;
}
for mask in &mut catalog.masks {
mask.head_masks = vec![row.clone(); m.header.arch.num_layers];
}
if std::env::var("STRIP").as_deref() == Ok("1") {
CmfModel::write(&out, &m.header, &tensors, None, m.vocab.as_deref())?;
println!("wrote {out} with NO masks");
} else {
CmfModel::write(&out, &m.header, &tensors, Some(&catalog), m.vocab.as_deref())?;
println!("wrote {out} with open head masks");
}
Ok(())
}