[FEA] Add New Unsupervised Learning Example#371
[FEA] Add New Unsupervised Learning Example#371rapids-bot[bot] merged 16 commits intorapidsai:mainfrom
Conversation
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Greptile OverviewGreptile SummaryAdds a comprehensive unsupervised learning example for the MAG dataset, implementing link prediction with GNN embeddings that can be used downstream for node classification. Key Changes
Implementation DetailsThe main script supports two modes:
The pipeline enriches the graph with betweenness centrality as edge attributes, trains an encoder-decoder architecture for link prediction, and exports concatenated original features + learned embeddings for downstream tasks. Minor Issues
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant mag_lp_mnmg.py
participant Model
participant GraphStore
participant FeatureStore
participant xgb.py
participant XGBoost
User->>mag_lp_mnmg.py: Run training script
mag_lp_mnmg.py->>mag_lp_mnmg.py: Initialize distributed env (torchrun)
mag_lp_mnmg.py->>GraphStore: Load MAG dataset
mag_lp_mnmg.py->>FeatureStore: Add node/edge features
mag_lp_mnmg.py->>mag_lp_mnmg.py: Compute betweenness centrality
mag_lp_mnmg.py->>FeatureStore: Store centrality as edge features
mag_lp_mnmg.py->>Model: Create Classifier (Encoder+Decoder)
loop Training Epochs
mag_lp_mnmg.py->>Model: Train on link prediction task
mag_lp_mnmg.py->>Model: Evaluate on test set
end
mag_lp_mnmg.py->>Model: Extract learned embeddings
mag_lp_mnmg.py->>mag_lp_mnmg.py: Write embeddings to parquet (x)
mag_lp_mnmg.py->>mag_lp_mnmg.py: Write labels to parquet (y)
User->>xgb.py: Run XGBoost script
xgb.py->>xgb.py: Read embeddings (x) and labels (y)
xgb.py->>xgb.py: Join data and split train/test
xgb.py->>XGBoost: Train classifier on embeddings
xgb.py->>XGBoost: Evaluate on test set
xgb.py->>User: Report accuracy
|
There was a problem hiding this comment.
Additional Comments (4)
-
python/cugraph-pyg/cugraph_pyg/examples/mag_lp_mnmg.py, line 96 (link)logic:
global_rankis not defined in the scope of theClassifier.__init__methodTo fix this, you'll need to pass
global_rankas a parameter to the Classifier constructor. -
python/cugraph-pyg/cugraph_pyg/examples/mag_lp_mnmg.py, line 111 (link)logic:
global_rankis not defined in the scope of theClassifier.__init__methodTo fix this, you'll need to pass
global_rankas a parameter to the Classifier constructor. -
python/cugraph-pyg/cugraph_pyg/examples/mag_lp_mnmg.py, line 278 (link)logic:
global_rankis not defined in the scope of thetrainfunctionTo fix this, you'll need to pass
global_rankas a parameter to thetrainfunction. -
python/cugraph-pyg/cugraph_pyg/examples/mag_lp_mnmg.py, line 687-690 (link)logic: doubled the embedding instead of adding
x_paperresidual
2 files reviewed, 4 comments
There was a problem hiding this comment.
Additional Comments (1)
-
python/cugraph-pyg/cugraph_pyg/examples/mag_lp_mnmg.py, line 681-684 (link)logic: duplicates
x_dict["paper"]addition - should addx_paperresidual instead
2 files reviewed, 1 comment
There was a problem hiding this comment.
Additional Comments (3)
-
python/cugraph-pyg/cugraph_pyg/examples/mag_lp_mnmg.py, line 201 (link)style: missing
@torch.no_grad()decorator - inference should disable gradient computation for performance and memory efficiency -
python/cugraph-pyg/cugraph_pyg/examples/mag_lp_mnmg.py, line 643 (link)logic:
drop_last=Truecauses embeddings for the last batch to not be computed, leaving uninitialized values in the pre-allocated tensor at line 646-648 -
python/cugraph-pyg/cugraph_pyg/examples/mag_lp_mnmg.py, line 272 (link)style:
global_rankaccessed from global scope - consider passing it as a parameter for better function isolation and testabilityNote: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
2 files reviewed, 3 comments
There was a problem hiding this comment.
Additional Comments (3)
-
python/cugraph-pyg/cugraph_pyg/examples/mag_lp_mnmg.py, line 548-549 (link)logic: Tensor used as index instead of scalar value.
train_szandtest_szare tensors but need to be converted to integers for slicing. -
python/cugraph-pyg/cugraph_pyg/examples/mag_lp_mnmg.py, line 492 (link)syntax: "betweeness" is misspelled
-
python/cugraph-pyg/cugraph_pyg/examples/xgb.py, line 92 (link)logic: Type consistency issue:
predictions_computedis a cupy array butdfy_test_computedis likely still a cudf Series/DataFrame
2 files reviewed, 3 comments
These are not isues - I've tested both files. |
Greptile's behavior is changing!From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
tingyu66
left a comment
There was a problem hiding this comment.
LGTM. Just left some nitpicks.
…add-mag-examples
|
/merge |
| "author": torch.zeros( | ||
| batch["author"].n_id.numel(), self.hidden_channels, device="cuda" | ||
| ), | ||
| "institution": torch.zeros( | ||
| batch["institution"].n_id.numel(), | ||
| self.hidden_channels, | ||
| device="cuda", | ||
| ), | ||
| "field_of_study": torch.zeros( | ||
| batch["field_of_study"].n_id.numel(), | ||
| self.hidden_channels, | ||
| device="cuda", | ||
| ), |
There was a problem hiding this comment.
Hard-coded device="cuda" makes code less flexible
| "author": torch.zeros( | |
| batch["author"].n_id.numel(), self.hidden_channels, device="cuda" | |
| ), | |
| "institution": torch.zeros( | |
| batch["institution"].n_id.numel(), | |
| self.hidden_channels, | |
| device="cuda", | |
| ), | |
| "field_of_study": torch.zeros( | |
| batch["field_of_study"].n_id.numel(), | |
| self.hidden_channels, | |
| device="cuda", | |
| ), | |
| "author": torch.zeros( | |
| batch["author"].n_id.numel(), self.hidden_channels, device=x_paper.device | |
| ), | |
| "institution": torch.zeros( | |
| batch["institution"].n_id.numel(), | |
| self.hidden_channels, | |
| device=x_paper.device | |
| ), | |
| "field_of_study": torch.zeros( | |
| batch["field_of_study"].n_id.numel(), | |
| self.hidden_channels, | |
| device=x_paper.device | |
| ), |
| "paper": x_paper, | ||
| "author": torch.zeros( | ||
| batch["author"].n_id.numel(), | ||
| model.module.hidden_channels, | ||
| device="cuda", | ||
| ), | ||
| "institution": torch.zeros( | ||
| batch["institution"].n_id.numel(), | ||
| model.module.hidden_channels, | ||
| device="cuda", | ||
| ), | ||
| "field_of_study": torch.zeros( | ||
| batch["field_of_study"].n_id.numel(), | ||
| model.module.hidden_channels, | ||
| device="cuda", | ||
| ), |
There was a problem hiding this comment.
Hard-coded device="cuda" makes code less flexible (use x_paper.device instead)
Adds a new unsupervised learning example that can learn embeddings. Closes #364