Skip to content

Commit

Permalink
Tensor tools print all (#2543)
Browse files Browse the repository at this point in the history
* Support whisper large-v3 turbo in the whisper-microphone example.

* Print all tensors when no argument is provided.
  • Loading branch information
LaurentMazare authored Oct 5, 2024
1 parent 410c89f commit d2e4329
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tensor-tools/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ fn run_print(
match format {
Format::Npz => {
let tensors = candle::npy::NpzTensors::new(file)?;
let names = if names.is_empty() {
tensors.names().into_iter().map(|v| v.to_string()).collect()
} else {
names
};
for name in names.iter() {
println!("==== {name} ====");
match tensors.get(name)? {
Expand All @@ -209,6 +214,11 @@ fn run_print(
use candle::safetensors::Load;
let tensors = unsafe { candle::safetensors::MmapedSafetensors::new(file)? };
let tensors: std::collections::HashMap<_, _> = tensors.tensors().into_iter().collect();
let names = if names.is_empty() {
tensors.keys().map(|v| v.to_string()).collect()
} else {
names
};
for name in names.iter() {
println!("==== {name} ====");
match tensors.get(name) {
Expand All @@ -222,6 +232,15 @@ fn run_print(
}
Format::Pth => {
let pth_file = candle::pickle::PthTensors::new(file, None)?;
let names = if names.is_empty() {
pth_file
.tensor_infos()
.keys()
.map(|v| v.to_string())
.collect()
} else {
names
};
for name in names.iter() {
println!("==== {name} ====");
match pth_file.get(name)? {
Expand All @@ -238,6 +257,11 @@ fn run_print(
Format::Ggml => {
let mut file = std::fs::File::open(file)?;
let content = candle::quantized::ggml_file::Content::read(&mut file, device)?;
let names = if names.is_empty() {
content.tensors.keys().map(|v| v.to_string()).collect()
} else {
names
};
for name in names.iter() {
println!("==== {name} ====");
match content.tensors.get(name) {
Expand All @@ -252,6 +276,11 @@ fn run_print(
Format::Gguf => {
let mut file = std::fs::File::open(file)?;
let content = gguf_file::Content::read(&mut file)?;
let names = if names.is_empty() {
content.tensor_infos.keys().map(|v| v.to_string()).collect()
} else {
names
};
for name in names.iter() {
println!("==== {name} ====");
match content.tensor(&mut file, name, device) {
Expand Down

0 comments on commit d2e4329

Please sign in to comment.