Skip to content

Commit d59a511

Browse files
Add a null check for tracer in the Module::load_method (#6319)
Add a null check for `event_tracer` param in the `Module::load_method` (#6298) Summary: Pull Request resolved: #6298 When testing the [LLM Manual](https://pytorch.org/executorch/0.4/llm/getting-started.html#profiling-and-debugging), I found etdump is not generated :(. It seems to be a bug introduced in D62520386 when a `tracer` parameter was added to `Module::load_method`. It overrides the `event_tracer_.get()`, resulting `tracer` being null and passed to `program_->load_method`, thus etdump is not generated. This diff just adds a check: it `tracer` is not null, use it; otherwise use the tracer get from class member event_tracer_. Reviewed By: tarun292, Gasoonjia, dbort Differential Revision: D64481537 fbshipit-source-id: 86cecbaea2b7293be28d60f4147deb31535fa6ea (cherry picked from commit ad0e5e8) Co-authored-by: Olivia Liu <[email protected]>
1 parent da2cd5b commit d59a511

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

extension/module/module.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ runtime::Result<std::unordered_set<std::string>> Module::method_names() {
125125

126126
runtime::Error Module::load_method(
127127
const std::string& method_name,
128-
torch::executor::EventTracer* tracer) {
128+
torch::executor::EventTracer* event_tracer) {
129129
if (!is_method_loaded(method_name)) {
130130
ET_CHECK_OK_OR_RETURN_ERROR(load());
131131

@@ -153,7 +153,9 @@ runtime::Error Module::load_method(
153153
method_holder.planned_memory.get(),
154154
temp_allocator_.get());
155155
method_holder.method = ET_UNWRAP_UNIQUE(program_->load_method(
156-
method_name.c_str(), method_holder.memory_manager.get(), tracer));
156+
method_name.c_str(),
157+
method_holder.memory_manager.get(),
158+
event_tracer ? event_tracer : this->event_tracer()));
157159
method_holder.inputs.resize(method_holder.method->inputs_size());
158160
methods_.emplace(method_name, std::move(method_holder));
159161
}

extension/module/module.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ class Module {
133133
* needed. The loaded method is cached to reuse the next time it's executed.
134134
*
135135
* @param[in] method_name The name of the method to load.
136-
* @param[in] event_tracer A EventTracer used for tracking and logging events.
136+
* @param[in] event_tracer Per-method event tracer to profile/trace methods
137+
* individually. When not given, the event tracer passed to the Module
138+
* constructor is used. Otherwise, this per-method event tracer takes
139+
* precedence.
137140
*
138141
* @returns An Error to indicate success or failure.
139142
*/

0 commit comments

Comments
 (0)