Repository: dmlc/dgl

Issue:
[Example][Bug] Running error on the example case: example/pytorch/arma
## 🐛 Bug

Example of using DGL to implement GNN with convolutional ARMA filters failed.

## To Reproduce

`python citation.py --gpu 0`

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->
```
Traceback (most recent call last):
  File "citation.py", line 142, in <module>
    acc_lists.append(main(args))
  File "citation.py", line 84, in main
    train_loss.backward()
  File "/opt/conda/lib/python3.8/site-packages/torch/_tensor.py", line 396, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
  File "/opt/conda/lib/python3.8/site-packages/torch/autograd/__init__.py", line 173, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [2708, 7]], which is output 0 of ReluBackward0, is at version 1; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).
```

`python citation.py --gpu 0 --dataset Citeseer --num-stacks 3`

```
Traceback (most recent call last):
  File "citation.py", line 142, in <module>
    acc_lists.append(main(args))
  File "citation.py", line 84, in main
    train_loss.backward()
  File "/opt/conda/lib/python3.8/site-packages/torch/_tensor.py", line 396, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph, inputs=inputs)
  File "/opt/conda/lib/python3.8/site-packages/torch/autograd/__init__.py", line 173, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.cuda.FloatTensor [3327, 6]], which is output 0 of ReluBackward0, is at version 2; expected version 0 instead. Hint: enable anomaly detection to find the operation that failed to compute its gradient, with torch.autograd.set_detect_anomaly(True).

```

## Expected behavior

The case should run through

## Environment

 - DGL Version (e.g., 1.0): 0.9
 - Backend Library & Version (e.g., PyTorch 0.4.1, MXNet/Gluon 1.3): 1.12
 - OS (e.g., Linux): ubuntu
 - How you installed DGL (`conda`, `pip`, source): source
 - Build command you used (if compiling from source):
 - Python version: 3.8
 - CUDA/cuDNN version (if applicable): 11.7
 - GPU models and configuration (e.g. V100): A100
 - Any other relevant information:

## Additional context

<!-- Add any other context about the problem here. -->



Discussion:

Resolving patch:
diff --git a/examples/pytorch/arma/model.py b/examples/pytorch/arma/model.py
--- a/examples/pytorch/arma/model.py
+++ b/examples/pytorch/arma/model.py
@@ -64,7 +64,7 @@ def forward(self, g, feats):
             # assume that the graphs are undirected and graph.in_degrees() is the same as graph.out_degrees()
             degs = g.in_degrees().float().clamp(min=1)
             norm = torch.pow(degs, -0.5).to(feats.device).unsqueeze(1)
-            output = None
+            output = [] 
 
             for k in range(self.K):
                 feats = init_feats
@@ -88,13 +88,9 @@ def forward(self, g, feats):
                     
                     if self.activation is not None:
                         feats = self.activation(feats)
-                    
-                if output is None:
-                    output = feats
-                else:
-                    output += feats
-                
-            return output / self.K 
+                output.append(feats)
+
+            return torch.stack(output).mean(dim=0)
 
 class ARMA4NC(nn.Module):
     def __init__(self,


Test patch: