dfdx icon indicating copy to clipboard operation
dfdx copied to clipboard

Tensor `Display` Implementation?

Open zicklag opened this issue 2 years ago • 4 comments

Hey there! I'm a fairly new to machine learning, but I'm wanting to use dydx instead of PyTorch as I go through pieces of the d2l course.

One thing I feel would be nice to have is a display implementation for tensors that would print out the tensors in a way similar to the display from PyTorch or TensorFlow.

This may exist already and I just haven't found it, but both of the debug representations are extremely wordy and include implementation details that aren't helpful when just wanting to visualize a tensor.

If you're open to this and I stick with using dydx, I might find time to implement it.

zicklag avatar May 17 '23 22:05 zicklag

Great idea, I love it! I think we could also implement display better for devices, which is semi-related to this.

Would be happy to help push forward any contributions related to this. You'd probably want to do something like:

  1. Convert the data to a Vec<E> using self.as_vec()
  2. Use self.strides to index in for the given amount of values you want to print out

I think pytorch prints out the first N and last N if the tensor is too big. We'd have to figure out what the limit is to print out the whole array.

chelsea0x3b avatar May 18 '23 12:05 chelsea0x3b

Cool, I'm hoping to continue finding some time trying out dydx, and if so I'll work on the Display implementation probably for both Tensor and Device.

I'm really impressed with the ergonomics and elegance of the API so far, great work!

zicklag avatar May 19 '23 02:05 zicklag

Thanks! And ideas/contributions like this will only help 😁

chelsea0x3b avatar May 19 '23 14:05 chelsea0x3b

FWIW you can get a pretty good string by using .array(), e.g. println("{#?}", my_tensor.array()). The array will have the same structure as the tensor (it's not a 1D array).

Also, the project is dfdx, not dydx!

emchristiansen avatar Jul 27 '23 18:07 emchristiansen