{"record":{"id":"0f8f53e2e3061321","repo":"huggingface/transformers","slug":"depending-on-the-model-size-divisor-or-pad-siz","errorCode":null,"errorMessage":"Depending on the model, `size_divisor` or `pad_size` or `size` must be specified if `do_pad` is `True`.","messagePattern":"Depending on the model, `size_divisor` or `pad_size` or `size` must be specified if `do_pad` is `True`\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_utils.py","lineNumber":614,"sourceCode":"    \"\"\"\n    Checks validity of typically used arguments in an `ImageProcessor` `preprocess` method.\n    Raises `ValueError` if arguments incompatibility is caught.\n    Many incompatibilities are model-specific. `do_pad` sometimes needs `size_divisor`,\n    sometimes `size_divisibility`, and sometimes `size`. New models and processors added should follow\n    existing arguments when possible.\n\n    \"\"\"\n    if do_rescale and rescale_factor is None:\n        raise ValueError(\"`rescale_factor` must be specified if `do_rescale` is `True`.\")\n\n    if do_pad and pad_size is None:\n        # Processors pad images using different args depending on the model, so the below check is pointless\n        # but we keep it for BC for now. TODO: remove in v5\n        # Usually padding can be called with:\n        #   - \"pad_size/size\" if we're padding to specific values\n        #   - \"size_divisor\" if we're padding to any value divisible by X\n        #   - \"None\" if we're padding to the maximum size image in batch\n        raise ValueError(\n            \"Depending on the model, `size_divisor` or `pad_size` or `size` must be specified if `do_pad` is `True`.\"\n        )\n\n    if do_normalize and (image_mean is None or image_std is None):\n        raise ValueError(\"`image_mean` and `image_std` must both be specified if `do_normalize` is `True`.\")\n\n    if do_center_crop and crop_size is None:\n        raise ValueError(\"`crop_size` must be specified if `do_center_crop` is `True`.\")\n\n    if do_resize and not (size is not None and resample is not None):\n        raise ValueError(\"`size` and `resample` must be specified if `do_resize` is `True`.\")\n\n\nclass ImageFeatureExtractionMixin:\n    \"\"\"\n    Mixin that contain utilities for preparing image features.\n    \"\"\"\n","sourceCodeStart":596,"sourceCodeEnd":632,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_utils.py#L596-L632","documentation":"Raised by `transformers.image_utils.validate_preprocess_arguments` when `do_pad=True` but `pad_size` is None. The in-code comment states this check is kept only for backwards compatibility and is 'pointless' because different processors pad via different knobs — `pad_size`/`size` (pad to specific values), `size_divisor` (pad to a multiple), or nothing (pad to the batch max). Nevertheless, when this validator runs with do_pad enabled and no pad_size, it raises unconditionally.","triggerScenarios":"Calling `processor.preprocess(images, do_pad=True)` without `pad_size`; enabling do_pad on a processor whose padding is driven by `size_divisor` or by batch-max logic but whose preprocess path still calls this validator with pad_size=None.","commonSituations":"Per-call flag toggling that forgets the paired padding argument; older/other-repo processor configs where do_pad=True is saved but pad_size is not; custom processors that pass do_pad through to the shared validator while intending size_divisor semantics.","solutions":["Pass a pad size with the flag: `processor(images, do_pad=True, pad_size={'height': H, 'width': W})` (match your processor's pad_size schema — some take dicts, some ints).","Or disable padding and pad manually with `transformers.image_transforms.pad` / `torch.nn.functional.pad`.","For size_divisor-style processors, pass the divisor argument their preprocess defines so their internal path supplies pad_size, or set `do_pad=False` and pad to the divisor yourself.","If the flag comes from a saved preprocessor_config.json, update the config to include pad_size and re-save."],"exampleFix":"// before\ninputs = processor(images=imgs, do_pad=True, return_tensors=\"pt\")  # ValueError\n\n// after\ninputs = processor(images=imgs, do_pad=True, pad_size={\"height\": 640, \"width\": 640}, return_tensors=\"pt\")\n// or pad manually:\nfrom transformers.image_transforms import pad\npadded = [pad(np.array(i), 0) for i in imgs]","handlingStrategy":"validation","validationCode":"if do_pad:\n    assert pad_size is not None, \"do_pad=True requires pad_size (dict or int, per processor)\"\n\ninputs = processor(images=images, do_pad=do_pad, pad_size=pad_size or {\"height\": 640, \"width\": 640})","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pair do_pad with the exact padding argument your processor defines (pad_size, size, or size_divisor).","Inspect the processor's preprocessor_config.json before enabling do_pad per-call.","If the validator conflicts with size_divisor-style processors, pad manually after preprocess."],"tags":["image-processing","preprocess","padding","argument-validation","configuration"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}