def map_tensor_metadata(a: Any, fn: Callable):
    """
    Map some `fn` to `a`, where `a` is either a TensorMetadata, or else a tuple/list/dict
    recursively containing TensorMetadata.
    """
    if isinstance(a, int):
        return 1
    elif a is None:
        return 1
    elif isinstance(a, TensorMetadata):
        return fn(a)
    elif isinstance(a, tuple):
        return tuple(map_tensor_metadata(elem, fn) for elem in a)
    elif isinstance(a, dict):
        return immutable_dict(
            {name: map_tensor_metadata(elem, fn) for name, elem in a.items()}
        )
    assert isinstance(
        a, list
    ), f"Only supporting tuple/list/TensorMetadata, but found {type(a)}"
    return immutable_list(map_tensor_metadata(elem, fn) for elem in a)

    Map some `fn` to `a`, where `a` is either a TensorMetadata, or else a tuple/list/dict
    recursively containing TensorMetadata.
    
fx2ait/fx2ait/acc_tracer/acc_utils.py