{"record":{"id":"a03096479a333ce8","repo":"huggingface/pytorch-image-models","slug":"coefficient-must-be-length-3-of-real-numbers-got","errorCode":null,"errorMessage":"Coefficient must be length-3 of real numbers, got: {x!r}","messagePattern":"Coefficient must be length-3 of real numbers, got: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"timm/optim/muon.py","lineNumber":1025,"sourceCode":"                    for shape in shapes[:10]:\n                        _logger.info(f\"      {shape}\")\n                    if len(shapes) > 10:\n                        _logger.info(f\"      ... and {len(shapes) - 10} more\")\n\n        return loss\n\n\ndef resolve_ns_coefficients(\n        value: Union[str, Sequence[float], Sequence[Sequence[float]]],\n        presets: Mapping[str, Sequence[Sequence[float]]]\n) -> List[Tuple[float, float, float]]:\n    # tiny helpers (kept inline for succinctness)\n    is_seq = lambda x: isinstance(x, Sequence) and not isinstance(x, (str, bytes))\n    is_real = lambda x: isinstance(x, numbers.Real) and not isinstance(x, bool)\n\n    def as_coeff(x: Sequence[float]) -> Tuple[float, float, float]:\n        if not is_seq(x) or len(x) != 3 or not all(is_real(v) for v in x):\n            raise ValueError(f\"Coefficient must be length-3 of real numbers, got: {x!r}\")\n        a, b, c = x  # type: ignore[misc]\n        return float(a), float(b), float(c)\n\n    if isinstance(value, str):\n        if value not in presets:\n            valid = \", \".join(sorted(presets.keys()))\n            raise ValueError(f\"Unknown coefficients preset '{value}'. Valid options: {valid}\")\n        seq = presets[value]\n        if not is_seq(seq) or len(seq) == 0:\n            raise ValueError(f\"Preset '{value}' is empty or invalid\")\n        return [as_coeff(item) for item in seq]  # validate & cast\n\n    if not is_seq(value):\n        raise TypeError(\n            \"Coefficients must be a preset name (str), a 3-sequence (a,b,c), \"\n            \"or a sequence of 3-sequences.\"\n        )\n","sourceCodeStart":1007,"sourceCodeEnd":1043,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/optim/muon.py#L1007-L1043","documentation":"Newton–Schulz coefficients passed to Muon must be sequences of exactly three real numbers (the a, b, c per iteration). This validation runs when parsing user-supplied coefficient tuples (or preset contents) via as_coeff.","triggerScenarios":"Passing ns_coefficients (or a preset entry) like (3.4445,), (1,2,3,4), (1.0,'a',-1.0), or a bool-containing tuple (bools are explicitly rejected as non-real).","commonSituations":"Copying coefficient triples from papers/code with a missing element; passing nested lists of wrong arity; passing Python booleans from a config system that coerces numbers.","solutions":["Supply exactly three floats per Newton–Schulz step, e.g. (3.4445, -4.7750, 2.0315)","Use a named preset string instead of hand-written triples","Validate config values before constructing the optimizer"],"exampleFix":"# before\nMuon(params, ns_coefficients=[(3.4445, -4.7750)])\n# after\nMuon(params, ns_coefficients=[(3.4445, -4.7750, 2.0315)])","handlingStrategy":"type-guard","validationCode":"import numbers\ndef coeff_ok(t):\n    return (isinstance(t, (list, tuple)) and len(t) == 3\n            and all(isinstance(v, numbers.Real) and not isinstance(v, bool) for v in t))\nassert all(coeff_ok(t) for t in cfg.ns_coefficients)","typeGuard":"def is_coeff_triple(t) -> bool:\n    import numbers\n    return (isinstance(t, (list, tuple)) and len(t) == 3\n            and all(isinstance(v, numbers.Real) and not isinstance(v, bool) for v in t))","tryCatchPattern":null,"preventionTips":["Use built-in preset names instead of hand-written triples","Validate config values are floats, not bools/strings"],"tags":["optimizer","muon","newton-schulz","coefficients","validation"],"backgroundTag":"invalid-argument-shape","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}