Skip to content

Conversation

@Gasoonjia
Copy link
Contributor

@Gasoonjia Gasoonjia commented Feb 14, 2025

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Feb 14, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/8496

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit f2fbce9 with merge base 728c255 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 14, 2025
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

Gasoonjia added a commit that referenced this pull request Feb 14, 2025
this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

ghstack-source-id: 266441637
Pull Request resolved: #8496
@Gasoonjia
Copy link
Contributor Author

@pytorchbot label "topic: not user facing"

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

Gasoonjia added a commit that referenced this pull request Feb 14, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)
ghstack-source-id: 266455279
Copy link
Contributor

@dbort dbort left a comment

Choose a reason for hiding this comment

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

I think that the API should change to take a simple Span<uint8_t> instead of a Tensor; see my comments for details.

Comment on lines 16 to 18
ET_CHECK_MSG(
offset_ <= debug_buffer_.size(),
"Ran out of space to store tensor data.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do not use ET_CHECK/ET_CHECK_MSG, which kills the entire process when it fails. This method should return Result<size_t> so that it can fail non-fatally when there's a problem.

}
uint8_t* offset_ptr =
internal::alignPointer(debug_buffer_.data() + offset_, 64);
offset_ = (offset_ptr - debug_buffer_.data()) + tensor.nbytes();
Copy link
Contributor

Choose a reason for hiding this comment

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

When bumping the offset forward, I strongly suggest zeroing out the memory in the padding. If you don't do that, and this buffer is written to a file, then that file may contain random data from the process.

a) this makes the file contents non-deterministic, and b) it could inadvertently write user data or secrets into the file if they had been stored in the heap and then freed before being used for this buffer.

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

Gasoonjia added a commit that referenced this pull request Feb 14, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0
ghstack-source-id: 266594898

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)
this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

Gasoonjia added a commit that referenced this pull request Feb 15, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0
ghstack-source-id: 266628126

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)
this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

Gasoonjia added a commit that referenced this pull request Feb 15, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0
ghstack-source-id: 266630225

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)
this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
Gasoonjia added a commit that referenced this pull request Feb 15, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0
ghstack-source-id: 266631718

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

Gasoonjia added a commit that referenced this pull request Feb 17, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0
ghstack-source-id: 266867606

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)
@tarun292
Copy link
Contributor

Looks great to me overall and i think most of @dbort's comments are addressed now. Will let him take a final look and stamp.

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

Gasoonjia added a commit that referenced this pull request Feb 18, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0
ghstack-source-id: 267007242

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)
Copy link
Contributor

@dbort dbort 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 renaming the subclass

Comment on lines 19 to 21
if (length == 0) {
return static_cast<size_t>(-1);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

From an earlier comment:

@dbort:

size_t is unsigned, so -1 will look like a very large positive number: 18 exabytes on a 64-bit machine. If this is part of the contract, please document it in the base class. But I'd recommend just returning offset_ in this case since it's a zero-sized buffer and the offset doesn't matter.

@Gasoonjia:

let me create another diff for solving that; this function copy&paste from copy_tensor_to_debug_buffer function in ETDumpGen; updating the returning data here may introduce BP issue

What is "BP"? A behavior change in this new function will not affect anyone, because it is not used yet. If some future caller needs this (size_t)-1 behavior for some reason, then they can deal with that themselves: they know when they're writing zero bytes. I'd prefer not to land potentially-dangerous logic like this, because it might never be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sry that's a typo. I wanted to type "BC", which refers to "Backward-Compatibility" issue.

This is not a new function. It has existed in the ETDumpGen class (https://github.com/pytorch/executorch/blob/main/devtools/etdump/etdump_flatcc.cpp#L511) for writing tensors into user-owned buffer, and our buffer_data_sink extracted that part of logic into our class for maintaining the current behavior.

Therefore, I would like to reproduce the existing logic first. I know it is not good enough. Will work on it in the following diffs.

Copy link
Contributor

Choose a reason for hiding this comment

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

But this is a new function that no-one uses yet. If ETDumpGen::copy_tensor_to_debug_buffer() calls this, then you can isolate the old behavior there, like

size_t ETDumpGen::copy_tensor_to_debug_buffer(executorch::aten::Tensor tensor) {
  // (comment explaining this special case)
  if (tensor.nbytes() == 0) {
    return static_cast<size_t>(-1);
  }
  return data_sink_->write(tensor.const_data_ptr(), tensor.nbytes());
}

This way, the new method can behave properly from the start, and other users/subclasses of DataSinkBase don't need to duplicate the old behavior.

size_t length) = 0;
/**
* Get the maximum capacity of the debug storage in bytes.
* Should return Error::NotSupported if the capacity is not available
Copy link
Contributor

Choose a reason for hiding this comment

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

If this might return NotSupported, then users of the base class can't depend on it. Ideally, base classes should only contain methods that all subclasses will be able to implement.

I recommend removing this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree but some of users need to get the size of debug buffer from ETDumpGen (https://github.com/pytorch/executorch/blob/main/devtools/etdump/etdump_flatcc.cpp#L646). Under current datasink scenerio, we need to have a way for retreiving the size of every datasink.

Copy link
Contributor

Choose a reason for hiding this comment

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

I only see one use of get_debug_buffer_size today, at https://fburl.com/code/3od7ch5t; and that is a bad use of the API. We should talk to them and see if they can do it in a different way, removing the only usage of this method.

we need to have a way for retreiving the size of every datasink

This just isn't possible for all datasinks. If the old ETDump interface needs to support it for now, then we can find a way to isolate that knowledge in the ETDump code, instead of requiring all DataSinks to follow the old pattern.

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

Gasoonjia added a commit that referenced this pull request Feb 20, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0
ghstack-source-id: 267495369

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)
Comment on lines 19 to 21
if (length == 0) {
return static_cast<size_t>(-1);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

But this is a new function that no-one uses yet. If ETDumpGen::copy_tensor_to_debug_buffer() calls this, then you can isolate the old behavior there, like

size_t ETDumpGen::copy_tensor_to_debug_buffer(executorch::aten::Tensor tensor) {
  // (comment explaining this special case)
  if (tensor.nbytes() == 0) {
    return static_cast<size_t>(-1);
  }
  return data_sink_->write(tensor.const_data_ptr(), tensor.nbytes());
}

This way, the new method can behave properly from the start, and other users/subclasses of DataSinkBase don't need to duplicate the old behavior.

* stored.
*/
explicit BufferDataSink(::executorch::runtime::Span<uint8_t> buffer)
: debug_buffer_(buffer), offset_(0), alighment_(64) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo

Suggested change
: debug_buffer_(buffer), offset_(0), alighment_(64) {}
: debug_buffer_(buffer), offset_(0), alignment_(64) {}

Comment on lines 33 to 34
explicit BufferDataSink(::executorch::runtime::Span<uint8_t> buffer)
: debug_buffer_(buffer), offset_(0), alighment_(64) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

May as well add an alignment param. And please document that it must be a power of 2

Suggested change
explicit BufferDataSink(::executorch::runtime::Span<uint8_t> buffer)
: debug_buffer_(buffer), offset_(0), alighment_(64) {}
explicit BufferDataSink(::executorch::runtime::Span<uint8_t> buffer, size_t alignment = 64)
: debug_buffer_(buffer), offset_(0), alignment_(alignment) {}

size_t length) = 0;
/**
* Get the maximum capacity of the debug storage in bytes.
* Should return Error::NotSupported if the capacity is not available
Copy link
Contributor

Choose a reason for hiding this comment

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

I only see one use of get_debug_buffer_size today, at https://fburl.com/code/3od7ch5t; and that is a bad use of the API. We should talk to them and see if they can do it in a different way, removing the only usage of this method.

we need to have a way for retreiving the size of every datasink

This just isn't possible for all datasinks. If the old ETDump interface needs to support it for now, then we can find a way to isolate that knowledge in the ETDump code, instead of requiring all DataSinks to follow the old pattern.

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
Gasoonjia added a commit that referenced this pull request Feb 24, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0
ghstack-source-id: 268108451

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

Copy link
Contributor

@dbort dbort left a comment

Choose a reason for hiding this comment

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

Thank you for all of these changes! A couple minor requests, but this looks great.

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

Gasoonjia added a commit that referenced this pull request Feb 24, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0
ghstack-source-id: 268121454

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)
this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

[ghstack-poisoned]
Gasoonjia added a commit that referenced this pull request Feb 25, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0
ghstack-source-id: 268137338

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D69583422

@facebook-github-bot facebook-github-bot merged commit de29a09 into gh/gasoonjia/1/base Feb 25, 2025
48 of 50 checks passed
@facebook-github-bot facebook-github-bot deleted the gh/gasoonjia/1/head branch February 25, 2025 07:53
swolchok added a commit that referenced this pull request Feb 25, 2025
Pull Request resolved: #8496

this diff introduce datasink class, the class for managing the customized debug data storage pipeline.

Detials can be found in https://docs.google.com/document/d/1y_m32mKdj-OgLcLUz9TKhBW3PC3bBDYSBbeAH544EfM/edit?tab=t.0
ghstack-source-id: 268137338

Differential Revision: [D69583422](https://our.internmc.facebook.com/intern/diff/D69583422/)

Co-authored-by: gasoonjia <[email protected]>
Co-authored-by: Scott Wolchok <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported topic: not user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants