def _check_bad_cuda_fork() -> None:
    """Checks whether it is safe to fork and initialize CUDA in the new processes, and raises an exception if not.

    The error message replaces PyTorch's 'Cannot re-initialize CUDA in forked subprocess' with helpful advice for
    Lightning users.

    """
    if not torch.cuda.is_initialized():
        return

    message = (
        "Lightning can't create new processes if CUDA is already initialized. Did you manually call"
        " `torch.cuda.*` functions, have moved the model to the device, or allocated memory on the GPU any"
        " other way? Please remove any such calls, or change the selected strategy."
    )
    if _IS_INTERACTIVE:
        message += " You will have to restart the Python kernel."
    raise RuntimeError(message)
Checks whether it is safe to fork and initialize CUDA in the new processes, and raises an exception if not.

    The error message replaces PyTorch's 'Cannot re-initialize CUDA in forked subprocess' with helpful advice for
    Lightning users.

    
src/lightning/fabric/strategies/launchers/multiprocessing.py