{"record":{"id":"6a0bb29ff860a861","repo":"rohitg00/ai-engineering-from-scratch","slug":"patch-size-self-patch-size-must-divide-image-siz","errorCode":null,"errorMessage":"patch_size {self.patch_size} must divide image_size {self.image_size}","messagePattern":"patch_size (.+?) must divide image_size (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phases/19-capstone-projects/58-vision-encoder-patches/code/main.py","lineNumber":32,"sourceCode":"import math\nfrom dataclasses import dataclass\n\nimport numpy as np\nimport torch\nimport torch.nn as nn\n\n\n@dataclass(frozen=True)\nclass FrontEndConfig:\n    image_size: int = 224\n    patch_size: int = 16\n    in_channels: int = 3\n    hidden: int = 768\n\n    @property\n    def grid_size(self) -> int:\n        if self.image_size % self.patch_size != 0:\n            raise ValueError(\n                f\"patch_size {self.patch_size} must divide image_size {self.image_size}\"\n            )\n        return self.image_size // self.patch_size\n\n    @property\n    def num_patches(self) -> int:\n        return self.grid_size * self.grid_size\n\n\ndef sinusoidal_2d(grid_h: int, grid_w: int, dim: int) -> torch.Tensor:\n    \"\"\"Build a deterministic 2D sinusoidal position table of shape (grid_h * grid_w, dim).\n\n    Half of dim encodes row position, half encodes column position. Within each\n    half, frequencies span the standard Transformer sin/cos band. Identical\n    inputs always produce identical outputs, with no learned state.\n    \"\"\"\n    if dim % 4 != 0:\n        raise ValueError(f\"sinusoidal_2d dim must be divisible by 4, got {dim}\")","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/rohitg00/ai-engineering-from-scratch/blob/39ea8a1c6d0b61f071226eff7ede4d4105fed820/phases/19-capstone-projects/58-vision-encoder-patches/code/main.py#L14-L50","documentation":"Error \"patch_size {self.patch_size} must divide image_size {self.image_size}\" thrown in rohitg00/ai-engineering-from-scratch.","triggerScenarios":"Thrown at phases/19-capstone-projects/58-vision-encoder-patches/code/main.py:32 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"39ea8a1c6d0b61f071226eff7ede4d4105fed820","analyzedAt":"2026-08-26T03:13:46.626Z","schemaVersion":2},"datasetVersion":"2026-08-26T07:17:17.940Z"}