Skip to content

Conversation

@yonigozlan
Copy link
Member

@yonigozlan yonigozlan commented Dec 10, 2025

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
}

@HuggingFaceDocBuilderDev

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.

Copy link
Member

@zucchini-nlp zucchini-nlp left a 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

Comment on lines +944 to +949
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:
Copy link
Member

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

Copy link
Member Author

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"]:
Copy link
Member

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

@github-actions
Copy link
Contributor

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

run-slow: flava, mask2former

@yonigozlan yonigozlan merged commit fc50bdc into huggingface:main Dec 15, 2025
25 checks passed
itazap pushed a commit that referenced this pull request Dec 15, 2025
* remove null values from saved preporcessor file for fast image processor

* preserve explicit None values != class default

* Fix flava test

* extend to video processor
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.

3 participants