candle icon indicating copy to clipboard operation
candle copied to clipboard

How to get raw tensor data?

Open WenheLI opened this issue 1 year ago • 2 comments

I am trying to implement an adaptive avg pool in candle. However, I guess my implementation will require an API to get the raw data/storage (storaged in plain/flatten array format). Wondering if there is such an API for that?

Thanks!

WenheLI avatar Jun 28 '24 19:06 WenheLI

Yes! The Candle CustomOp API allows this: https://docs.rs/candle-core/latest/candle_core/trait.CustomOp1.html

On the CPU, the storage is: https://docs.rs/candle-core/latest/candle_core/cpu_backend/enum.CpuStorage.html

EricLBuehler avatar Jun 28 '24 19:06 EricLBuehler

Thanks for the quick response! I did an initial implementation on CPU backend https://github.com/huggingface/candle/pull/2296 Let me know if this looks good and I can extend this to other backends.

WenheLI avatar Jun 28 '24 21:06 WenheLI