pytorch / torchcodec

PyTorch video decoding
BSD 3-Clause "New" or "Revised" License
83 stars 9 forks source link

Add more cuda tests #326

Closed ahmadsharif1 closed 3 weeks ago

ahmadsharif1 commented 3 weeks ago

This addresses comments:

https://github.com/pytorch/torchcodec/pull/319#discussion_r1822348889 https://github.com/pytorch/torchcodec/pull/319#discussion_r1822353651

  1. Add a mark in conftest.py
  2. Add a decorator that passes in cpu and cuda devices
  3. Adds more tests for cuda, especially batch frame extraction tests
  4. Update the tensor_close function to be more tolerant of differences. The default is now 90% of the values should be within 20 of each other.

I was not able to reuse the logic in the needs_cuda() decorator so I just duplicated that logic. If someone has better ideas let me know and I can incorporate them.

ahmadsharif1 commented 3 weeks ago

Thanks. Actually I just realized that in doing all the test refactors I missed a very important check -- we don't actually check that the frame is on the correct device.

@NicolasHug do you have any opinions on how it should be done.

I think we can even have a function like test_frame_against_reference(frame1, frame2, expected_device)

Within that function we can 1) assert frame is on device and 2) use the correct comparison function -- i.e. approximately equal for cuda and exactly equal for CPU

Thoughts?

As far as more tests are concerned, you (or I) can address those later. But let's align on the overall testing flow for cuda tests including testing the device and tensor values both.