def fp8_autocast(
    enabled: bool = False,
    calibrating: bool = False,
    fp8_recipe: Optional[DelayedScaling] = None,
    device: str = "cpu",
) -> None:
    """
    Context manager for FP8 usage.

    .. code-block:: python

        with fp8_autocast(enabled=True):
            out = model(inp)

    Parameters
    ----------
    enabled: bool, default = `True`
             whether or not to enable fp8
    calibrating: bool, default = `False`
                 calibration mode allows collecting statistics such as amax and scale
                 data of fp8 tensors even when executing without fp8 enabled.
    fp8_recipe: recipe.DelayedScaling, default = `None`
                recipe used for FP8 training.
    """
    global _FP8_ENABLED, _FP8_RECIPE, _FP8_CALIBRATION, _FP8_DEVICE
    fp8_state = (_FP8_ENABLED, _FP8_RECIPE, _FP8_CALIBRATION, _FP8_DEVICE)
    try:
        _FP8_ENABLED = enabled
        _FP8_RECIPE = get_default_fp8_recipe() if fp8_recipe is None else fp8_recipe
        _FP8_CALIBRATION = calibrating
        _FP8_DEVICE = device
        yield
    finally:
        _FP8_ENABLED, _FP8_RECIPE, _FP8_CALIBRATION, _FP8_DEVICE = fp8_state

    Context manager for FP8 usage.

    .. code-block:: python

        with fp8_autocast(enabled=True):
            out = model(inp)

    Parameters
    ----------
    enabled: bool, default = `True`
             whether or not to enable fp8
    calibrating: bool, default = `False`
                 calibration mode allows collecting statistics such as amax and scale
                 data of fp8 tensors even when executing without fp8 enabled.
    fp8_recipe: recipe.DelayedScaling, default = `None`
                recipe used for FP8 training.
    
intel_extension_for_pytorch/quantization/fp8/fp8.py