Skip to content

Fix VideoDecoder device argument to accept torch.device #607

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

Merged
merged 2 commits into from
Apr 2, 2025

Conversation

soheil-star01
Copy link
Contributor

Summary

This PR fixes an issue where passing a torch.device to the VideoDecoder constructor causes a type error when passed to the underlying C++ add_video_stream function, which expects a str.

Changes

  • Convert torch.device to str inside __init__ if necessary.

Why

Fixes bug #602: torch.device instances were not compatible with the expected C++ type (Optional[str]), causing decoding to fail.

Closes #602.

@facebook-github-bot
Copy link
Contributor

Hi @soheil-star01!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 29, 2025
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @soheil-star01 . Changes look good, before we merge could you please write a small non-regression test in https://github.com/pytorch/torchcodec/blob/main/test/decoders/test_decoders.py, to make sure that passing a torch.device() now works? Something as simple as this should be enough:

def test_device_instance(self):
	# Non-regression test for https://github.com/pytorch/torchcodec/issues/602	
	VideoDecoder(path, device=torch.device("cpu"))

@soheil-star01
Copy link
Contributor Author

Thank you for the PR @soheil-star01 . Changes look good, before we merge could you please write a small non-regression test in https://github.com/pytorch/torchcodec/blob/main/test/decoders/test_decoders.py, to make sure that passing a torch.device() now works? Something as simple as this should be enough:

def test_device_instance(self):
	# Non-regression test for https://github.com/pytorch/torchcodec/issues/602	
	VideoDecoder(path, device=torch.device("cpu"))

@NicolasHug Thank you. Done!

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @soheil-star01 !

@NicolasHug NicolasHug merged commit f4337de into pytorch:main Apr 2, 2025
46 checks passed
@NicolasHug NicolasHug added the bug Something isn't working label Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CLA Signed This label is managed by the Meta Open Source bot.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VideoDecoder API accepts device argument as str or torch.device, but underlying C++ API add_video_stream only takes in a str.
3 participants