candle
candle copied to clipboard
Is there a way to print tensor while debugging?
I need to see tensor values and shape.
Hardcoding println is inconvenient.
This seems to be less convenient than python.
I wonder if there is a better way.
Perhaps you can comment to #1279? I have noticed that there appears no way to modify or access specific elements.
I think what you are refering to are debugger visualizers, which allow to customize how the WinDbg or GDB / LLDB debuggers display certain structs.
This would allow us to customize the developer experience and e.g. display the values, type and shape of a tensor easily in the debugger.
Currently, there is no API to get the data of an n-dimensional tensor.
Currently, there is no API to get the data of a tensor.
What do you mean by this? The to_vecX() methods are here to retrieve the data from a tensor.
For the original question, we currently implement the Display trait to print a tensor in the same way pytorch would. We also have the Debug trait that provides a concise description with only the shape/element type.
Not sure what the debugger is using but it might be as simple as tweaking one of these traits or implementing a new one, I guess it depends on how the debugger is extracting the data so might be debugger dependent.
For the original question, we currently implement the
Displaytrait to print a tensor in the same way pytorch would. We also have theDebugtrait that provides a concise description with only the shape/element type. Not sure what the debugger is using but it might be as simple as tweaking one of these traits or implementing a new one, I guess it depends on how the debugger is extracting the data so might be debugger dependent.
I think the problem here is, that CodeLLDB (at least on windows) wont use the Debug or Display trait correctly and displays the "raw" tensor, which can be a bit hard to reason about if you don't know the internal structure.
https://github.com/huggingface/candle/assets/65088241/7433878d-9b94-422a-a0ce-9790ac554899
But it should be relatively easy to implement some debugger visualizers as we already have working Debug and Display traits.
What do you mean by this? The to_vecX() methods are here to retrieve the data from a tensor.
@LaurentMazare, sorry for the lack of clarity - I meant there is no way (to my knowledge) to get n-dimensional data out of a tensor without checking the rank. As another question: is there an API to modify tensor elements already - perhaps to return an &mut Vec<...>?
I think the problem here is, that CodeLLDB (at least on windows) wont use the
DebugorDisplaytrait correctly and displays the "raw" tensor, which can be a bit hard to reason about if you don't know the internal structure.
Sorry I'm a bit lazy here and haven't google but would you know if codelldb/... provide some hooks that let you customize the printing of arbitrary data structures. I imagine that it's likely to be the case.
Sorry I'm a bit lazy here and haven't google but would you know if codelldb/... provide some hooks that let you customize the printing of arbitrary data structures. I imagine that it's likely to be the case.
I believe this should do the trick: https://rust-lang.github.io/rfcs/3191-debugger-visualizer.html#supporting-pretty-printers
Took a stab at this in https://github.com/huggingface/candle/pull/1836