Skip to content

Conversation

@drivanov
Copy link
Contributor

@drivanov drivanov commented Jul 10, 2025

This PR addresses several warnings that appear in the example scripts, including:

  • UserWarnings triggered by unsafe tensor operations or missing configurations.
  • FutureWarnings indicating upcoming behavior changes in dependencies.

By resolving these issues, we aim to improve the clarity of the output and ensure better compatibility with future library versions. No changes to core logic or results are introduced.

/workspace/examples/gcn.py:84: UserWarning: Converting a tensor with requires_grad=True to a scalar may lead to unexpected behavior.
Consider using tensor.detach() first. (Triggered internally at /opt/pytorch/pytorch/torch/csrc/autograd/generated/python_variable_methods.cpp:835.)
  return float(loss)

/workspace/examples/compile/gcn.py:65: UserWarning: Converting a tensor with requires_grad=True to a scalar may lead to unexpected behavior.
Consider using tensor.detach() first. (Triggered internally at /opt/pytorch/pytorch/torch/csrc/autograd/generated/python_variable_methods.cpp:835.)

usr/local/lib/python3.12/dist-packages/torch/cuda/memory.py:491: FutureWarning: torch.cuda.reset_max_memory_allocated now calls torch.cuda.reset_peak_memory_stats, which resets /all/ peak memory stats.
  warnings.warn(

@drivanov drivanov requested a review from wsad1 as a code owner July 10, 2025 15:20
puririshi98 added a commit that referenced this pull request Jul 16, 2025
Follow-up to
[PR#10357](#10357) and
[PR#10360](#10360) to
address and resolve the warnings similar to the following ones:
```
/workspace/examples/gat.py:66: UserWarning: Converting a tensor with requires_grad=True to a scalar may lead to unexpected behavior.
Consider using tensor.detach() first. (Triggered internally at /opt/pytorch/pytorch/torch/csrc/autograd/generated/python_variable_methods.cpp:835.)
  return float(loss)

/workspace/examples/proteins_gmt.py:68: UserWarning: Converting a tensor with requires_grad=True to a scalar may lead to unexpected behavior.
Consider using tensor.detach() first. (Triggered internally at /opt/pytorch/pytorch/torch/csrc/autograd/generated/python_variable_methods.cpp:835.)
  total_loss += data.num_graphs * float(loss)
  ```

Co-authored-by: Rishi Puri <[email protected]>
Copy link
Contributor

@puririshi98 puririshi98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@puririshi98 puririshi98 enabled auto-merge (squash) July 16, 2025 17:35
auto-merge was automatically disabled July 16, 2025 17:36

Invalid email address

@puririshi98 puririshi98 merged commit 1b6455e into pyg-team:master Jul 16, 2025
17 of 18 checks passed
@drivanov drivanov deleted the fixing_warnings branch July 16, 2025 21:05
puririshi98 added a commit that referenced this pull request Jul 22, 2025
Follow-up to
[PR#10357](#10357) to
address and resolve the following remaining warning:
```
  test/datasets/test_snap_dataset.py::test_ego_facebook_snap_dataset /usr/local/lib/python3.12/dist-packages/torch_geometric/data/in_memory_dataset.py:131: 
UserWarning: Weights only load failed. Please file an issue to make torch.load(weights_only=True) compatible 
in your case. Please use torch.serialization.add_safe_globals([torch_geometric.datasets.snap_dataset.EgoData]) 
to allowlist this global. out = fs.torch_load(path)  
```

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Rishi Puri <[email protected]>
puririshi98 pushed a commit that referenced this pull request Jul 28, 2025
Follow-up to
[PR#10357](#10357) to
address and resolve the following warning:

```
  /usr/local/lib/python3.12/dist-packages/torch_geometric/contrib/explain/pgm_explainer.py:154: UserWarning: Converting 
a tensor with requires_grad=True to a scalar may lead to unexpected behavior.
  Consider using tensor.detach() first. (Triggered internally at /opt/pytorch/pytorch/torch/csrc/autograd/generated/python_variable_methods.cpp:835.)
    sample[num_nodes] = pred_change
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants