From 88c3dcad0c735178084ca37272b15130f82769b2 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 11 Jul 2024 15:10:02 -0400 Subject: [PATCH] Update [ghstack-poisoned] --- src/lib.rs | 4 ++++ src/parsers.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/templates.rs | 28 ++++++++++++++++++++++++++++ src/types.rs | 17 +++++++++++++++++ 4 files changed, 88 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 83f7520..d05b966 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -188,6 +188,10 @@ pub fn parse_path(path: &PathBuf, config: ParseConfig) -> anyhow::Result { } } +pub struct BwdCompilationMetricsParser<'t> { + tt: &'t TinyTemplate<'t>, +} +impl StructuredLogParser for BwdCompilationMetricsParser<'_> { + fn name(&self) -> &'static str { + "bwd_compilation_metrics" + } + fn get_metadata<'e>(&self, e: &'e Envelope) -> Option> { + e.bwd_compilation_metrics + .as_ref() + .map(|m| Metadata::BwdCompilationMetrics(m)) + } + fn parse<'e>( + &self, + lineno: usize, + metrics: Metadata<'e>, + _rank: Option, + compile_id: &Option, + _payload: &str, + ) -> anyhow::Result { + let filename = format!("{}.html", self.name()); + if let Metadata::BwdCompilationMetrics(m) = metrics { + let id = compile_id + .clone() + .map_or("(unknown) ".to_string(), |c| format!("{cid} ", cid = c)); + let context = BwdCompilationMetricsContext { + css: crate::CSS, + m: &m, + compile_id: id, + }; + let output = self.tt.render(&filename, &context)?; + simple_file_output(&filename, lineno, compile_id, &output) + } else { + Err(anyhow::anyhow!("Expected BwdCompilationMetrics metadata")) + } + } +} + pub struct ArtifactParser; impl StructuredLogParser for ArtifactParser { fn name(&self) -> &'static str { @@ -506,6 +544,7 @@ pub fn default_parsers<'t>(tt: &'t TinyTemplate<'t>) -> Vec "#; + +pub static TEMPLATE_BWD_COMPILATION_METRICS: &str = r#" + + + + Backward Compilation Metrics + + +

Backward Compilation Info for {compile_id}

+

Compile Time(seconds)

+ {{ if m.inductor_compile_time_s }} +

Inductor [?]: {m.inductor_compile_time_s} + {{ endif }} + {{ if m.code_gen_time_s }} +

Code Gen Time: {m.code_gen_time_s}

+ {{ endif}} +

Failures

+ {{ if m.fail_type }} +

Failure Exception:

{m.fail_type}

+

Failure Reason:

{m.fail_reason}

+ {{ else }} +

No failures!

+ {{ endif }} + + +"#; diff --git a/src/types.rs b/src/types.rs index eb9bdc8..2d1bb3d 100644 --- a/src/types.rs +++ b/src/types.rs @@ -277,6 +277,14 @@ pub struct CompilationMetricsMetadata { pub dynamo_time_before_restart_s: Option, } +#[derive(Debug, Deserialize, Serialize, Clone)] +pub struct BwdCompilationMetricsMetadata { + pub inductor_compile_time_s: Option, + pub code_gen_time_s: Option, + pub fail_type: Option, + pub fail_reason: Option, +} + #[derive(Debug, Deserialize, Serialize)] pub struct AOTAutogradBackwardCompilationMetricsMetadata { pub start_time: Option, @@ -295,6 +303,13 @@ pub struct SymbolicShapeSpecializationMetadata { pub user_stack: Option, } +#[derive(Debug, Serialize)] +pub struct BwdCompilationMetricsContext<'e> { + pub m: &'e BwdCompilationMetricsMetadata, + pub css: &'static str, + pub compile_id: String, +} + #[derive(Debug, Serialize)] pub struct AOTAutogradBackwardCompilationMetricsContext<'e> { pub m: &'e AOTAutogradBackwardCompilationMetricsMetadata, @@ -364,6 +379,7 @@ pub enum Metadata<'e> { OptimizeDdpSplitChild(&'e OptimizeDdpSplitChildMetadata), CompilationMetrics(&'e CompilationMetricsMetadata), AOTAutogradBackwardCompilationMetrics(&'e AOTAutogradBackwardCompilationMetricsMetadata), + BwdCompilationMetrics(&'e BwdCompilationMetricsMetadata), Artifact(&'e ArtifactMetadata), } @@ -390,6 +406,7 @@ pub struct Envelope { pub dynamo_cpp_guards_str: Option, pub inductor_output_code: Option, pub compilation_metrics: Option, + pub bwd_compilation_metrics: Option, pub aot_autograd_backward_compilation_metrics: Option, pub graph_dump: Option,