From fa967b66ee128570ea8d6746d1ab6a430aa88577 Mon Sep 17 00:00:00 2001 From: Simon Fan Date: Fri, 6 Dec 2024 14:32:32 -0800 Subject: [PATCH] cargo fmt --- src/lib.rs | 39 ++++++++++++++++++++++----------------- src/parsers.rs | 34 ++++++++++++++++++++-------------- src/types.rs | 20 ++++++++++++++------ 3 files changed, 56 insertions(+), 37 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ee75854..f85351b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -378,22 +378,24 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result { - format!("-_{}_{}_{}", d.frame_id, d.frame_compile_id, d.attempt) + .map_or(format!("unknown_{lineno}"), |c| match c { + CompileId::UserInitiated(d) => { + format!("-_{}_{}_{}", d.frame_id, d.frame_compile_id, d.attempt) + } + CompileId::CompiledAutogradInitiated { + compiled_autograd_id, + dynamo_id, + } => { + if let Some(d) = dynamo_id { + format!( + "{}_{}_{}_{}", + compiled_autograd_id, d.frame_id, d.frame_compile_id, d.attempt + ) + } else { + format!("{}_-_-_-", compiled_autograd_id) } - CompileId::CompiledAutogradInitiated { compiled_autograd_id, dynamo_id } => { - - if let Some(d) = dynamo_id { - format!("{}_{}_{}_{}", compiled_autograd_id, d.frame_id, d.frame_compile_id, d.attempt) - } else { - format!("{}_-_-_-", compiled_autograd_id) - } - }, } - ) + }) .into(); let parser: Box = Box::new(crate::parsers::CompilationMetricsParser { @@ -462,10 +464,13 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result { // Is this for data migration? d.attempt = 0; - }, - CompileId::CompiledAutogradInitiated { compiled_autograd_id: _, dynamo_id: _ } => { + } + CompileId::CompiledAutogradInitiated { + compiled_autograd_id: _, + dynamo_id: _, + } => { // DynamoId should already have attempt set - }, + } } } metrics_index.entry(cid).or_default().push(m.clone()); diff --git a/src/parsers.rs b/src/parsers.rs index 426963f..af80c10 100644 --- a/src/parsers.rs +++ b/src/parsers.rs @@ -56,21 +56,24 @@ fn simple_file_output( ) -> anyhow::Result { let compile_id_dir: PathBuf = compile_id .as_ref() - .map_or( - format!("unknown_{lineno}"), - |c | match c { - CompileId::UserInitiated(d) => { - format!("-_{}_{}_{}", d.frame_id, d.frame_compile_id, d.attempt) - } - CompileId::CompiledAutogradInitiated { compiled_autograd_id, dynamo_id } => { - if let Some(d) = dynamo_id { - format!("{}_{}_{}_{}", compiled_autograd_id, d.frame_id, d.frame_compile_id, d.attempt) - } else { - format!("{}_-_-_-", compiled_autograd_id) - } + .map_or(format!("unknown_{lineno}"), |c| match c { + CompileId::UserInitiated(d) => { + format!("-_{}_{}_{}", d.frame_id, d.frame_compile_id, d.attempt) + } + CompileId::CompiledAutogradInitiated { + compiled_autograd_id, + dynamo_id, + } => { + if let Some(d) = dynamo_id { + format!( + "{}_{}_{}_{}", + compiled_autograd_id, d.frame_id, d.frame_compile_id, d.attempt + ) + } else { + format!("{}_-_-_-", compiled_autograd_id) } } - ) + }) .into(); let subdir = PathBuf::from(compile_id_dir); let f = subdir.join(filename); @@ -392,7 +395,10 @@ impl StructuredLogParser for CompilationMetricsParser<'_> { // Is this for data migration? d.attempt = 0; } - CompileId::CompiledAutogradInitiated { compiled_autograd_id: _, dynamo_id: _} => { + CompileId::CompiledAutogradInitiated { + compiled_autograd_id: _, + dynamo_id: _, + } => { // DynamoId should already have attempt set } } diff --git a/src/types.rs b/src/types.rs index e30d7ba..3d5991f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -137,7 +137,7 @@ pub struct DynamoId { #[serde(untagged)] pub enum CompileId { // NOTE: serde(untagged) will match in the order - // this enum is defined + // this enum is defined // When compiled autograd calls torch.compile CompiledAutogradInitiated { @@ -146,7 +146,7 @@ pub enum CompileId { dynamo_id: Option, }, // When user calls torch.compile - UserInitiated(DynamoId) + UserInitiated(DynamoId), } fn _format_dynamo_id(d: &DynamoId) -> String { @@ -170,10 +170,18 @@ impl fmt::Display for CompileId { match self { CompileId::UserInitiated(d) => { write!(f, "[-/{}]", _format_dynamo_id(d)) - }, - CompileId::CompiledAutogradInitiated { compiled_autograd_id, dynamo_id } => { - write!(f, "[{}/{}]", compiled_autograd_id, format_dynamo_id(dynamo_id)) - }, + } + CompileId::CompiledAutogradInitiated { + compiled_autograd_id, + dynamo_id, + } => { + write!( + f, + "[{}/{}]", + compiled_autograd_id, + format_dynamo_id(dynamo_id) + ) + } } } }