Skip to content

Commit d17c4ef

Browse files
committed
Enable plugin autoloading
Requires: meta-pytorch/torchcodec#1151 Signed-off-by: Dmitry Rogozhkin <dmitry.v.rogozhkin@intel.com>
1 parent e44a56c commit d17c4ef

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,10 @@ python3 -m pip install --no-build-isolation -vv -e .
6969

7070
# How to use
7171

72-
Import the project in your Python script to register Intel device
73-
interface for the TorchCodec:
72+
TorchCodec will automatically load Intel Plugin if it is installed on the system via python packages entry point mechanism. No explcit project importing is required. Proceed by importing TorchCodec as usual:
7473

7574
```
7675
import torchcodec
77-
import torchcodec_xpu
7876
```
7977

8078
Before executing, make sure to export environment variables to point to FFmpeg installation:
@@ -84,6 +82,12 @@ export PATH=$HOME/_install/bin:$PATH
8482
export LD_LIBRARY_PATH=$HOME/_install/lib:$LD_LIBRARY_PATH
8583
```
8684

85+
Note that it is possible to disable auto loading by exporting the following environment variable:
86+
87+
```
88+
export TORCHCODEC_DEVICE_BACKEND_AUTOLOAD=0
89+
```
90+
8791
[Getting Started on Intel GPU]: https://docs.pytorch.org/docs/stable/notes/get_start_xpu.html
8892
[TorchCodec]: https://github.com/meta-pytorch/torchcodec
8993

patches/0001-Add-XPU-support-to-tests.patch

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
From 685063b320fb83aac6c1e9fa14d838b7e3fdb178 Mon Sep 17 00:00:00 2001
1+
From b0189f1fe8f367cb45981af3126e723ae3d515bf Mon Sep 17 00:00:00 2001
22
From: Edgar Romo Montiel <edgar.romo.montiel@intel.com>
33
Date: Tue, 9 Dec 2025 14:36:08 -0800
44
Subject: [PATCH] Add XPU support to tests
@@ -7,8 +7,8 @@ Signed-off-by: Edgar Romo Montiel <edgar.romo.montiel@intel.com>
77
---
88
test/conftest.py | 19 +++++++++++++++++--
99
test/test_ops.py | 14 ++++++++++++++
10-
test/utils.py | 18 ++++++++++++++++++
11-
3 files changed, 49 insertions(+), 2 deletions(-)
10+
test/utils.py | 17 +++++++++++++++++
11+
3 files changed, 48 insertions(+), 2 deletions(-)
1212

1313
diff --git a/test/conftest.py b/test/conftest.py
1414
index fa674bf..91ef29b 100644
@@ -73,17 +73,17 @@ index fa674bf..91ef29b 100644
7373
+ if torch.xpu.is_available():
7474
+ torch.xpu.set_rng_state(xpu_rng_state)
7575
diff --git a/test/test_ops.py b/test/test_ops.py
76-
index 0ec4515..bd8d5db 100644
76+
index 0ec4515..76c8a09 100644
7777
--- a/test/test_ops.py
7878
+++ b/test/test_ops.py
79-
@@ -47,6 +47,7 @@ from .utils import (
80-
NASA_AUDIO_MP3,
79+
@@ -48,6 +48,7 @@ from .utils import (
8180
NASA_VIDEO,
8281
needs_cuda,
83-
+ needs_xpu,
8482
needs_ffmpeg_cli,
83+
+ needs_xpu,
8584
SINE_MONO_S32,
8685
SINE_MONO_S32_44100,
86+
SINE_MONO_S32_8000,
8787
@@ -650,6 +651,19 @@ class TestVideoDecoderOps:
8888
duration, torch.tensor(0.0334).double(), atol=0, rtol=1e-3
8989
)
@@ -105,18 +105,10 @@ index 0ec4515..bd8d5db 100644
105105
class TestAudioDecoderOps:
106106
@pytest.mark.parametrize(
107107
diff --git a/test/utils.py b/test/utils.py
108-
index 6f4c77b..ae211d9 100644
108+
index cd735cf..f0f874e 100644
109109
--- a/test/utils.py
110110
+++ b/test/utils.py
111-
@@ -12,6 +12,7 @@ import pytest
112-
113-
import torch
114-
115-
+import torchcodec_xpu
116-
from torchcodec._core import get_ffmpeg_library_versions
117-
from torchcodec.decoders import set_cuda_backend, VideoDecoder
118-
from torchcodec.decoders._video_decoder import _read_custom_frame_mappings
119-
@@ -26,6 +27,13 @@ def needs_cuda(test_item):
111+
@@ -28,6 +28,13 @@ def needs_cuda(test_item):
120112
return pytest.mark.needs_cuda(test_item)
121113

122114

@@ -130,15 +122,15 @@ index 6f4c77b..ae211d9 100644
130122
# Decorator for skipping ffmpeg tests when ffmpeg cli isn't available. The tests are
131123
# effectively marked to be skipped in pytest_collection_modifyitems() of
132124
# conftest.py
133-
@@ -48,6 +56,7 @@ def all_supported_devices():
125+
@@ -50,6 +57,7 @@ def all_supported_devices():
134126
"cpu",
135127
pytest.param("cuda", marks=pytest.mark.needs_cuda),
136128
pytest.param(_CUDA_BETA_DEVICE_STR, marks=pytest.mark.needs_cuda),
137129
+ pytest.param("xpu", marks=pytest.mark.needs_xpu),
138130
)
139131

140132

141-
@@ -147,6 +156,15 @@ def assert_frames_equal(*args, **kwargs):
133+
@@ -156,6 +164,15 @@ def assert_frames_equal(*args, **kwargs):
142134
)
143135
else:
144136
torch.testing.assert_close(*args, **kwargs, atol=atol, rtol=0)

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ dynamic = ["version"]
1616
[project.urls]
1717
GitHub = "https://github.com/dvrogozh/torchcodec-xpu"
1818

19+
[project.entry-points.'torchcodec.backends']
20+
device_backend = 'torchcodec_xpu:load_torchcodec_xpu_shared_library'
21+
1922
[tool.setuptools.dynamic]
2023
version = {file = "version.txt"}
2124

src/torchcodec_xpu/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,3 @@ def load_torchcodec_xpu_shared_library():
6363
"""
6464
f"{traceback}"
6565
)
66-
67-
load_torchcodec_xpu_shared_library()
68-

0 commit comments

Comments
 (0)