Skip to content

Commit

Permalink
Add a null check for tracer in the Module::load_method (#6319)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
pytorchbot and Olivia-liu authored Oct 17, 2024
1 parent da2cd5b commit d59a511
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions extension/module/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ runtime::Result<std::unordered_set<std::string>> Module::method_names() {

runtime::Error Module::load_method(
const std::string& method_name,
torch::executor::EventTracer* tracer) {
torch::executor::EventTracer* event_tracer) {
if (!is_method_loaded(method_name)) {
ET_CHECK_OK_OR_RETURN_ERROR(load());

Expand Down Expand Up @@ -153,7 +153,9 @@ runtime::Error Module::load_method(
method_holder.planned_memory.get(),
temp_allocator_.get());
method_holder.method = ET_UNWRAP_UNIQUE(program_->load_method(
method_name.c_str(), method_holder.memory_manager.get(), tracer));
method_name.c_str(),
method_holder.memory_manager.get(),
event_tracer ? event_tracer : this->event_tracer()));
method_holder.inputs.resize(method_holder.method->inputs_size());
methods_.emplace(method_name, std::move(method_holder));
}
Expand Down
5 changes: 4 additions & 1 deletion extension/module/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ class Module {
* needed. The loaded method is cached to reuse the next time it's executed.
*
* @param[in] method_name The name of the method to load.
* @param[in] event_tracer A EventTracer used for tracking and logging events.
* @param[in] event_tracer Per-method event tracer to profile/trace methods
* individually. When not given, the event tracer passed to the Module
* constructor is used. Otherwise, this per-method event tracer takes
* precedence.
*
* @returns An Error to indicate success or failure.
*/
Expand Down

0 comments on commit d59a511

Please sign in to comment.