Skip to content
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

Handle grayscale images in expand2square #97

Merged
merged 2 commits into from
Jan 25, 2024

Conversation

isaac-vidas
Copy link
Contributor

Fix error when handling grayscale images in expand2square:

Exception in TokenizerManager:
Traceback (most recent call last):
  File "/home/gcpuser/sglang/python/sglang/srt/managers/tokenizer_manager.py", line 61, in get_pixel_values
    image = expand2square(
  File "/home/gcpuser/sglang/python/sglang/srt/mm_utils.py", line 167, in expand2square
    result = Image.new(pil_img.mode, (width, width), background_color)
  File "/opt/conda/envs/sglang_flashinfer/lib/python3.9/site-packages/PIL/Image.py", line 2941, in new
    return im._new(core.fill(mode, size, color))
TypeError: color must be int or single-element tuple

Fix handling grayscale images in expand2square
Copy link
Collaborator

@haotian-liu haotian-liu left a comment

Choose a reason for hiding this comment

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

Thanks. It makes sense not to assume that they are in RGB.

@@ -164,10 +164,14 @@ def expand2square(pil_img, background_color):
if width == height:
return pil_img
elif width > height:
if pil_img.mode == "L":
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just move this if pil_img.mode to the outer block, in case there's something else broken when width==height. Anyway we will need RGB.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense!
I moved the conversion to her as we only need to convert it if the width and height are not the same + changed elif to if condition to support the change.

Copy link
Collaborator

@haotian-liu haotian-liu left a comment

Choose a reason for hiding this comment

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

Thanks.

@Ying1123 Ying1123 merged commit 0c457ba into sgl-project:main Jan 25, 2024
@isaac-vidas isaac-vidas deleted the iv-grayscale-expand2square branch January 25, 2024 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants