def optimizer_fusion(optimizer, device_type, user_explict_fuse):
    r"""
    Patch "step" method to choose IPEX optimized fused update kernel.
    """

    if not hasattr(optimizer, "params_attr"):
        setattr(optimizer, "params_attr", {})  # noqa: B010
    try:
        if device_type == "cpu":
            step = OPTIMIZER_FUSED_STEP_MAPPING_CPU[type(optimizer)]
        elif device_type == "xpu":
            step = OPTIMIZER_FUSED_STEP_MAPPING_XPU[type(optimizer)]
        else:
            msg = (
                "IPEX does not support device type "
                + str(device_type)
                + ". For now, only support CPU, XPU."
            )
            warn_if_user_explicitly_set(user_explict_fuse, msg)
            return optimizer
        if not hasattr(optimizer, "_original_step"):
            setattr(optimizer, "_original_step", optimizer.step)  # noqa: B010
        optimizer.step = types.MethodType(step, optimizer)
        setattr(optimizer, "fused", True)  # noqa: B010
    except KeyError:
        msg = (
            "Does not suport fused step for "
            + str(type(optimizer))
            + ", will use non-fused step"
        )
        warn_if_user_explicitly_set(user_explict_fuse, msg)
    return optimizer

    Patch "step" method to choose IPEX optimized fused update kernel.
    
intel_extension_for_pytorch/optim/_optimizer_utils.py