-
Notifications
You must be signed in to change notification settings - Fork 31.5k
Remove null values from fast image processors dict #42780
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
Remove null values from fast image processors dict #42780
Conversation
|
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. |
zucchini-nlp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, can you also propagate the changes to video processors before merging? I believe it has the same issue
| if value is None: | ||
| class_default = getattr(type(self), key, "NOT_FOUND") | ||
| # Keep None if user explicitly set it (class default is non-None) | ||
| if class_default != "NOT_FOUND" and class_default is not None: | ||
| filtered_dict[key] = value | ||
| else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo we could start saving only values that are different from defaults in the future versions, same as in model configs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I was thinking about this, but since image processors configs are relatively small, I feel that it's nice to explicitely see all the parameters in the config files
| # Find an attribute with a non-None class default to test explicit None override | ||
| test_attr = None | ||
| for attr in ["do_resize", "do_rescale", "do_normalize"]: | ||
| if getattr(self.fast_image_processing_class, attr, None) not in [None, "NOT_FOUND"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: NOT_FOUND seems to be an unlikely option, unless it's set on purpose in processor class
|
[For maintainers] Suggested jobs to run (before merge) run-slow: flava, mask2former |
* remove null values from saved preporcessor file for fast image processor * preserve explicit None values != class default * Fix flava test * extend to video processor
What does this PR do?
As discussed internally, Cc @ArthurZucker, @zucchini-nlp
This is a bit more involved than I first thought, as we need to keep explicitly passed null values if the default of the class is not None, otherwise we would be loading the processor with the default when it should be None.
Before (Devstral):
{ "image_break_token": "[IMG_BREAK]", "image_end_token": "[IMG_END]", "image_processor": { "crop_size": null, "data_format": "channels_first", "device": null, "disable_grouping": null, "do_center_crop": null, "do_convert_rgb": true, "do_normalize": true, "do_pad": null, "do_rescale": true, "do_resize": true, "image_mean": [ 0.48145466, 0.4578275, 0.40821073 ], "image_processor_type": "PixtralImageProcessorFast", "image_seq_length": null, "image_std": [ 0.26862954, 0.26130258, 0.27577711 ], "input_data_format": null, "pad_size": null, "patch_size": 14, "processor_class": "PixtralProcessor", "resample": 3, "rescale_factor": 0.00392156862745098, "return_tensors": null, "size": { "longest_edge": 1540 } }, "image_token": "[IMG]", "patch_size": 14, "processor_class": "PixtralProcessor", "spatial_merge_size": 2 }After:
{ "image_break_token": "[IMG_BREAK]", "image_end_token": "[IMG_END]", "image_processor": { "data_format": "channels_first", "do_convert_rgb": true, "do_normalize": true, "do_rescale": true, "do_resize": true, "image_mean": [ 0.48145466, 0.4578275, 0.40821073 ], "image_processor_type": "PixtralImageProcessorFast", "image_std": [ 0.26862954, 0.26130258, 0.27577711 ], "patch_size": 14, "processor_class": "PixtralProcessor", "resample": 3, "rescale_factor": 0.00392156862745098, "size": { "longest_edge": 1540 } }, "image_token": "[IMG]", "patch_size": 14, "processor_class": "PixtralProcessor", "spatial_merge_size": 2 }