Skip to content

Commit f23d2b7

Browse files
Olivia-liufacebook-github-bot
authored andcommitted
Add a null check for tracer in the Module::load_method (#6298)
Summary: 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
1 parent 0a8e007 commit f23d2b7

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

extension/module/module.cpp

Lines changed: 3 additions & 3 deletions
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

@@ -151,9 +151,9 @@ runtime::Error Module::load_method(
151151
method_holder.memory_manager = std::make_unique<runtime::MemoryManager>(
152152
memory_allocator_.get(),
153153
method_holder.planned_memory.get(),
154-
temp_allocator_.get());
154+
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(), method_holder.memory_manager.get(), event_tracer ? event_tracer : this->event_tracer()));
157157
method_holder.inputs.resize(method_holder.method->inputs_size());
158158
methods_.emplace(method_name, std::move(method_holder));
159159
}

extension/module/module.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ 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 precedence.
137139
*
138140
* @returns An Error to indicate success or failure.
139141
*/

0 commit comments

Comments
 (0)