Skip to content

Commit

Permalink
Add support for "graph_dump" log (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
ezyang authored Apr 15, 2024
1 parent 8b03b33 commit ab7353a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,38 @@ impl StructuredLogParser for SentinelFileParser {
}
}

/**
* Generic parser for graph_dump entries
*/
pub struct GraphDumpParser;
impl StructuredLogParser for GraphDumpParser {
fn name(&self) -> &'static str {
"graph_dump" // ToDO: more specific?
}
fn get_metadata<'e>(&self, e: &'e Envelope) -> Option<Metadata<'e>> {
e.graph_dump.as_ref().map(|m| Metadata::GraphDump(m))
}
fn parse<'e>(
&self,
lineno: usize,
metadata: Metadata<'e>,
_rank: Option<u32>,
compile_id: &Option<CompileId>,
payload: &str,
) -> anyhow::Result<ParseOutput> {
if let Metadata::GraphDump(metadata) = metadata {
let filename: PathBuf = {
let mut r = OsString::from(&metadata.name);
r.push(OsStr::new(".txt"));
r.into()
};
simple_file_output(&filename.to_string_lossy(), lineno, compile_id, payload)
} else {
Err(anyhow::anyhow!("Expected GraphDump metadata"))
}
}
}

// Same as SentinelFileParser, but can log the size of the graph
pub struct DynamoOutputGraphParser;
impl StructuredLogParser for DynamoOutputGraphParser {
Expand Down Expand Up @@ -272,6 +304,7 @@ pub fn default_parsers<'t>(tt: &'t TinyTemplate<'t>) -> Vec<Box<dyn StructuredLo
Box::new(SentinelFileParser::new("inductor_post_grad_graph", |e| {
e.inductor_post_grad_graph.as_ref()
})),
Box::new(GraphDumpParser),
Box::new(DynamoOutputGraphParser),
Box::new(DynamoGuardParser { tt }),
Box::new(InductorOutputCodeParser),
Expand Down
7 changes: 7 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ pub struct OptimizeDdpSplitChildMetadata {
#[derive(Debug, Deserialize)]
pub struct EmptyMetadata {}

#[derive(Debug, Deserialize)]
pub struct GraphDumpMetadata {
pub name: String,
}

#[derive(Debug, Deserialize)]
pub struct DynamoOutputGraphMetadata {
_sizes: Option<FxHashMap<String, Vec<SymInt>>>,
Expand Down Expand Up @@ -246,6 +251,7 @@ pub struct RestartsAndFailuresContext {
#[derive(Debug)]
pub enum Metadata<'e> {
Empty(&'e EmptyMetadata),
GraphDump(&'e GraphDumpMetadata),
DynamoOutputGraph(&'e DynamoOutputGraphMetadata),
#[allow(dead_code)]
DynamoStart(&'e DynamoStartMetadata),
Expand Down Expand Up @@ -275,6 +281,7 @@ pub struct Envelope {
pub inductor_post_grad_graph: Option<EmptyMetadata>,
pub inductor_output_code: Option<InductorOutputCodeMetadata>,
pub compilation_metrics: Option<CompilationMetricsMetadata>,
pub graph_dump: Option<GraphDumpMetadata>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down

0 comments on commit ab7353a

Please sign in to comment.