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

CS224W - Adds TransD KGE, and Bernoulli corruption strategy for all KGE #9864

Closed
wants to merge 39 commits into from

Conversation

mattjhayes3
Copy link

@mattjhayes3 mattjhayes3 commented Dec 15, 2024

Implements TransD and Bernoulli corruption strategy (used in TransD and TransH papers).

Details

  • Did not see any PRs for these ones yet :)
  • Used the KGEModel base and tried to keep consistent with other KGE
  • Tried to implement everything as efficiently as possible while following the paper
  • Incorporated into examples/kge_fb15k_237.py, also adding duration calculation there
  • The Bernoulli parameters are currently computed for each batch rather than the whole training set
    • This is a little slower but seemed to work much better in terms of metrics
    • Also seems a little more intuitive for the user to simply flip a bool as opposed to requiring they pass their whole training set for initialization, or requiring they call loader().
    • We might also try cumulating the statistics during training, but these initial experiments suggest this would be the worst of both worlds (slower as we won't know when first epoch has ended, ultimately similar to precomputing in terms of metrics)
  • Happy to split Bernoulli into a separate PR, or make any other edits you might prefer.

Benchmarks

I was only able to compare it to TransE on examples/kge_fb15k_237.py and do 3 runs each, but even without any hyperparameter tuning, findings seem fairly consistent with paper, i.e. significant improvements in all metrics [colab]:

Method/Evalset Mean Rank MRR Hits@10
TransD Bernoulli Val 176.19 ± 0.74 0.223 ± 0.000 0.408 ± 0.001
TransD Bernoulli Test 180.65 ± 0.71 0.220 ± 0.001 0.401 ± 0.002
TransD Val 180.08 ± 0.37 0.211 ± 0.003 0.400 ± 0.002
TransD Test 184.06 ± 1.78 0.210 ± 0.003 0.396 ± 0.002
TransE Val 258.74 ± 5.76 0.221 ± 0.000 0.366 ± 0.004
TransE Test 268.30 ± 6.39 0.217 ± 0.001 0.362 ± 0.004

mattjhayes3 and others added 30 commits November 6, 2024 21:24
Before the fix, tensors can only be concatenated over `dim=0`. The `dim`
argument was not used by any operation in the function. This update
allows the tensors to be concatenated over any given dimension.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Matplotlib arrows don't have a source and a destination. They have a
text and a dot. As the
[example](https://matplotlib.org/stable/gallery/text_labels_and_annotations/fancyarrow_demo.html)
shows, a `<-` arrow points from the dot to the text and `->` points from
the text to the dot.
<img width="153" alt="Screenshot 2024-11-11 at 15 47 24"
src="https://github.com/user-attachments/assets/7a8333d3-6c58-46b2-a47b-ae6c6afff87d">
`_visualize_graph_via_networkx()` sets `xy=pos[src]` and
`xytext=pos[dst]`, so we want arrows from the dot (`xy`) to the text
(`xytext`). That's the `<-` arrow.

This can also be confirmed by comparing the visualization to the
GraphViz version. The arrows go the other way. Or just looking at the
data and the picture, haha! It took me a while to figure out that it's
not my graph that's messed up! 😅
…ral mesh elements (pyg-team#9776)

Now transforms 2D triangular elements/faces with shape [3,n] to as well
as 3D tetrahedral elements with shape [4,n] to edges of shape [2,n].

Including pytest case for face input with shape [4,n]

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: rusty1s <[email protected]>
…pyg-team#9748)

This patch adds support of torch_delaunay package, which works with
Torch tensors. The new implementation uses `torch_delaunay` package if
it is installed (by default), and then falls back to the `scipy`
implementation otherwise.

---------

Co-authored-by: rusty1s <[email protected]>
…yg-team#9756)

Example use case:

```python
from torch_geometric.utils import k_hop_subgraph
import torch

edge_index = torch.tensor([[1, 2, 3],
                           [0, 1, 1]])
# get the 2-hop neighbors of node 0 in the directed graph.
_, edge_index, _, edge_mask = k_hop_subgraph(0, 2, edge_index, relabel_nodes=False, directed=True)
```

This gives the following result:

Expected Outcome:
```python
>>> edge_index
tensor([[1, 2, 3],
        [0, 1, 1]])

>>> edge_mask
tensor([True,  True,  True])
```

Actual Outcome:
```python
>>> edge_index
tensor([[2, 3],
        [1, 1]])
>>> edge_mask
tensor([False,  True,  True])
```

This stems from the fact that the line `torch.index_select(node_mask, 0,
row, out=edge_mask)` overwrites `edge_mask`, effectively only marking
the edges used in the final hop as `True`.

To fix this, I have added `preserved_edge_mask ` that will mark the
edges used in each hop as `True`.

---------

Co-authored-by: rusty1s <[email protected]>
Removes `TensorAttr.fully_specify` which was originally added in pyg-team#4534.

---------

Co-authored-by: rusty1s <[email protected]>
Fixed the typo in the description of NeighborLoader.
reopened  pyg-team#9591 

Feature summary:

- Add GLEM as GNN & LLM Co-training model to PyG
- adapt GLEM's LM to AutoModelForSequenceClassification from
transformers
- Lora support
- LM/LLM support
- ogbn-products/ogbn-arxiv testing finished
- TAGDataset can be used as a wrapper class for any node classification
dataset in PyG with LM tokenizer and associate raw text
- external prediction as pseudo labels supported

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Rishi Puri <[email protected]>
Co-authored-by: Akihiro Nitta <[email protected]>
### Issue
- pyg-team#9694 
- pyg-team#9698

### Feature Summary

- Add `MoleculeGPTDataset`
- Add `MoleculeGPT` as GNN & LLM Co-training model to PyG
- Add an example for training and testing
- Split the PR into 3 sub-PRs (pyg-team#9723, pyg-team#9724, pyg-team#9725)
- Limited hardware resources, can't load `lmsys/vicuna-7b-v1.5`, use
`TinyLlama/TinyLlama-1.1B-Chat-v0.1` instead, and the full training
pipeline was not tested

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Giovanni Gatti <[email protected]>
Co-authored-by: Rishi Puri <[email protected]>
### Issue
- pyg-team#9694
- pyg-team#9700

### Feature Summary

- Add `GitMolDataset`
- Add `GITMol` as GNN & LLM Co-training model to PyG
- Add an example for pre-training
- Limited hardware resources, so the full training pipeline was not
tested
- Multi modal cross attention shares the same weight, not aligned with
the original paper

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Rishi Puri <[email protected]>
…xamples) (pyg-team#9666)

Follow up to [PR
9597](pyg-team#9597). Includes
multiple changes related to LLM+GNN experiments and scaling up to a
remote backend. Including:

- LargeGraphIndexer for building a large knowledge graph locally from
multiple samples in an arbitrary dataset
- Remote Backend Loader and examples for deploying a Retrieval algorithm
to a third party backend FeatureStore or GraphStore
- NVTX profiling tools for nsys users
- Quality of Life improvements and benchmarking scripts for G-Retriever.

Updates using these for WebQSP will be moved to a seperate PR

UPDATE:
PR is being broken up into smaller PRs. These can be previewed here:

- zaristei#6
- zaristei#7
- zaristei#8

---------

Co-authored-by: Zack Aristei <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Zachary Aristei <[email protected]>
Co-authored-by: Rishi Puri <[email protected]>
…ion (pyg-team#9807)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Updated to use new NGC CUDA DL base image. Some differences:

1. /workspace is the working directory
2. Python libs removed that were not included in NGC PyG image:
`torch_scatter torch_sparse torch_cluster torch_spline_conv
torchnet==0.0.4 h5py torchnet `
3. Using latest stable versions for graphviz and torch

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Rishi Puri <[email protected]>
mattjhayes3 and others added 9 commits December 14, 2024 05:00
Fix some issues with the docstrings of LargeGraphIndexer.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Zachary Aristei <[email protected]>
To avoid issues when node types contain the `EDGE_TYPE_STR_SPLIT`
delimiter.

---------

Co-authored-by: rusty1s <[email protected]>
This reverts commit e20f018.
@mattjhayes3 mattjhayes3 marked this pull request as ready for review December 15, 2024 01:41
@mattjhayes3 mattjhayes3 changed the base branch from master to multigpu-cleanup December 15, 2024 01:49
@mattjhayes3 mattjhayes3 changed the base branch from multigpu-cleanup to master December 15, 2024 01:49
@mattjhayes3
Copy link
Author

mattjhayes3 commented Dec 15, 2024

Sorry for all the extra auto-added reviewers! Was trying to fix the timeline with suggestion in https://stackoverflow.com/questions/16306012/github-pull-request-showing-commits-that-are-already-in-target-branch

Abandoning this in favor of #9866

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.