hpcaitech/Open-Sora · error · ValueError

Unexpected keyword arguments: {kwargs}

Error message

Unexpected keyword arguments: {kwargs}

What it means

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.

Source

Thrown at opensora/acceleration/checkpoint.py:234

    Returns:
        Output of running :attr:`function` on :attr:`*args`
    """
    if use_reentrant is None:
        warnings.warn(
            "torch.utils.checkpoint: the use_reentrant parameter should be "
            "passed explicitly. In version 2.4 we will raise an exception "
            "if use_reentrant is not passed. use_reentrant=False is "
            "recommended, but if you need to preserve the current default "
            "behavior, you can pass use_reentrant=True. Refer to docs for more "
            "details on the differences between the two variants.",
            stacklevel=2,
        )
        use_reentrant = True

    # Hack to mix *args with **kwargs in a python 2.7-compliant way
    preserve = kwargs.pop("preserve_rng_state", True)
    if kwargs and use_reentrant:
        raise ValueError("Unexpected keyword arguments: " + ",".join(arg for arg in kwargs))

    if use_reentrant:
        if context_fn is not noop_context_fn or debug is not False:
            raise ValueError("Passing `context_fn` or `debug` is only supported when " "use_reentrant=False.")
        return CheckpointFunctionWithOffload.apply(function, preserve, *args)
    else:
        gen = _checkpoint_without_reentrant_generator(
            function, preserve, context_fn, determinism_check, debug, *args, **kwargs
        )
        # Runs pre-forward logic
        next(gen)
        ret = function(*args, **kwargs)
        # Runs post-forward logic
        try:
            next(gen)
        except StopIteration:
            return ret

View on GitHub (pinned to 7ad6a96a13)

Solutions

  1. Set use_reentrant=False if you need context_fn/debug/determinism_check
  2. Remove the unsupported keyword arguments and keep only preserve_rng_state when reentrant mode is required

Example fix

# before
checkpoint(block, x, context_fn=my_fn, use_reentrant=True)
# after
checkpoint(block, x, context_fn=my_fn, use_reentrant=False)
Defensive patterns

Strategy: validation

Validate before calling

ALLOWED = {'preserve_rng_state', 'use_reentrant', 'context_fn', 'determinism_check', 'debug'}
if use_reentrant:
    bad = set(kwargs) - {'preserve_rng_state'}
    assert not bad, f'kwargs {bad} require use_reentrant=False'

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hpcaitech/Open-Sora@7ad6a96a13 (2026-08-28). Data as JSON: /api/errors/25eaf3cb34064a1c. Report an issue: GitHub.