-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Lightweight at-most-once logging for API usage #20745
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
facebook-github-bot
left a comment
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.
@dzhulgakov has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
Is there a way to ensure that we continue not to trigger these trigger points via static initialization? Seems like something subtle that's easy to break. |
c10/util/Logging.cpp
Outdated
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.
TORCH_CHECK please :)
torch/csrc/Module.cpp
Outdated
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.
This looks uber slow lol
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.
it's called from python, so it should be ok :) I'm putting it only in construction of classes, so the impact should be minimal
ezyang
left a comment
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.
Implementation seems sound
|
Added a simple python test to ensure that we don't add accidentally some static initialization logging (it's a pretty hacky test but it works - also verified that it fails if such logging is actually added) |
facebook-github-bot
left a comment
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.
@dzhulgakov has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
4702df8 to
d155af7
Compare
facebook-github-bot
left a comment
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.
@dzhulgakov has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
e63fc5c to
9e81649
Compare
facebook-github-bot
left a comment
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.
@dzhulgakov has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
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.
@dzhulgakov has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: Resubmit #20698 which got messed up. Idea is that when PyTorch is used in a custom build environment (e.g. Facebook), it's useful to track usage of various APIs centrally. This PR introduces a simple very lightweight mechanism to do so - only first invocation of a trigger point would be logged. This is significantly more lightweight than #18235 and thus we can allow to put logging in e.g. TensorImpl. Also adds an initial list of trigger points. Trigger points are added in such a way that no static initialization triggers them, i.e. just linking with libtorch.so will not cause any logging. Further suggestions of what to log are welcomed. Pull Request resolved: pytorch/pytorch#20745 Differential Revision: D15429196 Pulled By: dzhulgakov fbshipit-source-id: a5e41a709a65b7ebccc6b95f93854e583cf20aca
|
@dzhulgakov merged this pull request in c25e337. |
|
ASAN started failing after this PR merged but I am not sure if this diff could have actually caused it: |
This reverts commit c25e337. gh-metadata: pytorch pytorch 20906 gh/ezyang/139/head
Resubmit #20698 which got messed up.
Idea is that when PyTorch is used in a custom build environment (e.g. Facebook), it's useful to track usage of various APIs centrally. This PR introduces a simple very lightweight mechanism to do so - only first invocation of a trigger point would be logged. This is significantly more lightweight than #18235 and thus we can allow to put logging in e.g. TensorImpl.
Also adds an initial list of trigger points. Trigger points are added in such a way that no static initialization triggers them, i.e. just linking with libtorch.so will not cause any logging. Further suggestions of what to log are welcomed.
Test plan:
Used PYTORCH_API_USAGE_STDERR=1 env with various scenarios, verified that logging is indeed triggered.
Given the only-once nature of logging, I'm not sure adding unittest would be that beneficial as it might be impact by how multiple unittests are linked together in one binary.
Added a tiny benchmark to verify overhead. Since we're talking about static variable only, it seems to be 0.3ns with warm cache (note it's 1000 invocations reported below). Didn't test with cold cache as it's pretty hard to capture such a small overhead: