Skip to content

Commit 8d0cf06

Browse files
committed
Revert "Suport device=None (meta-pytorch#1025)"
This reverts commit b597922.
1 parent 289ff5d commit 8d0cf06

File tree

2 files changed

+3
-31
lines changed

2 files changed

+3
-31
lines changed

src/torchcodec/decoders/_video_decoder.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ class VideoDecoder:
5555
decoding which is best if you are running a single instance of ``VideoDecoder``.
5656
Passing 0 lets FFmpeg decide on the number of threads.
5757
Default: 1.
58-
device (str or torch.device, optional): The device to use for decoding.
59-
If ``None`` (default), uses the current default device.
58+
device (str or torch.device, optional): The device to use for decoding. Default: "cpu".
6059
If you pass a CUDA device, we recommend trying the "beta" CUDA
6160
backend which is faster! See :func:`~torchcodec.decoders.set_cuda_backend`.
6261
seek_mode (str, optional): Determines if frame access will be "exact" or
@@ -103,7 +102,7 @@ def __init__(
103102
stream_index: Optional[int] = None,
104103
dimension_order: Literal["NCHW", "NHWC"] = "NCHW",
105104
num_ffmpeg_threads: int = 1,
106-
device: Optional[Union[str, torch_device]] = None,
105+
device: Optional[Union[str, torch_device]] = "cpu",
107106
seek_mode: Literal["exact", "approximate"] = "exact",
108107
custom_frame_mappings: Optional[
109108
Union[str, bytes, io.RawIOBase, io.BufferedReader]
@@ -144,9 +143,7 @@ def __init__(
144143
if num_ffmpeg_threads is None:
145144
raise ValueError(f"{num_ffmpeg_threads = } should be an int.")
146145

147-
if device is None:
148-
device = str(torch.get_default_device())
149-
elif isinstance(device, torch_device):
146+
if isinstance(device, torch_device):
150147
device = str(device)
151148

152149
device_variant = _get_cuda_backend()

test/test_decoders.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -386,31 +386,6 @@ def test_device_instance(self):
386386
decoder = VideoDecoder(NASA_VIDEO.path, device=torch.device("cpu"))
387387
assert isinstance(decoder.metadata, VideoStreamMetadata)
388388

389-
@pytest.mark.parametrize(
390-
"device_str",
391-
[
392-
"cpu",
393-
pytest.param("cuda", marks=pytest.mark.needs_cuda),
394-
],
395-
)
396-
def test_device_none_default_device(self, device_str):
397-
# VideoDecoder defaults to device=None, which should respect both
398-
# torch.device() context manager and torch.set_default_device().
399-
400-
# Test with context manager
401-
with torch.device(device_str):
402-
decoder = VideoDecoder(NASA_VIDEO.path)
403-
assert decoder[0].device.type == device_str
404-
405-
# Test with set_default_device
406-
original_device = torch.get_default_device()
407-
try:
408-
torch.set_default_device(device_str)
409-
decoder = VideoDecoder(NASA_VIDEO.path)
410-
assert decoder[0].device.type == device_str
411-
finally:
412-
torch.set_default_device(original_device)
413-
414389
@pytest.mark.parametrize("device", all_supported_devices())
415390
@pytest.mark.parametrize("seek_mode", ("exact", "approximate"))
416391
def test_getitem_fails(self, device, seek_mode):

0 commit comments

Comments
 (0)