{"record":{"id":"25eaf3cb34064a1c","repo":"hpcaitech/Open-Sora","slug":"unexpected-keyword-arguments-kwargs","errorCode":null,"errorMessage":"Unexpected keyword arguments: {kwargs}","messagePattern":"Unexpected keyword arguments: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"opensora/acceleration/checkpoint.py","lineNumber":234,"sourceCode":"    Returns:\n        Output of running :attr:`function` on :attr:`*args`\n    \"\"\"\n    if use_reentrant is None:\n        warnings.warn(\n            \"torch.utils.checkpoint: the use_reentrant parameter should be \"\n            \"passed explicitly. In version 2.4 we will raise an exception \"\n            \"if use_reentrant is not passed. use_reentrant=False is \"\n            \"recommended, but if you need to preserve the current default \"\n            \"behavior, you can pass use_reentrant=True. Refer to docs for more \"\n            \"details on the differences between the two variants.\",\n            stacklevel=2,\n        )\n        use_reentrant = True\n\n    # Hack to mix *args with **kwargs in a python 2.7-compliant way\n    preserve = kwargs.pop(\"preserve_rng_state\", True)\n    if kwargs and use_reentrant:\n        raise ValueError(\"Unexpected keyword arguments: \" + \",\".join(arg for arg in kwargs))\n\n    if use_reentrant:\n        if context_fn is not noop_context_fn or debug is not False:\n            raise ValueError(\"Passing `context_fn` or `debug` is only supported when \" \"use_reentrant=False.\")\n        return CheckpointFunctionWithOffload.apply(function, preserve, *args)\n    else:\n        gen = _checkpoint_without_reentrant_generator(\n            function, preserve, context_fn, determinism_check, debug, *args, **kwargs\n        )\n        # Runs pre-forward logic\n        next(gen)\n        ret = function(*args, **kwargs)\n        # Runs post-forward logic\n        try:\n            next(gen)\n        except StopIteration:\n            return ret\n","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/hpcaitech/Open-Sora/blob/7ad6a96a135feb81f755c84fb391818718f6beb2/opensora/acceleration/checkpoint.py#L216-L252","documentation":"The checkpoint() helper rejects leftover keyword arguments when use_reentrant=True (the default in this code path). Because the reentrant implementation (CheckpointFunctionWithOffload) only supports preserve_rng_state, any other kwarg such as context_fn, debug, or determinism_check cannot be honored and is rejected rather than silently ignored.","triggerScenarios":"Calling checkpoint(fn, *args, context_fn=..., debug=..., determinism_check=...) while use_reentrant defaults/resolves to True; auto_grad_checkpoint and the module's forward pass through this function.","commonSituations":"Copy-pasting non-reentrant checkpoint usage (e.g. from torch.utils.checkpoint docs) into code that runs with use_reentrant=True; upgrading code that previously ignored extra kwargs.","solutions":["Set use_reentrant=False if you need context_fn/debug/determinism_check","Remove the unsupported keyword arguments and keep only preserve_rng_state when reentrant mode is required"],"exampleFix":"# before\ncheckpoint(block, x, context_fn=my_fn, use_reentrant=True)\n# after\ncheckpoint(block, x, context_fn=my_fn, use_reentrant=False)","handlingStrategy":"validation","validationCode":"ALLOWED = {'preserve_rng_state', 'use_reentrant', 'context_fn', 'determinism_check', 'debug'}\nif use_reentrant:\n    bad = set(kwargs) - {'preserve_rng_state'}\n    assert not bad, f'kwargs {bad} require use_reentrant=False'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Centralize checkpoint() calls behind a wrapper that enforces kwarg/mode compatibility","Prefer use_reentrant=False in new code; it supports the full option set"],"tags":["checkpointing","kwargs","pytorch","configuration"],"backgroundTag":"invalid-function-arguments","analyzedSha":"7ad6a96a135feb81f755c84fb391818718f6beb2","analyzedAt":"2026-08-28T16:58:37.171Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}