prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  in utils.subgraph.py  RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)
  ### 🐛 Describe the bug
  
  in utils.subgraph.py
  
  edge_mask = node_mask[edge_index[0]] & node_mask[edge_index[1]]
  
  RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)
  
  because edge_index on 'cuda:0' and node_mask on 'cpu'
  
  being solved with: node_mask=node_mask.to(device=device)
  
  
  
  
  ### Versions
  
  last version
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `torch_geometric/transforms/largest_connected_components.py`
  Content:
  ```
  1 import torch
  2 
  3 from torch_geometric.data import Data
  4 from torch_geometric.data.datapipes import functional_transform
  5 from torch_geometric.transforms import BaseTransform
  6 from torch_geometric.utils import to_scipy_sparse_matrix
  7 
  8 
  9 @functional_transform('largest_connected_components')
  10 class LargestConnectedComponents(BaseTransform):
  11     r"""Selects the subgraph that corresponds to the
  12     largest connected components in the graph
  13     (functional name: :obj:`largest_connected_components`).
  14 
  15     Args:
  16         num_components (int, optional): Number of largest components to keep
  17             (default: :obj:`1`)
  18         connection (str, optional): Type of connection to use for directed
  19             graphs, can be either :obj:`'strong'` or :obj:`'weak'`.
  20             Nodes `i` and `j` are strongly connected if a path
  21             exists both from `i` to `j` and from `j` to `i`. A directed graph
  22             is weakly connected if replacing all of its directed edges with
  23             undirected edges produces a connected (undirected) graph.
  24             (default: :obj:`'weak'`)
  25     """
  26     def __init__(
  27         self,
  28         num_components: int = 1,
  29         connection: str = 'weak',
  30     ) -> None:
  31         assert connection in ['strong', 'weak'], 'Unknown connection type'
  32         self.num_components = num_components
  33         self.connection = connection
  34 
  35     def forward(self, data: Data) -> Data:
  36         import numpy as np
  37         import scipy.sparse as sp
  38 
  39         assert data.edge_index is not None
  40 
  41         adj = to_scipy_sparse_matrix(data.edge_index, num_nodes=data.num_nodes)
  42 
  43         num_components, component = sp.csgraph.connected_components(
  44             adj, connection=self.connection)
  45 
  46         if num_components <= self.num_components:
  47             return data
  48 
  49         _, count = np.unique(component, return_counts=True)
  50         subset = np.in1d(component, count.argsort()[-self.num_components:])
  51 
  52         return data.subgraph(torch.from_numpy(subset).to(torch.bool))
  53 
  54     def __repr__(self) -> str:
  55         return f'{self.__class__.__name__}({self.num_components})'
  56
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/torch_geometric/transforms/largest_connected_components.py b/torch_geometric/transforms/largest_connected_components.py
  --- a/torch_geometric/transforms/largest_connected_components.py
  +++ b/torch_geometric/transforms/largest_connected_components.py
  @@ -47,9 +47,11 @@
               return data
   
           _, count = np.unique(component, return_counts=True)
  -        subset = np.in1d(component, count.argsort()[-self.num_components:])
  +        subset_np = np.in1d(component, count.argsort()[-self.num_components:])
  +        subset = torch.from_numpy(subset_np)
  +        subset = subset.to(data.edge_index.device, torch.bool)
   
  -        return data.subgraph(torch.from_numpy(subset).to(torch.bool))
  +        return data.subgraph(subset)
   
       def __repr__(self) -> str:
           return f'{self.__class__.__name__}({self.num_components})'
  
verification_info: {"golden_diff": "diff --git a/torch_geometric/transforms/largest_connected_components.py b/torch_geometric/transforms/largest_connected_components.py\n--- a/torch_geometric/transforms/largest_connected_components.py\n+++ b/torch_geometric/transforms/largest_connected_components.py\n@@ -47,9 +47,11 @@\n             return data\n \n         _, count = np.unique(component, return_counts=True)\n-        subset = np.in1d(component, count.argsort()[-self.num_components:])\n+        subset_np = np.in1d(component, count.argsort()[-self.num_components:])\n+        subset = torch.from_numpy(subset_np)\n+        subset = subset.to(data.edge_index.device, torch.bool)\n \n-        return data.subgraph(torch.from_numpy(subset).to(torch.bool))\n+        return data.subgraph(subset)\n \n     def __repr__(self) -> str:\n         return f'{self.__class__.__name__}({self.num_components})'\n", "issue": "in utils.subgraph.py  RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)\n### \ud83d\udc1b Describe the bug\n\nin utils.subgraph.py\r\n\r\nedge_mask = node_mask[edge_index[0]] & node_mask[edge_index[1]]\r\n\r\nRuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)\r\n\r\nbecause edge_index on 'cuda:0' and node_mask on 'cpu'\r\n\r\nbeing solved with: node_mask=node_mask.to(device=device)\r\n\r\n\r\n\n\n### Versions\n\nlast version\n", "before_files": [{"content": "import torch\n\nfrom torch_geometric.data import Data\nfrom torch_geometric.data.datapipes import functional_transform\nfrom torch_geometric.transforms import BaseTransform\nfrom torch_geometric.utils import to_scipy_sparse_matrix\n\n\n@functional_transform('largest_connected_components')\nclass LargestConnectedComponents(BaseTransform):\n    r\"\"\"Selects the subgraph that corresponds to the\n    largest connected components in the graph\n    (functional name: :obj:`largest_connected_components`).\n\n    Args:\n        num_components (int, optional): Number of largest components to keep\n            (default: :obj:`1`)\n        connection (str, optional): Type of connection to use for directed\n            graphs, can be either :obj:`'strong'` or :obj:`'weak'`.\n            Nodes `i` and `j` are strongly connected if a path\n            exists both from `i` to `j` and from `j` to `i`. A directed graph\n            is weakly connected if replacing all of its directed edges with\n            undirected edges produces a connected (undirected) graph.\n            (default: :obj:`'weak'`)\n    \"\"\"\n    def __init__(\n        self,\n        num_components: int = 1,\n        connection: str = 'weak',\n    ) -> None:\n        assert connection in ['strong', 'weak'], 'Unknown connection type'\n        self.num_components = num_components\n        self.connection = connection\n\n    def forward(self, data: Data) -> Data:\n        import numpy as np\n        import scipy.sparse as sp\n\n        assert data.edge_index is not None\n\n        adj = to_scipy_sparse_matrix(data.edge_index, num_nodes=data.num_nodes)\n\n        num_components, component = sp.csgraph.connected_components(\n            adj, connection=self.connection)\n\n        if num_components <= self.num_components:\n            return data\n\n        _, count = np.unique(component, return_counts=True)\n        subset = np.in1d(component, count.argsort()[-self.num_components:])\n\n        return data.subgraph(torch.from_numpy(subset).to(torch.bool))\n\n    def __repr__(self) -> str:\n        return f'{self.__class__.__name__}({self.num_components})'\n", "path": "torch_geometric/transforms/largest_connected_components.py"}], "after_files": [{"content": "import torch\n\nfrom torch_geometric.data import Data\nfrom torch_geometric.data.datapipes import functional_transform\nfrom torch_geometric.transforms import BaseTransform\nfrom torch_geometric.utils import to_scipy_sparse_matrix\n\n\n@functional_transform('largest_connected_components')\nclass LargestConnectedComponents(BaseTransform):\n    r\"\"\"Selects the subgraph that corresponds to the\n    largest connected components in the graph\n    (functional name: :obj:`largest_connected_components`).\n\n    Args:\n        num_components (int, optional): Number of largest components to keep\n            (default: :obj:`1`)\n        connection (str, optional): Type of connection to use for directed\n            graphs, can be either :obj:`'strong'` or :obj:`'weak'`.\n            Nodes `i` and `j` are strongly connected if a path\n            exists both from `i` to `j` and from `j` to `i`. A directed graph\n            is weakly connected if replacing all of its directed edges with\n            undirected edges produces a connected (undirected) graph.\n            (default: :obj:`'weak'`)\n    \"\"\"\n    def __init__(\n        self,\n        num_components: int = 1,\n        connection: str = 'weak',\n    ) -> None:\n        assert connection in ['strong', 'weak'], 'Unknown connection type'\n        self.num_components = num_components\n        self.connection = connection\n\n    def forward(self, data: Data) -> Data:\n        import numpy as np\n        import scipy.sparse as sp\n\n        assert data.edge_index is not None\n\n        adj = to_scipy_sparse_matrix(data.edge_index, num_nodes=data.num_nodes)\n\n        num_components, component = sp.csgraph.connected_components(\n            adj, connection=self.connection)\n\n        if num_components <= self.num_components:\n            return data\n\n        _, count = np.unique(component, return_counts=True)\n        subset_np = np.in1d(component, count.argsort()[-self.num_components:])\n        subset = torch.from_numpy(subset_np)\n        subset = subset.to(data.edge_index.device, torch.bool)\n\n        return data.subgraph(subset)\n\n    def __repr__(self) -> str:\n        return f'{self.__class__.__name__}({self.num_components})'\n", "path": "torch_geometric/transforms/largest_connected_components.py"}]}