{"record":{"id":"7585f52949a43730","repo":"huggingface/pytorch-image-models","slug":"coefficients-must-be-a-preset-name-str-a-3-sequ","errorCode":null,"errorMessage":"Coefficients must be a preset name (str), a 3-sequence (a,b,c), or a sequence of 3-sequences.","messagePattern":"Coefficients must be a preset name \\(str\\), a 3-sequence \\(a,b,c\\), or a sequence of 3-sequences\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"timm/optim/muon.py","lineNumber":1039,"sourceCode":"    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\n    # Decide single triple vs list-of-triples by structure\n    if len(value) == 3 and all(is_real(v) for v in value):  # type: ignore[index]\n        return [as_coeff(value)]  # single triple -> wrap\n\n    # Otherwise treat as list/tuple of triples\n    out = []\n    for i, item in enumerate(value):  # type: ignore[assignment]\n        if not is_seq(item):\n            raise TypeError(f\"Item {i} is not a sequence: {item!r}\")\n        out.append(as_coeff(item))\n    if not out:\n        raise ValueError(\"Coefficient list cannot be empty\")\n    return out\n","sourceCodeStart":1021,"sourceCodeEnd":1057,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/optim/muon.py#L1021-L1057","documentation":"Thrown by resolve_ns_coefficients in timm's Muon optimizer when the ns_coefficients argument is neither a string preset name nor a sequence. The API accepts only a preset name, a single 3-sequence (a,b,c), or a sequence of 3-sequences.","triggerScenarios":"Passing a scalar (ns_coefficients=0.5), None, or any non-iterable to timm.optim.Muon/AdamMuon's ns_coefficients parameter.","commonSituations":"Assuming ns_coefficients takes a single float, passing an uninitialized None default, or passing a dict of coefficients.","solutions":["Pass a preset name string, e.g. ns_coefficients='nesterov'","Pass a single triple: ns_coefficients=(0.9, 0.999, 1e-8) style (a,b,c)","Pass a list of triples for per-tensor coefficients"],"exampleFix":"# before\nMuon(params, ns_coefficients=0.9)\n\n# after\nMuon(params, ns_coefficients=(0.9, 0.95, 0.5))","handlingStrategy":"type-guard","validationCode":"from collections.abc import Sequence\nassert isinstance(ns_coefficients, (str, Sequence)), 'ns_coefficients must be str preset or sequence'","typeGuard":"def is_valid_coeffs(v) -> bool:\n    return isinstance(v, str) or (isinstance(v, (list, tuple)) and not isinstance(v, str))","tryCatchPattern":null,"preventionTips":["Pass explicit tuples like (a, b, c) or lists of triples","Avoid scalars/None for ns_coefficients"],"tags":["timm","muon-optimizer","typeerror","argument-validation"],"backgroundTag":"invalid-optimizer-argument","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}