def METHOD_NAME(x):
    if torch.is_tensor(x):
        return f(x)
    elif isinstance(x, collections.OrderedDict):
        # OrderedDict has attributes that needs to be preserved
        od = collections.OrderedDict(
            (key, METHOD_NAME(value)) for key, value in x.items())
        od.__dict__ = x.__dict__
        return od
    elif isinstance(x, dict):
        return {key: METHOD_NAME(value) for key, value in x.items()}
    elif isinstance(x, list):
        return [METHOD_NAME(x) for x in x]
    elif isinstance(x, tuple):
        return tuple(METHOD_NAME(x) for x in x)
    elif isinstance(x, set):
        return {METHOD_NAME(x) for x in x}
    else:
        return x