{"record":{"id":"c83a832b6655ecd3","repo":"sgl-project/sglang","slug":"n-must-be-a-positive-integer","errorCode":null,"errorMessage":"n must be a positive integer","messagePattern":"n must be a positive integer","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/sglang/srt/models/inkling_common/hmlp.py","lineNumber":17,"sourceCode":"from __future__ import annotations\n\nfrom typing import cast\n\nimport numpy as np\nimport torch\nfrom torch import nn\nfrom torch.nn import functional as F\n\nfrom sglang.srt.configs.inkling import InklingVisionConfig\nfrom sglang.srt.models.inkling_common.norm import RMSNorm\n\n\ndef _prime_factors(n: int) -> list[int]:\n    \"\"\"Return the prime factors of ``n`` in ascending order.\"\"\"\n    if n < 1:\n        raise ValueError(\"n must be a positive integer\")\n\n    factors: list[int] = []\n\n    while n % 2 == 0:\n        factors.append(2)\n        n //= 2\n\n    p = 3\n    while p * p <= n:\n        while n % p == 0:\n            factors.append(p)\n            n //= p\n        p += 2\n\n    if n > 1:\n        factors.append(n)\n    return factors\n","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/sgl-project/sglang/blob/0132848349585cfe6aae51c4941cbae872505f8a/python/sglang/srt/models/inkling_common/hmlp.py#L1-L35","documentation":"_prime_factors validates its input and raises ValueError for n < 1, since prime factorization is undefined for zero/negative numbers. plan_out_scales calls it to factor MLP layer counts, so a zero or negative layer/size value propagates here. It signals an invalid model config (e.g. n_layers = 0 or a negative dimension) rather than a runtime math bug.","triggerScenarios":"Calling plan_out_scales(temporal_patch_size, patch_size, n_layers, ...) (from HMLP __init__) with a non-positive value that reaches _prime_factors — typically n_layers <= 0 or a temporal_patch_size <= 0 being factored.","commonSituations":"Loading a checkpoint/config with num_hidden_layers: 0; typo'd config (negative or zero patch/layer counts); test code passing 0 defaults; sliced/partial configs from a quantized export.","solutions":["Fix the model config so the layer/size integers passed to the HMLP planner are >= 1 (check config.json num_hidden_layers and vision patch sizes)","Validate and clamp/abort early on invalid config before model construction","If building the config programmatically, assert the values before calling plan_out_scales"],"exampleFix":"# before\nplan_out_scales(temporal_patch_size=3, patch_size=16, n_layers=0)\n# after\nassert n_layers >= 1\nplan_out_scales(temporal_patch_size=3, patch_size=16, n_layers=n_layers)","handlingStrategy":"validation","validationCode":"if temporal_patch_size < 1 or patch_size <= 1 or n_layers < 1:\n    raise ConfigError(\"HMLP planner requires positive ints\")\nplan_out_scales(temporal_patch_size, patch_size, n_layers)","typeGuard":"def is_valid_hmlp_config(t: int, p: int, l: int) -> bool:\n    return isinstance(t, int) and isinstance(p, int) and isinstance(l, int) and t >= 1 and p > 1 and l >= 1","tryCatchPattern":null,"preventionTips":["Validate vision/MLP config ints >= 1 before model construction","Schema-validate config.json on load","Assert in adapter/config export scripts"],"tags":["sglang","value-error","config-validation","model-loading","inkling"],"backgroundTag":"invalid-argument-validation","analyzedSha":"0132848349585cfe6aae51c4941cbae872505f8a","analyzedAt":"2026-08-28T05:10:05.995Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}