Optimize train_CSL_graph_classification.py#84
Open
mzamini92 wants to merge 1 commit intographdeeplearning:masterfrom
Open
Optimize train_CSL_graph_classification.py#84mzamini92 wants to merge 1 commit intographdeeplearning:masterfrom
mzamini92 wants to merge 1 commit intographdeeplearning:masterfrom
Conversation
In both the training and evaluation loops, there are unnecessary calls to `loss.detach().item()`. You can calculate the loss without detaching it and only detach it if necessary at a later stage. In the train_epoch_dense function, you can remove the manual batch handling using `(iter % batch_size)` and instead rely on the `batch_size` parameter of the `data_loader`. The DataLoader automatically handles the batch iteration for you. In both the `train_epoch_sparse` and `train_epoch_dense` functions, you can move the `optimizer.zero_grad()` call outside the loop, just before the loop starts. This will avoid unnecessary repeated calls to `zero_grad()`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In both the training and evaluation loops, there are unnecessary calls to
loss.detach().item(). You can calculate the loss without detaching it and only detach it if necessary at a later stage. In the train_epoch_dense function, you can remove the manual batch handling using(iter % batch_size)and instead rely on thebatch_sizeparameter of thedata_loader. The DataLoader automatically handles the batch iteration for you. In both thetrain_epoch_sparseandtrain_epoch_densefunctions, you can move theoptimizer.zero_grad()call outside the loop, just before the loop starts. This will avoid unnecessary repeated calls tozero_grad().