-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: YdrMaster <ydrml@hotmail.com>
- Loading branch information
Showing
15 changed files
with
291 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ show = "xtask show" | |
split = "xtask split" | ||
merge = "xtask merge" | ||
filter = "xtask filter" | ||
convert = "xtask convert" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use crate::utils::{operate, show_file_info, Operator, OutputConfig, Shards}; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Args, Default)] | ||
pub struct ConvertArgs { | ||
/// File to split | ||
file: PathBuf, | ||
/// Output directory for splited shards | ||
#[clap(long, short)] | ||
output_dir: Option<PathBuf>, | ||
/// Operations to apply, separated by "->" | ||
#[clap(long)] | ||
ops: String, | ||
/// Max count of tensors per shard | ||
#[clap(long, short = 't')] | ||
max_tensors: Option<usize>, | ||
/// Max size in bytes per shard | ||
#[clap(long, short = 's')] | ||
max_bytes: Option<String>, | ||
/// If set, the first shard will not contain any tensor | ||
#[clap(long, short)] | ||
no_tensor_first: bool, | ||
} | ||
|
||
impl ConvertArgs { | ||
pub fn convert(self) { | ||
let Self { | ||
file, | ||
output_dir, | ||
ops, | ||
max_tensors, | ||
max_bytes, | ||
no_tensor_first, | ||
} = self; | ||
|
||
let shards = Shards::from(&*file); | ||
let files = operate( | ||
shards.iter_all(), | ||
ops.split("->").map(|op| { | ||
let op = op.trim(); | ||
if let Some(content) = op.strip_prefix("filter-meta:") { | ||
Operator::filter_meta_key(content) | ||
} else if let Some(content) = op.strip_prefix("filter-tensor:") { | ||
Operator::filter_tensor_name(content) | ||
} else if let Some(content) = op.strip_prefix("cast:") { | ||
Operator::cast(content) | ||
} else { | ||
panic!("Unsupported operation: {}", op) | ||
} | ||
}), | ||
OutputConfig { | ||
dir: output_dir.unwrap_or_else(|| std::env::current_dir().unwrap()), | ||
name: shards.name.into(), | ||
shard_max_tensor_count: max_tensors.unwrap_or(usize::MAX), | ||
shard_max_file_size: max_bytes.map_or(Default::default(), |s| s.parse().unwrap()), | ||
shard_no_tensor_first: no_tensor_first, | ||
}, | ||
) | ||
.unwrap(); | ||
|
||
show_file_info(&files); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.