Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
xmfan committed Dec 6, 2024
1 parent fb20d4d commit fa967b6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 37 deletions.
39 changes: 22 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,22 +378,24 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
let compile_id_dir: PathBuf = e
.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)
.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<dyn StructuredLogParser> =
Box::new(crate::parsers::CompilationMetricsParser {
Expand Down Expand Up @@ -462,10 +464,13 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result<ParseOu
CompileId::UserInitiated(d) => {
// 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());
Expand Down
34 changes: 20 additions & 14 deletions src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,24 @@ fn simple_file_output(
) -> anyhow::Result<ParserResults> {
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);
Expand Down Expand Up @@ -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
}
}
Expand Down
20 changes: 14 additions & 6 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -146,7 +146,7 @@ pub enum CompileId {
dynamo_id: Option<DynamoId>,
},
// When user calls torch.compile
UserInitiated(DynamoId)
UserInitiated(DynamoId),
}

fn _format_dynamo_id(d: &DynamoId) -> String {
Expand All @@ -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)
)
}
}
}
}
Expand Down

0 comments on commit fa967b6

Please sign in to comment.