def _replace_node_module(self, node: _torch.fx.Node, repl: _torch.nn.Module):
        """
        Method which takes in an input node and replacement module, and properly
        replaces the input node in the graph with a new node created for the
        replacement module. Preserves the node name. Intended to be a subgraph
        replacement with no global effect on the rest of the graph.
        """

        with self.graph_module.graph.inserting_after(node):
            # TODO: Check if node_name is correct for call_module function
            # Looks like "qualified" name needed here for the target parameter
            # https://pytorch.org/docs/stable/fx.html#torch.fx.Graph.call_module
            node_name = node.name
            self.model.__setattr__(node_name, repl)
            self.graph_module.__setattr__(node_name, repl)
            new_args = node.args if node.op == "call_module" else (node.args[0],)
            new_node = self.graph_module.graph.call_module(node_name, args=new_args)
            node.replace_all_uses_with(new_node)
            self.graph_module.graph.erase_node(node)
            new_node.name = node_name

        Method which takes in an input node and replacement module, and properly
        replaces the input node in the graph with a new node created for the
        replacement module. Preserves the node name. Intended to be a subgraph
        replacement with no global effect on the rest of the graph.
        
coremltools/optimize/torch/_utils/graph_utils.py