Skip to content

Commit 32b8356

Browse files
NicolasHugfacebook-github-bot
authored andcommitted
[fbsync] Use libjpeg-turbo for tests and builds (#7672)
Summary: Co-authored-by: Philip Meier <github.pmeier@posteo.de> Reviewed By: matteobettini Differential Revision: D48642301 fbshipit-source-id: bbf318b1568fdc24796c4e6649d010bdfbd27a44
1 parent fcf70d3 commit 32b8356

File tree

8 files changed

+40
-15
lines changed

8 files changed

+40
-15
lines changed

.github/scripts/setup-env.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ conda create \
4040
--quiet --yes \
4141
python="${PYTHON_VERSION}" pip \
4242
ninja cmake \
43-
libpng jpeg \
43+
libpng \
4444
'ffmpeg<4.3'
4545
conda activate ci
46+
conda install --quiet --yes libjpeg-turbo -c pytorch
4647
pip install --progress-bar=off --upgrade setuptools
4748

4849
# See https://github.com/pytorch/vision/issues/6790

.github/scripts/unittest.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ echo '::group::Install testing utilities'
1111
pip install --progress-bar=off pytest pytest-mock pytest-cov
1212
echo '::endgroup::'
1313

14+
python test/smoke_test.py
1415
pytest --junit-xml="${RUNNER_TEST_RESULTS_DIR}/test-results.xml" -v --durations=25

packaging/pre_build_script.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fi
1313

1414
if [[ "$(uname)" == Darwin || "$OSTYPE" == "msys" ]]; then
1515
# Install libpng from Anaconda (defaults)
16-
conda install libpng "jpeg<=9b" -yq
17-
conda install -yq ffmpeg=4.2 -c pytorch
16+
conda install libpng -yq
17+
conda install -yq ffmpeg=4.2 libjpeg-turbo -c pytorch
1818

1919
# Copy binaries to be included in the wheel distribution
2020
if [[ "$OSTYPE" == "msys" ]]; then

packaging/torchvision/meta.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ requirements:
1010
build:
1111
- {{ compiler('c') }} # [win]
1212
- libpng
13-
- jpeg
13+
- libjpeg-turbo
1414
# NOTE: The only ffmpeg version that we build is actually 4.2
1515
- ffmpeg >=4.2 # [not win]
1616

@@ -28,7 +28,7 @@ requirements:
2828
- requests
2929
- libpng
3030
- ffmpeg >=4.2 # [not win]
31-
- jpeg
31+
- libjpeg-turbo
3232
- pillow >=5.3.0, !=8.3.*
3333
- pytorch-mutex 1.0 {{ build_variant }} # [not osx ]
3434
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}
@@ -62,7 +62,7 @@ test:
6262
requires:
6363
- pytest
6464
- scipy
65-
- jpeg
65+
- libjpeg-turbo
6666
- ca-certificates
6767

6868

test/smoke_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def smoke_test_torchvision_resnet50_classify(device: str = "cpu") -> None:
7878
def main() -> None:
7979
print(f"torchvision: {torchvision.__version__}")
8080
print(f"torch.cuda.is_available: {torch.cuda.is_available()}")
81+
print(f"{torch.ops.image._jpeg_version() = }")
82+
assert torch.ops.image._is_compiled_against_turbo()
8183
smoke_test_torchvision()
8284
smoke_test_torchvision_read_decode()
8385
smoke_test_torchvision_resnet50_classify()

torchvision/csrc/io/image/cpu/decode_jpeg.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,23 @@ torch::Tensor decode_jpeg(const torch::Tensor& data, ImageReadMode mode) {
152152
jpeg_destroy_decompress(&cinfo);
153153
return tensor.permute({2, 0, 1});
154154
}
155+
#endif // #if !JPEG_FOUND
155156

157+
int64_t _jpeg_version() {
158+
#ifdef JPEG_FOUND
159+
return JPEG_LIB_VERSION;
160+
#else
161+
return -1;
162+
#endif
163+
}
164+
165+
bool _is_compiled_against_turbo() {
166+
#ifdef LIBJPEG_TURBO_VERSION
167+
return true;
168+
#else
169+
return false;
156170
#endif
171+
}
157172

158173
} // namespace image
159174
} // namespace vision

torchvision/csrc/io/image/cpu/decode_jpeg.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@ C10_EXPORT torch::Tensor decode_jpeg(
1010
const torch::Tensor& data,
1111
ImageReadMode mode = IMAGE_READ_MODE_UNCHANGED);
1212

13+
C10_EXPORT int64_t _jpeg_version();
14+
C10_EXPORT bool _is_compiled_against_turbo();
15+
1316
} // namespace image
1417
} // namespace vision

torchvision/csrc/io/image/image.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ PyMODINIT_FUNC PyInit_image(void) {
1919
namespace vision {
2020
namespace image {
2121

22-
static auto registry = torch::RegisterOperators()
23-
.op("image::decode_png", &decode_png)
24-
.op("image::encode_png", &encode_png)
25-
.op("image::decode_jpeg", &decode_jpeg)
26-
.op("image::encode_jpeg", &encode_jpeg)
27-
.op("image::read_file", &read_file)
28-
.op("image::write_file", &write_file)
29-
.op("image::decode_image", &decode_image)
30-
.op("image::decode_jpeg_cuda", &decode_jpeg_cuda);
22+
static auto registry =
23+
torch::RegisterOperators()
24+
.op("image::decode_png", &decode_png)
25+
.op("image::encode_png", &encode_png)
26+
.op("image::decode_jpeg", &decode_jpeg)
27+
.op("image::encode_jpeg", &encode_jpeg)
28+
.op("image::read_file", &read_file)
29+
.op("image::write_file", &write_file)
30+
.op("image::decode_image", &decode_image)
31+
.op("image::decode_jpeg_cuda", &decode_jpeg_cuda)
32+
.op("image::_jpeg_version", &_jpeg_version)
33+
.op("image::_is_compiled_against_turbo", &_is_compiled_against_turbo);
3134

3235
} // namespace image
3336
} // namespace vision

0 commit comments

Comments
 (0)