teeny_quant/cli/
inspect.rs1use std::path::PathBuf;
21
22use anyhow::{Context, Result};
23use clap::Args;
24
25use crate::format;
26use crate::read::read_metadata;
27
28#[derive(Args, Debug)]
30pub struct InspectArgs {
31 pub path: PathBuf,
33}
34
35pub fn run(args: InspectArgs) -> Result<()> {
37 let mapped = teeny_data::safetensors::SafeTensors::from_pretrained(&args.path)
38 .with_context(|| format!("failed to open '{}'", args.path.display()))?;
39 let tensors = mapped.tensors().with_context(|| {
40 format!(
41 "failed to read tensor headers from '{}'",
42 args.path.display()
43 )
44 })?;
45
46 let mut names = tensors.names();
47 names.sort();
48
49 println!("{:<55} {:<10} {:>14} shape", "name", "dtype", "bytes");
50 let mut total_bytes = 0usize;
51 for name in &names {
52 let view = tensors
53 .tensor(name)
54 .with_context(|| format!("reading tensor '{name}'"))?;
55 let nbytes = view.data().len();
56 total_bytes += nbytes;
57 println!(
58 "{:<55} {:<10} {:>14} {:?}",
59 name,
60 format!("{:?}", view.dtype()),
61 nbytes,
62 view.shape()
63 );
64 }
65 println!(
66 "\n{} tensor(s), {:.2} MiB total",
67 names.len(),
68 total_bytes as f64 / (1024.0 * 1024.0)
69 );
70
71 let metadata = read_metadata(&args.path)?;
72 if let Some(config) = format::config_from_metadata(&metadata)? {
73 println!(
74 "\nquantization_config:\n{}",
75 serde_json::to_string_pretty(&config)?
76 );
77 }
78
79 Ok(())
80}