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

[Multi-task Learning] Add GSgnnMultiTaskSharedEncoderModel #855

Merged
merged 10 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 33 additions & 4 deletions python/graphstorm/dataloading/dataloading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,12 +1706,15 @@ def __init__(self, dataset, task_infos, task_dataloaders):
# check dataloaders
lens = []
for task_info, dataloader in zip(task_infos, task_dataloaders):
# For evaluation and testing, we allow some of the val_dataloaders or test_dataloaders
# to be empty (None).
assert isinstance(dataloader, (GSgnnEdgeDataLoaderBase,
GSgnnLinkPredictionDataLoaderBase,
GSgnnNodeDataLoaderBase)), \
GSgnnNodeDataLoaderBase)) or dataloader is None, \
"The task data loader should be an instance of GSgnnEdgeDataLoaderBase, " \
"GSgnnLinkPredictionDataLoaderBase or GSgnnNodeDataLoaderBase"
num_iters = len(dataloader)
"GSgnnLinkPredictionDataLoaderBase or GSgnnNodeDataLoaderBase" \
f"But get {type(dataloader)}"
num_iters = len(dataloader) if dataloader is not None else 0
lens.append(num_iters)
logging.debug("Task %s has number of iterations of %d",
task_info, num_iters)
Expand All @@ -1728,7 +1731,8 @@ def _reset_loader(self):
""" reset the dataloaders
"""
for dataloader in self._dataloaders:
iter(dataloader)
if dataloader is not None:
iter(dataloader)
self._num_iters = 0

def __iter__(self):
Expand All @@ -1747,6 +1751,19 @@ def __next__(self):
# call __next__ of each dataloader
mini_batches = []
for task_info, dataloader in zip(self._task_infos, self._dataloaders):
if dataloader is None:
# The dataloader is None
logging.warning("The dataloader of %s is None. "
"Please check whether the coresponding "
"train/val/test mask(s) are missing."
"If you are calling iter(mt_dataloader) for validation "
"or testing, we suggest you to use "
"mt_dataloader.dataloaders to get task specific "
"dataloaders and call the corresponding evaluators "
"task by task", task_info.task_id)
mini_batches.append((task_info, None))
continue

try:
mini_batch = next(dataloader)
except StopIteration:
Expand Down Expand Up @@ -1789,6 +1806,18 @@ def task_infos(self):
# useful for conducting validation scores and test scores.
return self._task_infos

@property
def fanout(self):
""" The fanout of each GNN layers of each dataloader

Returns
-------
list of list or list of dict of list : the fanouts for each GNN layer.
"""
fanouts = [dataloader.fanout if dataloader is not None \
else None for dataloader in self.dataloaders]
return fanouts


####################### Distillation #############################

Expand Down
3 changes: 3 additions & 0 deletions python/graphstorm/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
GSgnnLinkPredictionModelBase,
GSgnnLinkPredictionModelInterface,
run_lp_mini_batch_predict)
from .multitask_gnn import (GSgnnMultiTaskModelInterface,
GSgnnMultiTaskSharedEncoderModel)
from .multitask_gnn import multi_task_mini_batch_predict
from .rgcn_encoder import RelationalGCNEncoder, RelGraphConvLayer
from .rgat_encoder import RelationalGATEncoder, RelationalAttLayer
from .sage_encoder import SAGEEncoder, SAGEConv
Expand Down
Loading
Loading