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

[Op] Print #81

Merged
merged 3 commits into from
Mar 20, 2023
Merged

[Op] Print #81

merged 3 commits into from
Mar 20, 2023

Conversation

comaniac
Copy link
Contributor

Description

This PR introduces a utility op op.Print that prints intermediate results for traced modules. A unit test and tutorial are also provided.

Checklist

  • PR's title starts with a category (e.g. [Bugfix], [Model], [Tutorial], etc)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage
  • Code is well-documented

cc @chhzh123 @zarzen

@chhzh123
Copy link
Contributor

I'm actually thinking some non-intrusive ways to print the intermediate output. Otherwise, users still need to modify the model itself.

@chhzh123
Copy link
Contributor

For example, can we add a .print() primitive to do this? It should act like .annotate that only adds a hook or insert a module for printing the results.

tests/test_op.py Outdated
self.print = op.Print()

def forward(self, x):
out = self.lienar(x) + x
Copy link
Contributor

Choose a reason for hiding this comment

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

self.linear

@comaniac
Copy link
Contributor Author

For example, can we add a .print() primitive to do this? It should act like .annotate that only adds a hook or insert a module for printing the results.

This also creates some limitations. For example, you cannot print intermediate results inside a module but just its final output. We could maybe design a primitive only for traced GraphModule, but in this case users still have to use .find to identify the position for printing. We could think more on this mechanism and see if we could further improve it in the future.

@chhzh123
Copy link
Contributor

I can think of two ways for now:

  1. Attach print information to submodules and print out the results when executing these submodules, but this does not support arbitrary print point as you mentioned.
  2. Leverage fx.Interpreter. We can either print the output for each op, or provide an interface for users to determine which op's output should be print out.

Copy link
Contributor

@chhzh123 chhzh123 left a comment

Choose a reason for hiding this comment

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

@comaniac We can merge for now and improve this feature later.

@comaniac
Copy link
Contributor Author

Sure please go ahead and merge then.

@chhzh123
Copy link
Contributor

Thanks

@chhzh123 chhzh123 merged commit 3e46518 into awslabs:main Mar 20, 2023
@comaniac comaniac deleted the print_op branch March 20, 2023 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants