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.
Fixed a bug in TextEncodeQwenImageEditPlus where the rescaling would not preserve the original image ratio.
In the original code, despite having a single
scale_byfactor that is used to both rescale width and height, width and height are actually rescaled by a different factor, due to possible a possible loss of precision during the following rounding operations:The corrected code computes a single optimal scaling factor,

s_optimal, that guarantees the aspect ratio is preserved. This factor solves the following minimization problem efficiently using the GCD algorithm:where
tis the target size, so typically 1024 in this case.This ensures the resulting image area is as close as possible to the target (1024x1024) while ensuring both dimensions are multiples of 8 and the target ratio is preserved.