Repository: pyg-team/pytorch_geometric
Pull request #7923 (2023-08-24 05:41:34)

Fix `bias_initializer` in `HeteroLinear`

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

> :exclamation: Current head ea4da33 differs from pull request most recent head 35bc271. Consider uploading reports for the commit 35bc271 to get more accurate results

```diff
@@            Coverage Diff             @@
##           master    #7923      +/-   ##
==========================================
- Coverage   89.35%   89.34%   -0.01%     
==========================================
  Files         457      457              
  Lines       26857    26857              
==========================================
- Hits        23997    23996       -1     
- Misses       2860     2861       +1     
```


| [Files Changed](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7923?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) | Coverage Δ | |
|---|---|---|
| [torch\_geometric/nn/dense/linear.py](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7923?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team#diff-dG9yY2hfZ2VvbWV0cmljL25uL2RlbnNlL2xpbmVhci5weQ==) | `88.99% <100.00%> (ø)` | |

... and [2 files with indirect coverage changes](https://app.codecov.io/gh/pyg-team/pytorch_geometric/pull/7923/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team)

: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 968fa1e51..4946196c0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -87,6 +87,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 
 ### Changed
 
+- Fixed the usage of `bias_initializer` in `HeteroLinear` ([#7923](https://github.com/pyg-team/pytorch_geometric/pull/7923))
 - Fixed broken links in `HGBDataset` ([#7907](https://github.com/pyg-team/pytorch_geometric/pull/7907))
 - Fixed an issue where `SetTransformerAggregation` produced `NaN` values for isolates nodes ([#7902](https://github.com/pyg-team/pytorch_geometric/pull/7902))
 - Fixed `model_summary` on modules with uninitialized parameters ([#7884](https://github.com/pyg-team/pytorch_geometric/pull/7884))
diff --git a/torch_geometric/nn/dense/linear.py b/torch_geometric/nn/dense/linear.py
index 05900aac1..d7804c12d 100644
--- a/torch_geometric/nn/dense/linear.py
+++ b/torch_geometric/nn/dense/linear.py
@@ -249,8 +249,8 @@ class HeteroLinear(torch.nn.Module):
         r"""Resets all learnable parameters of the module."""
         reset_weight_(self.weight, self.in_channels,
                       self.kwargs.get('weight_initializer', None))
-        reset_weight_(self.bias, self.in_channels,
-                      self.kwargs.get('bias_initializer', None))
+        reset_bias_(self.bias, self.in_channels,
+                    self.kwargs.get('bias_initializer', None))
 
     def forward(self, x: Tensor, type_vec: Tensor) -> Tensor:
         r"""


Test patch:
diff --git a/test/nn/dense/test_linear.py b/test/nn/dense/test_linear.py
index d193276dc..9c004b7b0 100644
--- a/test/nn/dense/test_linear.py
+++ b/test/nn/dense/test_linear.py
@@ -127,6 +127,17 @@ def test_hetero_linear(device):
     assert torch.allclose(jit(x, type_vec), out, atol=1e-3)
 
 
+def test_hetero_linear_initializer():
+    lin = HeteroLinear(
+        16,
+        32,
+        num_types=3,
+        weight_initializer='glorot',
+        bias_initializer='zeros',
+    )
+    assert torch.equal(lin.bias, torch.zeros_like(lin.bias))
+
+
 @withCUDA
 @pytest.mark.parametrize('use_segmm', [True, False])
 def test_hetero_linear_amp(device, use_segmm):