Cherry pick rocjpeg and rocjpeg fallback - #6
Open
apinge wants to merge 4 commits into
Open
Conversation
apinge
marked this pull request as ready for review
July 29, 2026 14:00
sammysun0711
force-pushed
the
qwen3_5_v0.5.15_dflash
branch
from
July 29, 2026 14:16
f9bcf42 to
b783021
Compare
apinge
force-pushed
the
try-cherry-pick-de3560e40-rocjpeg-fallback
branch
from
July 29, 2026 14:29
47a5fde to
651384c
Compare
…ted format (sgl-project#257) (cherry picked from commit de3560e)
(cherry picked from commit de55abd)
apinge
force-pushed
the
try-cherry-pick-de3560e40-rocjpeg-fallback
branch
from
August 4, 2026 02:18
651384c to
04cdcbd
Compare
Signed-off-by: root <root@hjbog-srdc-21.amd.com>
There was a problem hiding this comment.
Pull request overview
This PR cherry-picks upstream changes to improve multimodal image ingestion by enabling JPEG batch decoding (rocjpeg path) with a CPU/OpenCV fallback, and wiring that into the multimodal processor data-loading fast/legacy paths.
Changes:
- Added JPEG-format detection plus new
load_image_tensor()andbatch_decode_jpeg_gpu()utilities to support “return bytes for JPEG, decode otherwise” and batch decode. - Updated
BaseMultimodalProcessorimage loading to return(img_tensor_bytes, "jpeg")for JPEGs and batch-decode them after the parallel load stage. - Adjusted file path handling for
file://inputs inget_image_bytes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| python/sglang/srt/utils/common.py | Adds JPEG detection, batch JPEG decode helper with fallback, new tensor-oriented image loader, and improves file:// path normalization. |
| python/sglang/srt/multimodal/processors/base_processor.py | Switches image load path to the new tensor/bytes API and adds JPEG batch decode in both fast and legacy multimodal loading. |
Suppressed comments (1)
python/sglang/srt/multimodal/processors/base_processor.py:1065
- Same as fast path:
batch_decode_jpeg_gpu()can yieldNoneentries, anddecoded_img.to(...)will fail with an attribute error. Consider surfacing a clearer error (or skipping/handling failures) before storing intofinal_results.
# Batch decode all JPEG images
if jpeg_bytes_list:
decoded_images = batch_decode_jpeg_gpu(
jpeg_bytes_list, device=target_device
)
# Put decoded images back to their original positions
for img_idx, decoded_img in zip(jpeg_indices, decoded_images):
final_results[img_idx] = decoded_img.to(target_device)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1780
to
+1784
| def load_image_tensor( | ||
| image_file: Union[Image.Image, str, ImageData, bytes], | ||
| discard_alpha_channel: bool = True, | ||
| ) -> tuple[Image.Image, tuple[int, int]]: | ||
| """ |
Comment on lines
+1798
to
+1802
| if isinstance(image_file, Image.Image): | ||
| image = image_file | ||
| image_size = (image.width, image.height) | ||
| img_tensor = F.pil_to_tensor(image) | ||
| return img_tensor, None |
Comment on lines
541
to
+543
| try: | ||
| if modality == Modality.IMAGE: | ||
| img, _ = load_image(data, cls.gpu_image_decode) | ||
| if isinstance(img, torch.Tensor): | ||
| return img # JPEG already decoded on GPU by nvJPEG | ||
| # PIL decodes lazily; do it here in the io worker so the decode | ||
| # doesn't run later on the event-loop thread. | ||
| if discard_alpha_channel and img.mode != "RGB": | ||
| return img.convert("RGB") | ||
| img.load() | ||
| return img | ||
| return load_image_tensor(data, discard_alpha_channel) |
Comment on lines
+953
to
+960
| # Batch decode all JPEG images on GPU | ||
| if jpeg_bytes_list: | ||
| decoded_images = batch_decode_jpeg_gpu( | ||
| jpeg_bytes_list, device=target_device | ||
| ) | ||
| for img_idx, decoded_img in zip(jpeg_indices, decoded_images): | ||
| images[img_idx] = decoded_img.to(target_device) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Cherry pick zejunchen-zejun#211 and zejunchen-zejun#257
Modifications
Accuracy Tests
Speed Tests and Profiling
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ❌ Run #30451825788
Latest PR Test (Extra): ❌ Run #30451825715