{"record":{"id":"5374db419e87d6e7","repo":"huggingface/pytorch-image-models","slug":"preset-value-is-empty-or-invalid","errorCode":null,"errorMessage":"Preset '{value}' is empty or invalid","messagePattern":"Preset '(.+?)' is empty or invalid","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"timm/optim/muon.py","lineNumber":1035,"sourceCode":"        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\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))","sourceCodeStart":1017,"sourceCodeEnd":1053,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/optim/muon.py#L1017-L1053","documentation":"Thrown by resolve_ns_coefficients in timm's Muon optimizer when a named Nesterov-style coefficients preset exists in the presets dict but maps to an empty or non-sequence value. It is a data-integrity check on the internal presets table, guarding before attempting to iterate the preset's items.","triggerScenarios":"Passing ns_coefficients='preset_name' to timm.optim.Muon/AdamMuon where the presets dict entry for that name is empty ([]) or not a sequence (e.g. None or a scalar).","commonSituations":"Custom/monkeypatched presets tables, stale forks where a preset was emptied, or programmatic preset generation that produced an empty list.","solutions":["Use a well-known built-in preset name (print/inspect the presets dict to see valid entries)","If defining custom presets, ensure each value is a non-empty sequence of 3-sequences","Pass explicit coefficients as a (a,b,c) tuple or list of triples instead of a preset name"],"exampleFix":"# before\nopt = Muon(params, ns_coefficients='my_preset')  # preset entry is []\n\n# after\nopt = Muon(params, ns_coefficients=[(0.1, 0.5, 0.9)])","handlingStrategy":"validation","validationCode":"from timm.optim.muon import NS_COEFFICIENT_PRESETS  # inspect presets dict\nname = 'my_preset'\nassert name in NS_COEFFICIENT_PRESETS and len(NS_COEFFICIENT_PRESETS[name]) > 0","typeGuard":"def valid_preset(name: str, presets: dict) -> bool:\n    seq = presets.get(name)\n    return isinstance(seq, (list, tuple)) and len(seq) > 0","tryCatchPattern":null,"preventionTips":["Inspect the presets dict before referencing a preset name","Keep custom presets non-empty sequences of triples"],"tags":["timm","muon-optimizer","preset-validation","valueerror"],"backgroundTag":"invalid-optimizer-argument","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}