Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensor tools print all #2543

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions candle-examples/examples/whisper-microphone/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ enum WhichModel {
Large,
LargeV2,
LargeV3,
LargeV3Turbo,
#[value(name = "distil-medium.en")]
DistilMediumEn,
#[value(name = "distil-large-v2")]
Expand All @@ -405,6 +406,7 @@ impl WhichModel {
| Self::Large
| Self::LargeV2
| Self::LargeV3
| Self::LargeV3Turbo
| Self::DistilLargeV2 => true,
Self::TinyEn | Self::BaseEn | Self::SmallEn | Self::MediumEn | Self::DistilMediumEn => {
false
Expand All @@ -425,6 +427,7 @@ impl WhichModel {
Self::Large => ("openai/whisper-large", "refs/pr/36"),
Self::LargeV2 => ("openai/whisper-large-v2", "refs/pr/57"),
Self::LargeV3 => ("openai/whisper-large-v3", "main"),
Self::LargeV3Turbo => ("openai/whisper-large-v3-turbo", "main"),
Self::DistilMediumEn => ("distil-whisper/distil-medium.en", "main"),
Self::DistilLargeV2 => ("distil-whisper/distil-large-v2", "main"),
}
Expand Down
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
Loading