Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update virtual_node.py #7751

Closed
wants to merge 3 commits into from
Closed

Update virtual_node.py #7751

wants to merge 3 commits into from

Conversation

mzamini92
Copy link
Contributor

Instead of creating new tensors in each iteration, can't we modify the existing tensors in-place? also, instead of creating new tensors by concatenating existing tensors, isn't it better we use tensor views to represent the augmented tensors? It seems in old_data = copy.copy(data) the subsequent operations only modify the data object and don't change the underlying tensor data. are these valid points?

Instead of creating new tensors in each iteration, can't we modify the existing tensors in-place? 
also, instead of creating new tensors by concatenating existing tensors, isn't it better we use tensor views to represent the augmented tensors?
It seems in `old_data = copy.copy(data)` the subsequent operations only modify the data object and don't change the underlying tensor data.
are these valid points?
@mzamini92 mzamini92 requested a review from wsad1 as a code owner July 16, 2023 02:45
@codecov
Copy link

codecov bot commented Jul 16, 2023

Codecov Report

Merging #7751 (fd53e6c) into master (c6f3a55) will decrease coverage by 0.36%.
The diff coverage is 91.66%.

@@            Coverage Diff             @@
##           master    #7751      +/-   ##
==========================================
- Coverage   91.91%   91.56%   -0.36%     
==========================================
  Files         452      452              
  Lines       25550    25543       -7     
==========================================
- Hits        23485    23389      -96     
- Misses       2065     2154      +89     
Impacted Files Coverage Δ
torch_geometric/transforms/virtual_node.py 95.23% <91.66%> (-0.42%) ⬇️

... and 19 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@akihironitta akihironitta left a comment

Choose a reason for hiding this comment

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

I guess the idea behind making a copy is that we want to avoid silently contaminating the original data. I believe that's the motivation for #7429.

However, for your change in this PR specifically, the data is already copy.copy()'ed in the BaseTransform.__call__, so it shouldn't change any behaviour.

@mzamini92
Copy link
Contributor Author

I guess the idea behind making a copy is that we want to avoid silently contaminating the original data. I believe that's the motivation for #7429.

However, for your change in this PR specifically, the data is already copy.copy()'ed in the BaseTransform.__call__, so it shouldn't change any behaviour.

Thank you. if that's the case then yes maybe having copy.copy() is not bad. do we need to close the PR? or I should do anything special to merge it?

@rusty1s
Copy link
Member

rusty1s commented Jul 19, 2023

We need the separation here between old_data and data since we modify data in the for-loop (and potentially its number of nodes/edges), and thus is_node_attr and is_edge_attr inside the loop may fail to recognize node-level and edge-level tensors since their size does no longer match.

Feel free to re-open if you have strong concerns.

@rusty1s rusty1s closed this Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants