-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Cleanup examples #10097
base: master
Are you sure you want to change the base?
Cleanup examples #10097
Conversation
xnuohz
commented
Mar 5, 2025
- Combine 15 examples related to cora into 1 file
- Update related docs, github workflow, readme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
code changes look good at first review, but for such an extensive change i would ask that you run every one of the deleted examples, and then the new version with its corresponding args for this planetoid example. I would ask that you share those logs and also check yourself to make sure that the new version is as good or better in terms of accuracy, speed, and readability. and if not for any reason try to understand why. This is a very valuable PR but we want to be careful with something like this.
If compute is an issue, i would ask that you write a bash script for me that will automatically run the above experiments and have the logs saved to some shared cloud drive or a github repo so you can do the above mentioned anlaysis after i run the script.
regardless once you have said analysis, i will look through myself as well and make sure our analyses align. then i think this is safe to merge
also please update the changelog |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great so far! ✨
Tbh, I'd vote for having many separate 90~100 lines of code examples to allow users to immediately understand what the script does and easily modify the scirpt that they're interested in (at the cost of maintaining duplicate code in the example directory), but I guess this is just my preference.
Could we also add type annotations?
examples/planetoid_train.py
Outdated
if not WITH_TORCH_SPLINE_CONV: | ||
quit("This example requires 'torch-spline-conv'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this script need the package in all cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated and only judged when gnn_choice = splinegnn
examples/planetoid_train.py
Outdated
if not WITH_TORCH_SPLINE_CONV: | ||
quit("This example requires 'torch-spline-conv'") | ||
|
||
# define args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# define args |
examples/planetoid_train.py
Outdated
wall_clock_start = time.perf_counter() | ||
seed_everything(123) | ||
|
||
# detect device |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to remove comments that don't add any information.
# detect device |
examples/planetoid_train.py
Outdated
total_loss = 0 | ||
for pos_rw, neg_rw in loader: | ||
optimizer.zero_grad() | ||
loss = model.loss(pos_rw.to(device), neg_rw.to(device)) | ||
loss.backward() | ||
optimizer.step() | ||
total_loss += loss.item() | ||
return total_loss / len(loader) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's accumulate the loss as a tensor and not as a float so that we don't need to cuda sync every iteration:
total_loss = 0 | |
for pos_rw, neg_rw in loader: | |
optimizer.zero_grad() | |
loss = model.loss(pos_rw.to(device), neg_rw.to(device)) | |
loss.backward() | |
optimizer.step() | |
total_loss += loss.item() | |
return total_loss / len(loader) | |
total_loss = torch.zeros(1, device=device).squeeze() | |
for pos_rw, neg_rw in loader: | |
optimizer.zero_grad() | |
loss = model.loss(pos_rw.to(device), neg_rw.to(device)) | |
loss.backward() | |
optimizer.step() | |
total_loss += loss | |
return total_loss.item() / len(loader) |
examples/planetoid_train.py
Outdated
times = [] | ||
best_val_acc = test_acc = 0. | ||
for epoch in range(args.epochs): | ||
start = time.time() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit for consistency:
start = time.time() | |
start = time.perf_counter() |
for more information, see https://pre-commit.ci
…c into examples/cleanup
for more information, see https://pre-commit.ci
@puririshi98 @akihironitta ready for review, thank you
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh, I'd vote for having many separate 90~100 lines of code examples to allow users to immediately understand what the script does and easily modify the scirpt that they're interested in (at the cost of maintaining duplicate code in the example directory), but I guess this is just my preference.
I think that is a valid point, instead of just deleting them all, @xnuohz could you leave them in and update the readme to say that
"planetoid_train.py combines (insert list of python examples it covers) into a single unified framework that can all be run run with planetoid_train.sh. (insert description of the planetoid datasets it covers in general and explain why they can all be covered with a unified codebase)".
@akihironitta thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also @xnuohz please figure out why that 1 example is worse and add some special condition to the framework that fixes the issue. this should be considered a strict requirement for merging
after added model params init, their results are consistent |
okay lets wait till @akihironitta replies to my previous comment about restructuring this PR to satisfy his concerns. |