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

Support pre-packed weights #483

Merged
merged 2 commits into from
Dec 25, 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
16 changes: 13 additions & 3 deletions rten-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ struct Args {
/// Whether to enable graph optimizations
optimize: bool,

/// Whether to enable prepacking of weights
prepack_weights: bool,

/// Run model and don't produce other output
quiet: bool,

Expand Down Expand Up @@ -115,6 +118,7 @@ fn parse_args() -> Result<Args, lexopt::Error> {
let mut verbose = false;
let mut input_sizes = Vec::new();
let mut optimize = true;
let mut prepack_weights = false;

let mut parser = lexopt::Parser::from_env();
while let Some(arg) = parser.next()? {
Expand All @@ -128,6 +132,7 @@ fn parse_args() -> Result<Args, lexopt::Error> {
.map_err(|_| "Unable to parse `n_iters`".to_string())?;
}
Long("no-optimize") => optimize = false,
Short('p') | Long("prepack") => prepack_weights = true,
Short('q') | Long("quiet") => quiet = true,
Short('v') | Long("verbose") => verbose = true,
Short('V') | Long("version") => {
Expand Down Expand Up @@ -163,12 +168,15 @@ Options:

-q, --quiet Run model and don't produce other output

-t, --timing Output timing info
-p, --prepack Enable prepacking of weights.
This requires additional memory but makes inference faster.

-s, --size <spec>
Specify size for a dynamic dimension in the form `dim_name=size`
or `input_name.dim_name=size`

-t, --timing Output timing info

-v, --verbose Enable verbose logging
-V, --version Display RTen version
",
Expand All @@ -183,14 +191,15 @@ Options:
let model = values.pop_front().ok_or("missing `<model>` arg")?;

Ok(Args {
input_sizes,
mmap,
model,
n_iters,
mmap,
optimize,
prepack_weights,
quiet,
timing,
verbose,
input_sizes,
})
}

Expand Down Expand Up @@ -461,6 +470,7 @@ fn main() -> Result<(), Box<dyn Error>> {

let mut model_opts = ModelOptions::with_all_ops();
model_opts.enable_optimization(args.optimize);
model_opts.prepack_weights(args.prepack_weights);

let model = if args.mmap {
unsafe { model_opts.load_mmap(args.model)? }
Expand Down
10 changes: 10 additions & 0 deletions src/gemm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ impl<T> PackedBMatrix<T> {
fn panel_len(&self) -> usize {
self.panel_width * self.rows
}

/// Number of rows in the unpacked matrix.
pub fn rows(&self) -> usize {
self.rows
}

/// Number of columns in the unpacked matrix.
pub fn cols(&self) -> usize {
self.cols
}
}

impl<T> ExtractBuffer for PackedBMatrix<T> {
Expand Down
Loading
Loading