Skip to content

Remove redundant condition checks in get_image_size method#45461

Merged
Rocketknight1 merged 2 commits intohuggingface:mainfrom
JiauZhang:main
Apr 17, 2026
Merged

Remove redundant condition checks in get_image_size method#45461
Rocketknight1 merged 2 commits intohuggingface:mainfrom
JiauZhang:main

Conversation

@JiauZhang
Copy link
Copy Markdown
Contributor

What does this PR do?

Remove redundant condition checks in get_image_size method

@@ -358,14 +358,6 @@ def get_image_size(
resize_height = max(int(round(resize_height / 32) * 32), 32)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The removed early-return optimization (if resize_height == height and resize_width == width) avoided tensor allocation when no resize was needed. Its removal means every call now allocates a torch.tensor even when input dimensions are already valid — this could add measurable overhead in high-throughput inference pipelines. Consider restoring the check or benchmarking the impact.

@JiauZhang
Copy link
Copy Markdown
Contributor Author

JiauZhang commented Apr 16, 2026

@afurm

   if resize_height == height and resize_width == width:
          return SizeDict(height=resize_height, width=resize_width), torch.tensor(
              [height, width], dtype=torch.float32, device=image.device
          )
# The last return is the same as the one above.
      return SizeDict(height=resize_height, width=resize_width), torch.tensor(
            [height, width], dtype=torch.float32, device=image.device
        )

@Rocketknight1
Copy link
Copy Markdown
Member

Rocketknight1 commented Apr 16, 2026

Are you sure these are redundant..? In particular, the if resize_width <= 0 or resize_height <= 0: block is clearly doing something that is no longer covered after this PR

@JiauZhang
Copy link
Copy Markdown
Contributor Author

@Rocketknight1

resize_height = max(int(round(resize_height / 32) * 32), 32)
resize_width = max(int(round(resize_width / 32) * 32), 32)

# resize_height >=32 and resize_width >=32

  if resize_height == height and resize_width == width:
        return SizeDict(height=resize_height, width=resize_width), torch.tensor(
            [height, width], dtype=torch.float32, device=image.device
        )
......

@Rocketknight1
Copy link
Copy Markdown
Member

@JiauZhang sorry, you're correct! These conditions are totally redundant. One last thing before I approve - can you use make fix-repo to ensure any changes are propagated through the modular system? You might have to make the edit in a modular file first to ensure it gets propagated correctly.

@JiauZhang
Copy link
Copy Markdown
Contributor Author

@Rocketknight1
Done.

@github-actions
Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: pp_ocrv5_server_det

Copy link
Copy Markdown
Member

@Rocketknight1 Rocketknight1 left a comment

Choose a reason for hiding this comment

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

Thank you, merging!

@Rocketknight1 Rocketknight1 enabled auto-merge April 17, 2026 13:22
@Rocketknight1 Rocketknight1 added this pull request to the merge queue Apr 17, 2026
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Merged via the queue into huggingface:main with commit 5399876 Apr 17, 2026
21 checks passed
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.

4 participants