Skip to content
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

Merged
merged 25 commits into from
May 28, 2021
Merged

[IR][Pass][Instrument] Pass instrument framework #7952

merged 25 commits into from
May 28, 2021

Conversation

zackcquic
Copy link
Contributor

This commit provides utilities 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()
  1. Integrate existing PassContext::Trace() and timing profile

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

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
@tkonolige
Copy link
Contributor

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.

@tqchen
Copy link
Member

tqchen commented Apr 30, 2021

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

@zackcquic
Copy link
Contributor Author

@tqchen @tkonolige Here is the RFC:
https://discuss.tvm.apache.org/t/pass-instrument-framework-proposal/9874

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.

@jroesch jroesch self-assigned this May 1, 2021
@jroesch
Copy link
Member

jroesch commented May 1, 2021

I will try and comment over the weekend, thanks for the PR!

@zackcquic
Copy link
Contributor Author

zackcquic commented May 5, 2021

Hi @tqchen @jroesch

The CI failed, because of the following message:

docker: write /var/lib/docker/tmp/GetImageBlob707223609: no space left on device.

See 'docker run --help'.

script returned exit code 125

I think it may be not related to the change but the CI environment, right?

And another thing is the workflow:

1 workflow awaiting approval
First-time contributors need a maintainer to approve running workflows

I think it may require someone to approve, right?
Or I need to do something else?

@zackcquic
Copy link
Contributor Author

I will try and comment over the weekend, thanks for the PR!

Hi @jroesch:

Just a gentle ping to receive feedback on this PR.

Thanks,
Zack

python/tvm/ir/instrument.py Show resolved Hide resolved
include/tvm/ir/instrument.h Outdated Show resolved Hide resolved
include/tvm/ir/instrument.h Show resolved Hide resolved
include/tvm/ir/instrument.h Outdated Show resolved Hide resolved
python/tvm/ir/transform.py Outdated Show resolved Hide resolved
include/tvm/ir/instrument.h Outdated Show resolved Hide resolved
@tqchen
Copy link
Member

tqchen commented May 12, 2021

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

@zackcquic
Copy link
Contributor Author

zackcquic commented May 13, 2021

@tqchen Thanks a lot for review.

@zackcquic
Copy link
Contributor Author

@tqchen I just made modification based on comments.

include/tvm/ir/instrument.h Show resolved Hide resolved
@tqchen
Copy link
Member

tqchen commented May 17, 2021

cc @jroesch @Hzfengsy @junrushao1994 @vinx13 @areusch @mbrookhart @yzhliu would be great if you can help to review this PR

@zackcquic
Copy link
Contributor Author

cc @jroesch @Hzfengsy @junrushao1994 @vinx13 @areusch @mbrookhart @yzhliu would be great if you can help to review this PR

@zackcquic zackcquic closed this May 18, 2021
@zackcquic zackcquic reopened this May 18, 2021
@zackcquic
Copy link
Contributor Author

@tqchen requested changes updated

@altanh
Copy link
Contributor

altanh commented May 18, 2021

thanks for the PR and sorry for delay, I'll review this today!

@zackcquic zackcquic requested a review from areusch May 23, 2021 12:12
Copy link
Contributor

@altanh altanh left a 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).

include/tvm/ir/transform.h Outdated Show resolved Hide resolved
include/tvm/ir/transform.h Outdated Show resolved Hide resolved
include/tvm/ir/transform.h Outdated Show resolved Hide resolved
include/tvm/ir/transform.h Outdated Show resolved Hide resolved
include/tvm/ir/transform.h Outdated Show resolved Hide resolved
include/tvm/ir/transform.h Outdated Show resolved Hide resolved
include/tvm/ir/transform.h Outdated Show resolved Hide resolved
python/tvm/ir/transform.py Show resolved Hide resolved
tests/python/relay/test_pass_manager.py Show resolved Hide resolved
@zackcquic
Copy link
Contributor Author

zackcquic commented May 25, 2021

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 test_pass_profiler.py to test_pass_instrument.py, and PassTimingInstrument are tested in this file.

@altanh
Copy link
Contributor

altanh commented May 25, 2021

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 test_pass_profiler.py to test_pass_instrument.py, and PassTimingInstrument are tested in this file.

Thanks, sorry I missed it (looks like github collapsed the file and I scrolled too fast...)

Copy link
Contributor

@areusch areusch left a 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.

tests/python/relay/test_pass_instrument.py Outdated Show resolved Hide resolved
tests/python/relay/test_pass_instrument.py Outdated Show resolved Hide resolved
tests/python/relay/test_pass_instrument.py Outdated Show resolved Hide resolved
src/ir/transform.cc Outdated Show resolved Hide resolved
@zackcquic zackcquic requested a review from areusch May 25, 2021 17:48
} catch (const Error& e) {
LOG(INFO) << "Pass instrumentation entering pass context failed.";
LOG(INFO) << "Disable pass instrumentation.";
pass_ctx_node->instruments.clear();
Copy link
Contributor

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.

Copy link
Contributor Author

@zackcquic zackcquic May 26, 2021

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.

@zackcquic zackcquic requested a review from areusch May 26, 2021 22:49
@zackcquic
Copy link
Contributor Author

@areusch @tqchen change request are all done.
Thanks a lot for reviewing efforts. 👍

Copy link
Contributor

@areusch areusch left a 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!

@zackcquic
Copy link
Contributor Author

Hi @tqchen,

Just a ping for reviewing :), thanks a lot.

@tqchen tqchen merged commit ece644c into apache:main May 28, 2021
@tqchen
Copy link
Member

tqchen commented May 28, 2021

Thanks @zackcquic @areusch @tkonolige @altanh

@tqchen
Copy link
Member

tqchen commented May 28, 2021

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 :)

@zackcquic
Copy link
Contributor Author

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.

@zackcquic zackcquic deleted the dev branch May 29, 2021 03:17
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Jun 17, 2021
* [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
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Jun 17, 2021
* [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants