{"record":{"id":"a8eb6951bbabe201","repo":"unslothai/unsloth","slug":"the-aspect-ratio-must-be-positive-got-aspect-wid","errorCode":null,"errorMessage":"The aspect ratio must be positive, got {aspect_width}:{aspect_height}.","messagePattern":"The aspect ratio must be positive, got (.+?):(.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"studio/backend/core/training/diffusion_h3_clips.py","lineNumber":155,"sourceCode":"    return num_text_tokens + audio_rows + latent_frames * rows_per_frame\n\n\ndef h3_train_canvas(\n    aspect_width: float,\n    aspect_height: float,\n    short_edge: int = H3_CANVAS_SHORT_EDGE,\n    max_pixels: Optional[int] = None,\n) -> tuple[int, int]:\n    \"\"\"MiniMax-H3's canvas rule, as ``(width, height)``.\n\n    Identical arithmetic to the pipeline's ``resolve_canvas_size`` (which returns\n    ``(height, width)``), re-expressed here so the trainer can size a dataset before any\n    diffusers import. ``short_edge`` is the run's ``resolution``; the area cap scales with it\n    so a smaller training canvas keeps the released aspect budget rather than the released\n    pixel count.\n    \"\"\"\n    if aspect_width <= 0 or aspect_height <= 0:\n        raise ValueError(f\"The aspect ratio must be positive, got {aspect_width}:{aspect_height}.\")\n    ratio = aspect_width / aspect_height\n    if not H3_MIN_ASPECT_RATIO <= ratio <= H3_MAX_ASPECT_RATIO:\n        raise ValueError(\n            f\"MiniMax-H3 was trained on aspect ratios from 1:4 to 4:1; this clip is \"\n            f\"{aspect_width:g}x{aspect_height:g} ({ratio:.2f}:1). Crop it first.\"\n        )\n    if max_pixels is None:\n        # The released cap, rescaled to the requested short edge: (1344/768) * short_edge^2.\n        max_pixels = int(H3_CANVAS_MAX_PIXELS * (short_edge / H3_CANVAS_SHORT_EDGE) ** 2)\n    if ratio >= 1.0:\n        width, height = short_edge * ratio, float(short_edge)\n    else:\n        width, height = float(short_edge), short_edge / ratio\n    area = width * height\n    if area > max_pixels:\n        scale = math.sqrt(max_pixels / area)\n        width, height = width * scale, height * scale\n","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/unslothai/unsloth/blob/203007d19051dcd2ae33876786d117c99f6b0368/studio/backend/core/training/diffusion_h3_clips.py#L137-L173","documentation":"Raised by the H3 canvas helper when aspect_width or aspect_height is zero or negative. The function mirrors MiniMax-H3's resolve_canvas_size arithmetic to size a training canvas before any diffusers import, and a non-positive edge makes the ratio (and every downstream dimension) undefined. It is a pure input-validation guard on the aspect pair.","triggerScenarios":"Passing aspect_width=0 or a negative dimension; deriving the aspect from a clip probe that failed and returned zeros; integer underflow in aspect math (width - crop_left going below zero).","commonSituations":"Metadata/JSON rows carrying 0x0 dimensions; portrait/landscape branch swapping width and height into the wrong slots; degenerate clips whose decoder reported no size.","solutions":["Fix the producer of the aspect pair so both values are positive integers.","Skip/log clips whose probed dimensions are non-positive instead of feeding them to the canvas helper.","Validate dimensions when loading metadata.jsonl rows at ingestion time."],"exampleFix":"# before\nw, h = h3_canvas_size(0, 1080, short_edge=768)  # probe returned width 0\n\n# after\nif clip_width > 0 and clip_height > 0:\n    w, h = h3_canvas_size(clip_width, clip_height, short_edge=768)","handlingStrategy":"validation","validationCode":"def aspect_inputs_valid(w: int, h: int) -> bool:\n    return isinstance(w, int) and isinstance(h, int) and w > 0 and h > 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate probed clip dimensions at ingestion and drop 0x0 rows from metadata.","Treat non-positive dimensions from any decoder probe as a corrupt clip."],"tags":["validation","video","aspect-ratio","minimax-h3"],"backgroundTag":null,"analyzedSha":"203007d19051dcd2ae33876786d117c99f6b0368","analyzedAt":"2026-08-15T02:48:39.846Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}