-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
[IR][Pass][Instrument] Pass instrument framework #7952
Conversation
This commit provides utilies to instrument passes: 1. Add a new namespace tvm.instrument 2. Introduce PassInstrument and PassInstrumentor to PassContext Example ------- passes_mem = #... Impl of memory instrument passes_time = tvm.instrument.PassesTimeInstrument() with tvm.transform.PassContext( pass_instrumentor=PassInstrumentor([passes_mem, passes_time])): tvm.relay.build(mod, 'llvm') passes_mem.rendor() passes_time.rendor() 3. Integrate existing PassContext::Trace() and timing profile
Thanks for the contribution @zackcquic. In order to avoid duplicating code it might be worth unifying this with the runtime profiling framework (available here https://github.com/apache/tvm/blob/main/include/tvm/runtime/profiling.h). I have a branch (which I haven't submitted yet) that allows users to extend which kinds of information are collected. You can view the branch here: https://github.com/tkonolige/incubator-tvm/tree/profiler_papi. With this branch, I think the profiler supports all the features you want. |
Thank you @zackcquic ! Looks like a good addition, do you mind also create an RFC discussion post? I agree it is important to have pass instrumentations, would be good to know how can it interact with Trace, since some of the callbacks might be similar and we need to unify the interface. On the design side, I think the runtime profiling and pass instrumentation might be different enough that might worth two separate solutions(perhaps a bit of reuse of timer if needed) As the former have more complexity wrt to GPU timer etc, while the later allows more statistics to be collected |
@tqchen @tkonolige Here is the RFC: And here is some reply for previous questions: I would like to separate runtime profiling and pass instrumentation, too. This PR only focuses on pass profiling mechanisms like the passes time profiling, wants to make it easier to add more passes profiling implementations. You might notice that this PR introduces a new namespace tvm.intrument. It intends to cover all instrument related (not limited to pass, but this PR only shows pass instrument), instead of mixing instrumentation/profiling code with transformation codes in tvm.transform. RuntimeProfiling could be add to this namespace, eg: tvm.instrument.Runtime.Profiling. |
I will try and comment over the weekend, thanks for the PR! |
The CI failed, because of the following message:
I think it may be not related to the change but the CI environment, right? And another thing is the workflow:
I think it may require someone to approve, right? |
Hi @jroesch: Just a gentle ping to receive feedback on this PR. Thanks, |
Sorry for the long delay. @zackcquic I have added review comments. One thing that would be helpful to get put more thoughts on is the naming. in particular what is the argument name when passing a list of pass instrumentors. cc @junrushao1994 @vinx13 @altanh @zhiics @yzhliu Please also help to take a look |
@tqchen Thanks a lot for review. |
@tqchen I just made modification based on comments. |
cc @jroesch @Hzfengsy @junrushao1994 @vinx13 @areusch @mbrookhart @yzhliu would be great if you can help to review this PR |
|
@tqchen requested changes updated |
thanks for the PR and sorry for delay, I'll review this today! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes, this looks much better now! Mostly spelling nits here, but also could you please add back the test for the PassTimingInstrument
? Looks like it got removed here (previously was in tests/python/relay/test_pass_profiler.py
).
I renamed |
Thanks, sorry I missed it (looks like github collapsed the file and I scrolled too fast...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the detailed survey of pass instrumentation APIs and all of the test cases, @zackcquic ! I just have a few more questions about things and otherwise I think it's looking great.
} catch (const Error& e) { | ||
LOG(INFO) << "Pass instrumentation entering pass context failed."; | ||
LOG(INFO) << "Disable pass instrumentation."; | ||
pass_ctx_node->instruments.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is where I'm suggesting you should call pi->ExitPassContext()
for all pi
whose EnterPassContext
has successfully returned so far.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and test case updated, thanks a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @zackcquic for working through this!
Hi @tqchen, Just a ping for reviewing :), thanks a lot. |
Thanks @zackcquic @areusch @tkonolige @altanh |
Thanks @zackcquic for putting all the hard work polishing the API, improving the code and bring the implementation. It would be great if we can followup to add design docs and examples :) |
Sure, I will add it. Thank you very much. |
* [IR][Pass][Instrument] Pass instrument framework This commit provides utilies to instrument passes: 1. Add a new namespace tvm.instrument 2. Introduce PassInstrument and PassInstrumentor to PassContext Example ------- passes_mem = #... Impl of memory instrument passes_time = tvm.instrument.PassesTimeInstrument() with tvm.transform.PassContext( pass_instrumentor=PassInstrumentor([passes_mem, passes_time])): tvm.relay.build(mod, 'llvm') passes_mem.rendor() passes_time.rendor() 3. Integrate existing PassContext::Trace() and timing profile * [IR][Pass][Instrument] Fix python test_pass_manager.py * Fix comment * Fix lint * Fix test_pass_annotation * Fix test_pass_annotation.py * Fix lint * Fix test_pass_annotation.py * Fix test_pass_annotation.py * Fix review comments * Fix tutorial use_pass_infra.py * Fix review comments * Fix review comments * Fix typo * Fix review comments * Fix review comments * Fix unittest error: test_cow_pass * Fix unittest error * Add more test cases for exceptions * Fix nit * Doc override_instruments() * Fix review comments * Fix lint * Fix EnterContext exception behavior
* [IR][Pass][Instrument] Pass instrument framework This commit provides utilies to instrument passes: 1. Add a new namespace tvm.instrument 2. Introduce PassInstrument and PassInstrumentor to PassContext Example ------- passes_mem = #... Impl of memory instrument passes_time = tvm.instrument.PassesTimeInstrument() with tvm.transform.PassContext( pass_instrumentor=PassInstrumentor([passes_mem, passes_time])): tvm.relay.build(mod, 'llvm') passes_mem.rendor() passes_time.rendor() 3. Integrate existing PassContext::Trace() and timing profile * [IR][Pass][Instrument] Fix python test_pass_manager.py * Fix comment * Fix lint * Fix test_pass_annotation * Fix test_pass_annotation.py * Fix lint * Fix test_pass_annotation.py * Fix test_pass_annotation.py * Fix review comments * Fix tutorial use_pass_infra.py * Fix review comments * Fix review comments * Fix typo * Fix review comments * Fix review comments * Fix unittest error: test_cow_pass * Fix unittest error * Add more test cases for exceptions * Fix nit * Doc override_instruments() * Fix review comments * Fix lint * Fix EnterContext exception behavior
This commit provides utilities to instrument passes:
Add a new namespace tvm.instrument
Introduce PassInstrument and PassInstrumentor to PassContext
Example
Thanks for contributing to TVM! Please refer to guideline https://tvm.apache.org/docs/contribute/ for useful information and tips. After the pull request is submitted, please request code reviews from Reviewers by @ them in the pull request thread.
Hi @altanh @tqchen:
I tried to integrate current passes profile mechanisms and make it more extendable, usage is as the commit's code example. Many parts are inspired by LLVM and MLIR.
How do you think?
This is my first attempt to TVM :), I have read through the guideline, but it there are stilling something wrong, please let me know.
Regards,
Zack