{"record":{"id":"11d8e1a1a5b1e3f4","repo":"huggingface/pytorch-image-models","slug":"unknown-mode-mode","errorCode":null,"errorMessage":"Unknown mode: {mode}","messagePattern":"Unknown mode: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"timm/optim/muon.py","lineNumber":365,"sourceCode":"    \"\"\"\n    original_shape = tensor.shape\n    if tensor.ndim == 2:\n        return tensor, original_shape\n    if tensor.ndim < 2:\n        raise ValueError(f\"Tensor must have at least 2 dimensions, got {tensor.ndim}\")\n\n    out_ch, in_ch = tensor.shape[:2]\n    if mode == \"flatten\":\n        # Flatten: (out, in, *spatial) -> (out, in * spatial_prod)\n        return tensor.reshape(out_ch, -1), original_shape\n    elif mode == \"batched\":\n        # Batched: (out, in, *spatial) -> (spatial_prod, out, in)\n        # Move spatial dimension to front so zeropower_via_newtonschulz batches over it\n        reshaped = tensor.reshape(out_ch, in_ch, -1)  # (out, in, spatial_prod)\n        reshaped = reshaped.permute(2, 0, 1)  # (spatial_prod, out, in)\n        return reshaped, original_shape\n    else:\n        raise ValueError(f\"Unknown mode: {mode}\")\n\n\ndef muon(\n        params: List[torch.Tensor],\n        grads: List[torch.Tensor],\n        momentum_bufs: List[torch.Tensor],\n        *,\n        lr: float,\n        weight_decay: float,\n        momentum: float,\n        nesterov: bool,\n        ns_steps: int,\n        ns_coefficients: NSCoeff,\n        eps: float,\n        safety_factor: float,\n        adjust_lr_fn: Optional[str],\n        conv_mode: str,\n        normalize_spatial: bool,","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/optim/muon.py#L347-L383","documentation":"reshape_for_muon accepts only mode=\"flatten\" or mode=\"batched\" for reshaping >2-D conv weights; any other string raises this ValueError.","triggerScenarios":"Calling reshape_for_muon(t, mode='reshape') or constructing Muon(conv_mode='flatten'/'batched' but passing a different mode string to the internal helper, or a typo like 'flat'.","commonSituations":"Typos in mode strings; code written against an older/newer API with different mode names.","solutions":["Use \"flatten\" or \"batched\" (these are also the valid conv_mode values of the Muon constructor)","Set conv_mode on the Muon optimizer rather than calling the helper with an ad-hoc mode"],"exampleFix":"# before\nreshape_for_muon(conv_weight, mode=\"flat\")\n# after\nreshape_for_muon(conv_weight, mode=\"flatten\")","handlingStrategy":"validation","validationCode":"assert mode in (\"flatten\", \"batched\")","typeGuard":"def is_valid_mode(m: str) -> bool:\n    return m in (\"flatten\", \"batched\")","tryCatchPattern":null,"preventionTips":["Prefer setting conv_mode on the Muon constructor over calling the helper directly","Use constants for mode strings"],"tags":["optimizer","muon","enum-validation"],"backgroundTag":"invalid-enum-argument","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}