Repository: pyg-team/pytorch_geometric
Pull request #7363 (2023-05-13 20:13:48)

Do not modify input in-place in `to_hetero_with_bases`

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7363?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) Report
> Merging [#7363](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7363?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (5b97546) into [master](https://app.codecov.io/gh/pyg-team/pytorch_geometric/commit/5959fedb25d3c4cbc913ab8e22dd3453d9f30c4f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (5959fed) will **decrease** coverage by `0.01%`.
> The diff coverage is `100.00%`.

> :exclamation: Current head 5b97546 differs from pull request most recent head d1a23e0. Consider uploading reports for the commit d1a23e0 to get more accurate results

```diff
@@            Coverage Diff             @@
##           master    #7363      +/-   ##
==========================================
- Coverage   91.52%   91.52%   -0.01%     
==========================================
  Files         438      438              
  Lines       24364    24362       -2     
==========================================
- Hits        22299    22297       -2     
  Misses       2065     2065              
```


| [Impacted Files](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7363?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) | Coverage Δ | |
|---|---|---|
| [...h\_geometric/nn/to\_hetero\_with\_bases\_transformer.py](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7363?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team#diff-dG9yY2hfZ2VvbWV0cmljL25uL3RvX2hldGVyb193aXRoX2Jhc2VzX3RyYW5zZm9ybWVyLnB5) | `95.28% <100.00%> (-0.05%)` | :arrow_down: |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team)


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 36c331f2b..6fb004059 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -40,6 +40,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 
 ### Changed
 
+- Fixed a bug in which inputs where modified in-place in `to_hetero_with_bases` ([#7363](https://github.com/pyg-team/pytorch_geometric/pull/7363))
 - Do not load `node_default` and `edge_default` attributes in `from_networkx` ([#7348](https://github.com/pyg-team/pytorch_geometric/pull/7348))
 - Updated examples to use `NeighborLoader` instead of `NeighborSampler` ([#7152](https://github.com/pyg-team/pytorch_geometric/pull/7152))
 - Fixed `HGTConv` utility function `_construct_src_node_feat` ([#7194](https://github.com/pyg-team/pytorch_geometric/pull/7194))
diff --git a/torch_geometric/nn/to_hetero_with_bases_transformer.py b/torch_geometric/nn/to_hetero_with_bases_transformer.py
index 93c71c571..726f1634b 100644
--- a/torch_geometric/nn/to_hetero_with_bases_transformer.py
+++ b/torch_geometric/nn/to_hetero_with_bases_transformer.py
@@ -393,10 +393,7 @@ class LinearAlign(torch.nn.Module):
     def forward(
         self, x_dict: Dict[Union[NodeType, EdgeType], Tensor]
     ) -> Dict[Union[NodeType, EdgeType], Tensor]:
-
-        for key, x in x_dict.items():
-            x_dict[key] = self.lins[key2str(key)](x)
-        return x_dict
+        return {key: self.lins[key2str(key)](x) for key, x in x_dict.items()}
 
     def __repr__(self) -> str:
         return (f'{self.__class__.__name__}(num_relations={len(self.lins)}, '


Test patch:
diff --git a/test/nn/test_to_hetero_with_bases_transformer.py b/test/nn/test_to_hetero_with_bases_transformer.py
index b26871a30..6f40f0cb2 100644
--- a/test/nn/test_to_hetero_with_bases_transformer.py
+++ b/test/nn/test_to_hetero_with_bases_transformer.py
@@ -152,7 +152,7 @@ def test_to_hetero_with_bases():
     assert isinstance(out, dict) and len(out) == 2
     assert out['paper'].size() == (100, 32)
     assert out['author'].size() == (100, 32)
-    assert sum(p.numel() for p in model.parameters()) == 6076
+    assert sum(p.numel() for p in model.parameters()) == 5948
 
     model = Net3()
     in_channels = {'x': 16, 'edge_attr': 8}
@@ -164,7 +164,7 @@ def test_to_hetero_with_bases():
     assert out['author'].size() == (100, 32)
 
     model = Net4()
-    in_channels = {'x': 16}
+    in_channels = {'x0': 16}
     model = to_hetero_with_bases(model, metadata, num_bases=4,
                                  in_channels=in_channels, debug=False)
     out = model(x_dict, edge_index_dict)