{"record":{"id":"286681c1691d9b70","repo":"huggingface/transformers","slug":"padding-dimensions-are-negative-please-make-sure","errorCode":null,"errorMessage":"Padding dimensions are negative. Please make sure that the `pad_size` is larger than the image size. Got pad_size={pad_size}, image_size={image_size}.","messagePattern":"Padding dimensions are negative\\. Please make sure that the `pad_size` is larger than the image size\\. Got pad_size=(.+?), image_size=(.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/image_processing_backends.py","lineNumber":184,"sourceCode":"        \"\"\"Pad images using Torchvision with batched operations.\"\"\"\n        if pad_size is not None:\n            if not (pad_size.height and pad_size.width):\n                raise ValueError(f\"Pad size must contain 'height' and 'width' keys only. Got pad_size={pad_size}.\")\n            pad_size = (pad_size.height, pad_size.width)\n        else:\n            pad_size = get_max_height_width(images)\n\n        grouped_images, grouped_images_index = group_images_by_shape(\n            images, disable_grouping=disable_grouping, is_nested=is_nested\n        )\n        processed_images_grouped = {}\n        processed_masks_grouped = {}\n        for shape, stacked_images in grouped_images.items():\n            image_size = stacked_images.shape[-2:]\n            padding_height = pad_size[0] - image_size[0]\n            padding_width = pad_size[1] - image_size[1]\n            if padding_height < 0 or padding_width < 0:\n                raise ValueError(\n                    f\"Padding dimensions are negative. Please make sure that the `pad_size` is larger than the \"\n                    f\"image size. Got pad_size={pad_size}, image_size={image_size}.\"\n                )\n            if image_size != pad_size:\n                padding = (0, 0, padding_width, padding_height)\n                stacked_images = tvF.pad(stacked_images, padding, fill=fill_value, padding_mode=padding_mode)\n            processed_images_grouped[shape] = stacked_images\n\n            if return_mask:\n                stacked_masks = torch.zeros_like(stacked_images, dtype=torch.int64)[..., 0, :, :]\n                stacked_masks[..., : image_size[0], : image_size[1]] = 1\n                processed_masks_grouped[shape] = stacked_masks\n\n        processed_images = reorder_images(processed_images_grouped, grouped_images_index, is_nested=is_nested)\n        if return_mask:\n            processed_masks = reorder_images(processed_masks_grouped, grouped_images_index, is_nested=is_nested)\n            return processed_images, processed_masks\n","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/image_processing_backends.py#L166-L202","documentation":"Error \"Padding dimensions are negative. Please make sure that the `pad_size` is larger than the image size. Got pad_size={pad_size}, image_size={image_size}.\" thrown in huggingface/transformers.","triggerScenarios":"Raised in image padding when target pad dimensions are smaller than the image dimensions, yielding negative padding.","commonSituations":"Requesting a pad_size smaller than the actual image size in an image preprocessing pipeline.","solutions":["Ensure `pad_size` height/width are at least the image height/width.","Compute pad_size as max(pad, image_size) before calling pad."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}