(func, src_type, dst_type, convert_output=True)
return new_forward
Patch the forward method of a module.

    Args:
        func (callable): The original forward method.
        src_type (torch.dtype): Type of input arguments to be converted from.
        dst_type (torch.dtype): Type of input arguments to be converted to.
        convert_output (bool): Whether to convert the output back to src_type.

    Returns:
        callable: The patched forward method.
Patch the forward method of a module.
Patch the forward method of a module .
def patch_forward_method(func, src_type, dst_type, convert_output=True):
    """Patch the forward method of a module.

    Args:
        func (callable): The original forward method.
        src_type (torch.dtype): Type of input arguments to be converted from.
        dst_type (torch.dtype): Type of input arguments to be converted to.
        convert_output (bool): Whether to convert the output back to src_type.

    Returns:
        callable: The patched forward method.
    """

    def new_forward(*args, **kwargs):
        output = func(*cast_tensor_type(args, src_type, dst_type),
                      **cast_tensor_type(kwargs, src_type, dst_type))
        if convert_output:
            output = cast_tensor_type(output, dst_type, src_type)
        return output

    return new_forward
def patch_forward_method ( func , src_type , dst_type , convert_output = True ) : def new_forward ( * args , * * kwargs ) : output = func ( * cast_tensor_type ( args , src_type , dst_type ) , * * cast_tensor_type ( kwargs , src_type , dst_type ) ) if convert_output : output = cast_tensor_type ( output , dst_type , src_type ) return output return new_forward