{"record":{"id":"ac1f6c816a18b37b","repo":"huggingface/pytorch-image-models","slug":"api-has-changed-state-steps-argument-must-conta-ac1f6c","errorCode":null,"errorMessage":"API has changed, `state_steps` argument must contain a list of singleton tensors","messagePattern":"API has changed, `state_steps` argument must contain a list of singleton tensors","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"timm/optim/nadamw.py","lineNumber":186,"sourceCode":"        state_steps: List[Tensor],\n        foreach: Optional[bool] = None,\n        capturable: bool = False,\n        *,\n        beta1: float,\n        beta2: float,\n        lr: float,\n        weight_decay: float,\n        eps: float,\n        caution: bool,\n        maximize: bool,\n        max_lr: Optional[float],\n) -> None:\n    r\"\"\"Functional API that performs NAdamW algorithm computation.\n      See NAdamW class for details.\n    \"\"\"\n\n    if not all(isinstance(t, torch.Tensor) for t in state_steps):\n        raise RuntimeError(\n            'API has changed, `state_steps` argument must contain a list of' +\n            ' singleton tensors')\n\n    if foreach is None:\n        try:\n            # cannot do foreach if this overload doesn't exist when caution enabled\n            foreach = not caution or 'Scalar' in torch.ops.aten._foreach_maximum_.overloads()\n            # Match native PyTorch: tensor lr without capturable mode is supported by the single-tensor path.\n            if foreach and torch.is_tensor(lr) and not capturable:\n                foreach = False\n        except Exception:\n            foreach = False\n\n    if foreach and not torch.jit.is_scripting():\n        func = _multi_tensor_nadamw\n    else:\n        func = _single_tensor_nadamw\n","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/huggingface/pytorch-image-models/blob/9a5261e31b3b5128526eb2658333b4c0a54464ae/timm/optim/nadamw.py#L168-L204","documentation":"RuntimeError from the functional nadamw() API: every element of state_steps must be a torch.Tensor (singleton step counters). This mirrors an upstream PyTorch optimizer-API change from plain ints to tensors for capturable/foreach support.","triggerScenarios":"Calling timm.optim.nadamw.functional_nadamw(...) (or NadamW class internals) with state_steps as a list of Python ints instead of tensors.","commonSituations":"Custom training loops calling the functional API directly with hand-built state, or old code written against the pre-tensor state_steps API after upgrading timm/PyTorch.","solutions":["Convert steps to tensors: state_steps=[torch.tensor(0.0) for _ in params] and increment in-place via step += 1","Prefer using the NAdamW class .step() rather than the functional API unless you need custom control","Check timm version changelog if migrating old functional-API code"],"exampleFix":"# before\nfunctional_nadamw(params, grads, exp_avgs, exp_avg_sqs, [0, 0], ...)\n\n# after\nfunctional_nadamw(params, grads, exp_avgs, exp_avg_sqs, [torch.zeros(()) for _ in params], ...)","handlingStrategy":"type-guard","validationCode":"import torch\nassert all(isinstance(s, torch.Tensor) for s in state_steps)","typeGuard":"def steps_are_tensors(steps) -> bool:\n    import torch\n    return all(isinstance(s, torch.Tensor) for s in steps)","tryCatchPattern":null,"preventionTips":["Prefer the NAdamW class API over functional calls","Initialize state['step'] as torch.tensor(0.0) in custom loops"],"tags":["timm","nadamw","functional-api","state-steps","pytorch-version-change"],"backgroundTag":"optimizer-api-state-steps-tensor","analyzedSha":"9a5261e31b3b5128526eb2658333b4c0a54464ae","analyzedAt":"2026-08-27T02:34:25.417Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}