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

Add --no-optimize flag to rten CLI #368

Merged
merged 1 commit into from
Sep 20, 2024
Merged
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
20 changes: 17 additions & 3 deletions rten-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ use std::collections::VecDeque;
use std::error::Error;
use std::time::Instant;

use rten::{Dimension, InputOrOutput, Model, ModelMetadata, NodeId, Output, RunOptions};
use rten::{
Dimension, InputOrOutput, Model, ModelMetadata, ModelOptions, NodeId, Output, RunOptions,
};
use rten_tensor::prelude::*;
use rten_tensor::Tensor;

struct Args {
/// Model file to load.
model: String,

/// Whether to enable graph optimizations
optimize: bool,

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

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

let mut parser = lexopt::Parser::from_env();
while let Some(arg) = parser.next()? {
Expand All @@ -120,6 +126,7 @@ fn parse_args() -> Result<Args, lexopt::Error> {
.parse()
.map_err(|_| "Unable to parse `n_iters`".to_string())?;
}
Long("no-optimize") => optimize = false,
Short('q') | Long("quiet") => quiet = true,
Short('v') | Long("verbose") => verbose = true,
Short('V') | Long("version") => {
Expand Down Expand Up @@ -151,6 +158,8 @@ Options:
-n, --n_iters <n>
Number of times to evaluate model

--no-optimize Disable graph optimizations

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

-t, --timing Output timing info
Expand All @@ -176,6 +185,7 @@ Options:
model,
n_iters,
mmap,
optimize,
quiet,
timing,
verbose,
Expand Down Expand Up @@ -404,10 +414,14 @@ fn print_input_output_list(model: &Model, node_ids: &[NodeId]) {
/// running. See `docs/profiling.md`.
fn main() -> Result<(), Box<dyn Error>> {
let args = parse_args()?;

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

let model = if args.mmap {
unsafe { Model::load_mmap(args.model)? }
unsafe { model_opts.load_mmap(args.model)? }
} else {
Model::load_file(args.model)?
model_opts.load_file(args.model)?
};

if !args.quiet {
Expand Down
Loading