def remove_getattr_nodes(graph: InternalTorchIRGraph) -> None:
    """
    Remove the getattr nodes in the graph
    """

    getattr_nodes = []
    new_nodes = []

    for node in graph.nodes:

        for block in node.blocks:
            remove_getattr_nodes(block)

        if node.kind == "getattr":
            getattr_nodes.append(node)
        else:
            new_nodes.append(node)

    # check the getattr nodes not in the outputs
    for node in getattr_nodes:
        if node.name in graph.outputs:
            raise RuntimeError("{} should not be in the graph outputs.".format(node.name))

    # remove the getattr nodes
    graph.nodes = new_nodes

    Remove the getattr nodes in the graph
    
coremltools/converters/mil/frontend/torch/torchir_passes.py