-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[PyTorch TB] Write raw tensor as tensor_proto #104908
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
This is the first diff to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- ghstack-source-id: 194155757 Differential Revision: [D47302017](https://our.internmc.facebook.com/intern/diff/D47302017/) [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/104908
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New FailuresAs of commit 88e722f: NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
torch/utils/tensorboard/summary.py
Outdated
], | ||
proto_val_field: torch.view_as_real(tensor).tolist() | ||
if proto_val_field == "scomplex_val" or proto_val_field == "dcomplex_val" | ||
else tensor.reshape(-1).tolist(), |
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 a bit more idiomatic and modern might be .flatten()
instead of reshape(-1)
also, the two branches are currently not equivalent. if multidim tensors can be accepted here, the view_as_real(...).tolist() can produce nested lists
Also beware that tensor.reshape(-1).tolist() can produce python scalar instead of the list for numel() == 1 inputs: #52262 - my proposal for that one is to introduce a tolist(force = True)
which would always return a list, even for scalars (so .numel() == 1 and .numel() == 0 probably should be checked)
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.
Updated, thanks!
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.
Added checks for numel() == 1
and numel() == 0
This is the first diff to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- Differential Revision: [D47302017](https://our.internmc.facebook.com/intern/diff/D47302017/) [ghstack-poisoned]
This is the first diff to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- Differential Revision: [D47302017](https://our.internmc.facebook.com/intern/diff/D47302017/) [ghstack-poisoned]
This is the first diff to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- Differential Revision: [D47302017](https://our.internmc.facebook.com/intern/diff/D47302017/) [ghstack-poisoned]
This is the first diff to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- Differential Revision: [D47302017](https://our.internmc.facebook.com/intern/diff/D47302017/) [ghstack-poisoned]
This is the first diff to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- Differential Revision: [D47302017](https://our.internmc.facebook.com/intern/diff/D47302017/) [ghstack-poisoned]
Pull Request resolved: #104908 This diff applies changes to open-source PyTorch to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- ghstack-source-id: 194300671 ghstack-source-id: 194300671 Differential Revision: [D47357048](https://our.internmc.facebook.com/intern/diff/D47357048/)
This is the first diff to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- Differential Revision: [D47302017](https://our.internmc.facebook.com/intern/diff/D47302017/) [ghstack-poisoned]
This is the first diff to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- Differential Revision: [D47302017](https://our.internmc.facebook.com/intern/diff/D47302017/) [ghstack-poisoned]
This is the first diff to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- Differential Revision: [D47302017](https://our.internmc.facebook.com/intern/diff/D47302017/) [ghstack-poisoned]
This is the first diff to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- Differential Revision: [D47302017](https://our.internmc.facebook.com/intern/diff/D47302017/) [ghstack-poisoned]
torch/utils/tensorboard/summary.py
Outdated
) | ||
|
||
# type maps: torch.Tensor type -> (protobuf type, protobuf val field) | ||
type_map = { |
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.
make this a private constant map outside the function? _TENSOR_TYPE_MAP = ... or something?
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.
Makes sense, applied changes.
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.
Generally looks good to me, thanks for adding tests! some nits inline
torch/utils/tensorboard/summary.py
Outdated
|
||
if tensor.dtype in type_map: | ||
proto_val_field = type_map[tensor.dtype][1] | ||
proto_val_contents = ( |
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.
For readability, I'd still this make this explicit
proto_val_contents = []
if proto_val_field == ...:
proto_val_contents = ...
elif tensor.numel() == 1
proto_val_contents = ...
and so on
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.
I see what you mean. Made changes.
This is the first diff to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- Differential Revision: [D47302017](https://our.internmc.facebook.com/intern/diff/D47302017/) [ghstack-poisoned]
Pull Request resolved: #104908 This diff applies changes to open-source PyTorch to support logging of raw tensors for [TensorBoard Intermediate Logging](https://www.internalfb.com/intern/wiki/TensorBoard/Intermediate_Logging/) Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor. 1. add `tensor_proto()` to `summary.py` which takes a tensor and convert to protobuf 2. add `add_tensor()` to `writer.py` 3. formatting changes introduced by `arc lint` ------------- ghstack-source-id: 194385501 ghstack-source-id: 194385501 Differential Revision: [D47357048](https://our.internmc.facebook.com/intern/diff/D47357048/)
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
@pytorchbot revert -c ignoredsignal -m "broke win-vs2019-cpu-py3 and macos-12-py3-arm64 " |
@pytorchbot successfully started a revert job. Check the current status here. |
Can't revert PR that was landed via phabricator as D47302017. Please revert by going to the internal diff and clicking Unland. |
@pytorchbot revert -m="Diff reverted internally" -c="ghfirst" This Pull Request has been reverted by a revert inside Meta. To re-land this change, please open another pull request, assign the same reviewers, fix the CI failures that caused the revert and make sure that the failing CI runs on the PR by applying the proper ciflow label (e.g., ciflow/trunk).) |
@pytorchbot successfully started a revert job. Check the current status here. |
@sethlee0111 your PR has been successfully reverted. |
This reverts commit dceae41. Reverted #104908 on behalf of https://github.com/facebook-github-bot due to Diff reverted internally ([comment](#104908 (comment)))
Stack from ghstack (oldest at bottom):
This is the first diff to support logging of raw tensors for TensorBoard Intermediate Logging
Ultimately, we aim to support the feature where store full tensor is stored as a tensor protobuf to TB. Protobuf contains shape, dtype, and elements of the given tensor.
tensor_proto()
tosummary.py
which takes a tensor and convert to protobufadd_tensor()
towriter.py
arc lint
Differential Revision: D47302017