Skip to content

Adding TGCN for nodeproppred - #89

Merged
ntgbaoo merged 6 commits into
mainfrom
79-tgcn-nodePropPrediction
Jul 11, 2025
Merged

Adding TGCN for nodeproppred#89
ntgbaoo merged 6 commits into
mainfrom
79-tgcn-nodePropPrediction

Conversation

@ntgbaoo

@ntgbaoo ntgbaoo commented Jul 3, 2025

Copy link
Copy Markdown
Member

Objective

Adding the implementation of T-GCN and a node property prediction example for T-GCN

New scripts

Testing evidence

Command used:

python .\examples\nodeproppred\tgcn.py --dataset tgbn-trade --time-gran Y --batch-time-gran Y --epochs 100 --seed 720

python .\examples\nodeproppred\gclstm.py --dataset tgbn-trade --time-gran Y --batch-time-gran Y --epochs 100 --seed 720
  • Cross Entropy Loss & validation NDCG over epochs:
test_tgcn
  • Achieved test result (no early stopping): 0.2521 NDCG on tgbn-trade (GCLSTM achieved 0.2462 NDCG)

TODO for another PR:

  • Add link prediction example for TGCN

Bảo Ngô added 2 commits July 2, 2025 19:36
Added initial development of TGCN and updated __init__.py with new model class
Fixed importing wrong lib for zeros() init. Added NodePropPred example for TGCN. Added Integration test for TGCN
@ntgbaoo

ntgbaoo commented Jul 3, 2025

Copy link
Copy Markdown
Member Author

Not sure why the test check on GitHub failed. The test ran successfully on my local (except 3 tests failed due to the issue mentioned in this PR #82)
image

@Jacob-Chmura

Copy link
Copy Markdown
Member

Not sure why the test check on GitHub failed

Safe to ignore these tests. There was an issue in the test cases due to auto-merging conflicts in some PRs that I pushed. I have adressed these and the fix should be in master shortly.

@Jacob-Chmura Jacob-Chmura left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very nice work. Just some minor comments. I am not familiar with the TGCN paper, @shenyangHuang please review the core library layer and make a judgement on the expected performance.

Comment thread test/integration/test_tgcn.py Outdated
'--gres=gpu:a100l:1',
]
)
def test_gclstm_nodeprop_pred(slurm_job_runner, dataset):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
def test_gclstm_nodeprop_pred(slurm_job_runner, dataset):
def test_tgcn_nodeprop_pred(slurm_job_runner, dataset):

Comment thread examples/nodeproppred/tgcn.py Outdated
Comment on lines +1 to +4
r"""python -u gclstm.py --dataset tgbn-trade --time-gran r --batch-time-gran r
python -u gclstm.py --dataset tgbn-genre --time-gran s --batch-time-gran D\
example commands to run this script.
"""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
r"""python -u gclstm.py --dataset tgbn-trade --time-gran r --batch-time-gran r
python -u gclstm.py --dataset tgbn-genre --time-gran s --batch-time-gran D\
example commands to run this script.
"""
"""

I think this can be removed

Comment thread examples/nodeproppred/tgcn.py Outdated
edge_index = torch.stack([batch.src, batch.dst], dim=0)
edge_weight = batch.edge_weight if hasattr(batch, 'edge_weight') else None # type: ignore
z, h_0 = self.encoder(node_feat, edge_index, edge_weight, h_0)
z_node = z[batch.nid_to_idx[batch.node_ids]] # type: ignore

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

After merging #60, the batch attribute to use is actually global_to_local.

Suggested change
z_node = z[batch.nid_to_idx[batch.node_ids]] # type: ignore
z_node = z[batch.global_to_local[batch.node_ids]] # type: ignore

Comment thread examples/nodeproppred/tgcn.py Outdated
self,
x: torch.Tensor,
edge_index: torch.Tensor,
edge_weight: torch.Tensor,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
edge_weight: torch.Tensor,
edge_weight: torch.Tensor | None,

Comment thread examples/nodeproppred/tgcn.py Outdated
parser.add_argument('--seed', type=int, default=1337, help='random seed to use')
parser.add_argument('--dataset', type=str, default='tgbn-genre', help='Dataset name')
parser.add_argument('--device', type=str, default='cpu', help='torch device')
parser.add_argument('--epochs', type=int, default=100, help='number of epochs')

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just double checking if we want to use 100 or 10 as default number of epochs

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I would say 100 epochs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

for DTDG methods usually takes more epochs

Comment thread tgm/nn/recurrent/tgcn.py Outdated
edge_index (PyTorch Long Tensor): Graph edge indices.
edge_weight (PyTorch Long Tensor, optional): Edge weight vector.
H (PyTorch Tensor, optional): Hidden state matrix for all nodes.
C (PyTorch Tensor, optional): Cell state matrix for all nodes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
C (PyTorch Tensor, optional): Cell state matrix for all nodes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unless we need this tensor in which case example should be updated

@Jacob-Chmura Jacob-Chmura mentioned this pull request Jul 3, 2025
2 tasks
@ntgbaoo ntgbaoo self-assigned this Jul 4, 2025
@ntgbaoo ntgbaoo changed the title Adding GCLSTM for nodeproppred Adding TGCN for nodeproppred Jul 5, 2025
@codecov

codecov Bot commented Jul 5, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 29.62963% with 38 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
tgm/nn/recurrent/tgcn.py 26.92% 38 Missing ⚠️

📢 Thoughts on this report? Let us know!

@shenyangHuang

Copy link
Copy Markdown
Collaborator

test performance of 0.3654 is quite sensible.
for tgbn-trade TGN achieves 0.374 test. So I would say the performance is quite reasonable.
see here for the leaderboard.

@shenyangHuang shenyangHuang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

performance looks good.

Comment thread tgm/nn/recurrent/tgcn.py
in_channels: int,
out_channels: int,
improved: bool = False,
cached: bool = False,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

when would you want to turn this one? what would be the benefit?

@ntgbaoo ntgbaoo Jul 6, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

improved and cached are both used to configure GCNConv. By default, they are set to False. From what I am understanding from reading the documentation from PyG.

  • If we set improved = True , the self-loops are added A+2I instead of A+I. This increases the weight of self-loops, giving each node’s own features more influence during aggregation.
  • If we set cached = True, the layer computes the normalized adjacency matrix only once, and reuses it. This speeds up training and inference but is only suitable for transductive learning. Scenarios where cached can be set to True include tasks such as traffic forecasting, where graph structure is assumed to be static and only node features are dynamic. cached should not be set to False when graph structure dynamically changes.

Thanks for pointing this out. These are all useful information that we should include in the comment section.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah thanks for adding the comments here, much more clear now

Comment thread examples/nodeproppred/tgcn.py Outdated
parser.add_argument('--seed', type=int, default=1337, help='random seed to use')
parser.add_argument('--dataset', type=str, default='tgbn-genre', help='Dataset name')
parser.add_argument('--device', type=str, default='cpu', help='torch device')
parser.add_argument('--epochs', type=int, default=100, help='number of epochs')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

for DTDG methods usually takes more epochs

@ntgbaoo
ntgbaoo requested a review from shenyangHuang July 6, 2025 01:05
@ntgbaoo

ntgbaoo commented Jul 6, 2025

Copy link
Copy Markdown
Member Author

I added further information about cached and improved in the comment section and increased the default number of epochs as you suggested, @shenyangHuang. Please take a look whenever you have a chance.

Comment thread tgm/nn/recurrent/tgcn.py
in_channels: int,
out_channels: int,
improved: bool = False,
cached: bool = False,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah thanks for adding the comments here, much more clear now

@ntgbaoo
ntgbaoo requested a review from Jacob-Chmura July 6, 2025 17:40
@ntgbaoo
ntgbaoo requested a review from shenyangHuang July 11, 2025 02:27
@shenyangHuang

Copy link
Copy Markdown
Collaborator

The new performance makes sense to me, I got similar range from GCN yesterday for nodeproppred.

@ntgbaoo
ntgbaoo merged commit cdf618d into main Jul 11, 2025
6 checks passed
@ntgbaoo
ntgbaoo deleted the 79-tgcn-nodePropPrediction branch July 12, 2025 02:01
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