def METHOD_NAME(cls, training_step_output: STEP_OUTPUT) -> "ManualResult":
    extra = {}
    if isinstance(training_step_output, dict):
        extra = training_step_output.copy()
    elif isinstance(training_step_output, Tensor):
        extra = {"loss": training_step_output}
    elif training_step_output is not None:
        raise MisconfigurationException(
            "In manual optimization, `training_step` must either return a Tensor or have no return."
        )
    if "loss" in extra:
        # we detach manually as it's expected that it will have a `grad_fn`
        extra["loss"] = extra["loss"].detach()
    return cls(extra=extra)