- 
                Notifications
    
You must be signed in to change notification settings  - Fork 712
 
[devtool] introduce datasink class to etdump #8496
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
[devtool] introduce datasink class to etdump #8496
Conversation
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]
          
🔗 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 FailuresAs of commit f2fbce9 with merge base 728c255 ( This comment was automatically generated by Dr. CI and updates every 15 minutes.  | 
    
| 
           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-source-id: 266441637 Pull Request resolved: #8496
| 
           @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]
| 
           This pull request was exported from Phabricator. Differential Revision: D69583422  | 
    
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
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 think that the API should change to take a simple Span<uint8_t> instead of a Tensor; see my comments for details.
        
          
                devtools/etdump/data_sink.cpp
              
                Outdated
          
        
      | ET_CHECK_MSG( | ||
| offset_ <= debug_buffer_.size(), | ||
| "Ran out of space to store tensor data."); | 
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.
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.
        
          
                devtools/etdump/data_sink.cpp
              
                Outdated
          
        
      | } | ||
| uint8_t* offset_ptr = | ||
| internal::alignPointer(debug_buffer_.data() + offset_, 64); | ||
| offset_ = (offset_ptr - debug_buffer_.data()) + tensor.nbytes(); | 
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.
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]
| 
           This pull request was exported from Phabricator. Differential Revision: D69583422  | 
    
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]
| 
           This pull request was exported from Phabricator. Differential Revision: D69583422  | 
    
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]
| 
           This pull request was exported from Phabricator. Differential Revision: D69583422  | 
    
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]
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/)
| 
           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]
| 
           This pull request was exported from Phabricator. Differential Revision: D69583422  | 
    
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/)
| 
           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]
| 
           This pull request was exported from Phabricator. Differential Revision: D69583422  | 
    
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/)
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.
Thanks for renaming the subclass
| if (length == 0) { | ||
| return static_cast<size_t>(-1); | ||
| } | 
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.
From an earlier comment:
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.
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.
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.
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.
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.
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.
        
          
                devtools/etdump/data_sink_base.h
              
                Outdated
          
        
      | size_t length) = 0; | ||
| /** | ||
| * Get the maximum capacity of the debug storage in bytes. | ||
| * Should return Error::NotSupported if the capacity is not available | 
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.
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.
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 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.
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 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]
| 
           This pull request was exported from Phabricator. Differential Revision: D69583422  | 
    
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/)
| if (length == 0) { | ||
| return static_cast<size_t>(-1); | ||
| } | 
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.
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.
        
          
                devtools/etdump/buffer_data_sink.h
              
                Outdated
          
        
      | * stored. | ||
| */ | ||
| explicit BufferDataSink(::executorch::runtime::Span<uint8_t> buffer) | ||
| : debug_buffer_(buffer), offset_(0), alighment_(64) {} | 
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.
Typo
| : debug_buffer_(buffer), offset_(0), alighment_(64) {} | |
| : debug_buffer_(buffer), offset_(0), alignment_(64) {} | 
        
          
                devtools/etdump/buffer_data_sink.h
              
                Outdated
          
        
      | explicit BufferDataSink(::executorch::runtime::Span<uint8_t> buffer) | ||
| : debug_buffer_(buffer), offset_(0), alighment_(64) {} | 
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.
May as well add an alignment param. And please document that it must be a power of 2
| 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) {} | 
        
          
                devtools/etdump/data_sink_base.h
              
                Outdated
          
        
      | size_t length) = 0; | ||
| /** | ||
| * Get the maximum capacity of the debug storage in bytes. | ||
| * Should return Error::NotSupported if the capacity is not available | 
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 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]
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/)
| 
           This pull request was exported from Phabricator. Differential Revision: D69583422  | 
    
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.
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]
| 
           This pull request was exported from Phabricator. Differential Revision: D69583422  | 
    
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]
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/)
| 
           This pull request was exported from Phabricator. Differential Revision: D69583422  | 
    
de29a09
      into
      
  
    gh/gasoonjia/1/base
  
    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]>
Stack from ghstack (oldest at bottom):
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