Skip to content

Commit

Permalink
Fix UDOP dtype issue (#34180)
Browse files Browse the repository at this point in the history
* Trigger UDOP tests

* Try forcing dtype in LayoutLMV3

* Do checks to see where uint8 is getting in

* Do checks to see where uint8 is getting in

* Found it!

* Add .astype(np.float32)

* Remove forced check, make fixup

* Checking where exactly the uint8 creeps in

* More checking on the uint8 issues

* Manually upcast in rescale()

* Remove UDOP trigger
  • Loading branch information
Rocketknight1 authored Oct 18, 2024
1 parent 6604764 commit e46e3bc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transformers/image_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ def rescale(
if not isinstance(image, np.ndarray):
raise TypeError(f"Input image must be of type np.ndarray, got {type(image)}")

rescaled_image = image * scale
rescaled_image = image.astype(np.float64) * scale # Numpy type promotion has changed, so always upcast first
if data_format is not None:
rescaled_image = to_channel_dimension_format(rescaled_image, data_format, input_data_format)

rescaled_image = rescaled_image.astype(dtype)
rescaled_image = rescaled_image.astype(dtype) # Finally downcast to the desired dtype at the end

return rescaled_image

Expand Down

0 comments on commit e46e3bc

Please sign in to comment.