huggingface/pytorch-image-models · error · ValueError
Preset '{value}' is empty or invalid
Error message
Preset '{value}' is empty or invalid What it means
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.
Source
Thrown at timm/optim/muon.py:1035
presets: Mapping[str, Sequence[Sequence[float]]]
) -> List[Tuple[float, float, float]]:
# tiny helpers (kept inline for succinctness)
is_seq = lambda x: isinstance(x, Sequence) and not isinstance(x, (str, bytes))
is_real = lambda x: isinstance(x, numbers.Real) and not isinstance(x, bool)
def as_coeff(x: Sequence[float]) -> Tuple[float, float, float]:
if not is_seq(x) or len(x) != 3 or not all(is_real(v) for v in x):
raise ValueError(f"Coefficient must be length-3 of real numbers, got: {x!r}")
a, b, c = x # type: ignore[misc]
return float(a), float(b), float(c)
if isinstance(value, str):
if value not in presets:
valid = ", ".join(sorted(presets.keys()))
raise ValueError(f"Unknown coefficients preset '{value}'. Valid options: {valid}")
seq = presets[value]
if not is_seq(seq) or len(seq) == 0:
raise ValueError(f"Preset '{value}' is empty or invalid")
return [as_coeff(item) for item in seq] # validate & cast
if not is_seq(value):
raise TypeError(
"Coefficients must be a preset name (str), a 3-sequence (a,b,c), "
"or a sequence of 3-sequences."
)
# Decide single triple vs list-of-triples by structure
if len(value) == 3 and all(is_real(v) for v in value): # type: ignore[index]
return [as_coeff(value)] # single triple -> wrap
# Otherwise treat as list/tuple of triples
out = []
for i, item in enumerate(value): # type: ignore[assignment]
if not is_seq(item):
raise TypeError(f"Item {i} is not a sequence: {item!r}")
out.append(as_coeff(item))View on GitHub (pinned to 9a5261e31b)
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
Example fix
# before opt = Muon(params, ns_coefficients='my_preset') # preset entry is [] # after opt = Muon(params, ns_coefficients=[(0.1, 0.5, 0.9)])
Defensive patterns
Strategy: validation
Validate before calling
from timm.optim.muon import NS_COEFFICIENT_PRESETS # inspect presets dict name = 'my_preset' assert name in NS_COEFFICIENT_PRESETS and len(NS_COEFFICIENT_PRESETS[name]) > 0
Type guard
def valid_preset(name: str, presets: dict) -> bool:
seq = presets.get(name)
return isinstance(seq, (list, tuple)) and len(seq) > 0 Prevention
- Inspect the presets dict before referencing a preset name
- Keep custom presets non-empty sequences of triples
When it happens
Trigger: 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).
Common situations: Custom/monkeypatched presets tables, stale forks where a preset was emptied, or programmatic preset generation that produced an empty list.
Related errors
- Coefficient list cannot be empty
- Coefficients must be a preset name (str), a 3-sequence (a,b,
- Item {i} is not a sequence: {item!r}
- Invalid learning rate: {}
- Invalid learning rate: {lr}
AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27).
Data as JSON: /api/errors/5374db419e87d6e7.
Report an issue: GitHub.