Skip to content

Add configurable event tracing names for method execution #8033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

cptspacemanspiff
Copy link
Contributor

@cptspacemanspiff cptspacemanspiff commented Jan 29, 2025

Summary

This is kind of a quality of life thing when working with exported modules with multiple methods.

The Issue:

By default, all methods of a module use the same profiling event and event block. This is fine, when one only has a single method exported, however the profiling data becomes less meaningful if there are multiple methods.

This is related to #8030 where I am exporting multiple methods on a single module and having them all share internal state.

The change:

In Method::execute, allow the caller to optionally pass in const char* block name and profiling event name.

Error execute(
      char const* block_name = "Method::execute",
      const char* profile_event_name = "Method::execute");

By default these are the same as what was hardcoded internally.

Additionally change the behavior of Module::execute to pass in the name of the current method.

  auto block_name = std::string("Execute::" + method_name);
  auto profile_event_name = std::string("Method::execute::" + method_name);

This does change the current behavior of Module, as anyone using that api will no longer get the previous hardcoded "Method::execute" names.

cc @JacobSzwejbka @dbort

- Updated Method::execute to accept optional block and profile event names
- Modified Module::execute to pass method-specific event names to method execution
Copy link

pytorch-bot bot commented Jan 29, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/8033

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 605d0f1 with merge base 3eea1f1 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 29, 2025
@manuelcandales manuelcandales added module: runtime Issues related to the core runtime and code under runtime/ module: extension Issues related to code under extension/ release notes: api Changes to public facing apis (any interfaces, pybinded runtime methods, etc.) triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Jan 29, 2025
@JacobSzwejbka
Copy link
Contributor

added @shoumikhin and @tarun292

Copy link
Contributor

@dbort dbort left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core runtime API already lets users pass a different EventTracer instance to each Method via Program::load_method(). I'd rather find some way to have the tracer instance record that a given trace is for a specific method, instead of modifying core runtime APIs.

The higher-level Module interface could construct a tracer for each method, and could pass the method name to each tracer instance.

@shoumikhin
Copy link
Contributor

@dbort is there any chance to log the method name for the event tracer in Method::execute(), e.g. for the event_tracer_entry?

@dbort
Copy link
Contributor

dbort commented Jan 30, 2025

is there any chance to log the method name for the event tracer in Method::execute(), e.g. for the event_tracer_entry?

Sure we could do something like that. The question is: what's the best way to log it? @tarun292 ? Would it make sense to update the EventTracer API to have a hook like begin_method(const char* name)? Or just stick it in a profiling event string?

The main pain is that if we want to construct a string with the method, like "Method(NAME)::execute" then we'd need to do so in a stack buffer like

char buf[32];
snprintf(buf, sizeof(buf), "Method(%s)::execute", method_name);

which would take some extra time, so we'd want to be sure to avoid it when no event tracer is installed, and possibly compile it out if profiling is disabled.

@cptspacemanspiff
Copy link
Contributor Author

So, looking back at this, I do not have a full understanding of the Event Tracer design / thought process.

For the use case of Executorch programs with multiple graphs/ methods is the thought process that one would generate an ET_Dump for each method independently? IE method_1.etdump method_2.etdump?

Or would this all get collapsed into a single etdump, with internal separation based on the block_name/ profile_name / (is there some other separation possibility?)

@dbort
Copy link
Contributor

dbort commented Feb 11, 2025

s the thought process that one would generate an ET_Dump for each method independently? IE method_1.etdump method_2.etdump?

I believe so; in fact I think it's typical to generate a separate dump for each execution of a given method. @tarun292 or @Gasoonjia would know better

@Gasoonjia
Copy link
Contributor

one would generate an ET_Dump for each method independently? IE method_1.etdump method_2.etdump

Correct. Each ETDump file corresponds to a method's inference; every time a method is executed, all debug/runtime related data will be stored in a single ETDump.

@cptspacemanspiff
Copy link
Contributor Author

cptspacemanspiff commented Feb 11, 2025

If my understanding is correct, the best way to handle this is to create and pass an independent event tracer instance for each method that gets called.

The way my current code works is that I end up adding an additional abstraction layer and wrapping the module class. This wrapping class calls load_method on all methods.

I guess additionally during this stage, my wrapper should (optionally) create and pass event tracers for each method, storing them for later write-out. (I am currently doing this for the root event tracer only)

This seems easy and if this is the recommended method, I can close out this as nothing in executorch needs to change. The only real downside is that I end up with multiple-files per program.

Side-note:

I have made some changes on the python side to etrecord generation/inspector, which are similar to this issue, but again the question is what is the recommended approach?

#8336

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. module: extension Issues related to code under extension/ module: runtime Issues related to the core runtime and code under runtime/ release notes: api Changes to public facing apis (any interfaces, pybinded runtime methods, etc.) triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants