Skip to content

Commit

Permalink
fixing to_data_list
Browse files Browse the repository at this point in the history
  • Loading branch information
levtelyatnikov committed May 14, 2024
1 parent db35363 commit ec42f1e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion configs/train.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
defaults:
- _self_
- dataset: NCI1 #us_country_demos
- model: hypergraph/edgnn #hypergraph/unignn2 #allsettransformer
- model: simplicial/scn #hypergraph/unignn2 #allsettransformer
- evaluator: default
- callbacks: default
- logger: wandb # set logger here or use command line (e.g. `python train.py logger=tensorboard`)
Expand Down
15 changes: 10 additions & 5 deletions topobenchmarkx/data/dataloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ def __cat_dim__(self, key: str, value: Any, *args, **kwargs) -> Any:
def to_data_list(batch):
"""Workaround needed since torch_geometric doesn't work well with
torch.sparse."""
for key in batch:
for key in batch.keys():
if batch[key].is_sparse:
sparse_data = batch[key].coalesce()
batch[key] = SparseTensor.from_torch_sparse_coo_tensor(sparse_data)
data_list = batch.to_data_list()

for i, data in enumerate(data_list):
for key in data:
if isinstance(data[key], SparseTensor):
Expand Down Expand Up @@ -65,10 +66,9 @@ def collate_fn(batch):
value = value.coalesce()
data[key] = value

# Generate batch_slice values for x_2, x_3, ...
# Generate batch_slice values for x_1, x_2, x_3, ...
x_keys = [el for el in keys if ("x_" in el)]
for x_key in x_keys:
# current_number_of_nodes = data["x_0"].shape[0]
if x_key != "x_0":
if x_key != "x_hyperedges":
cell_dim = int(x_key.split("_")[1])
Expand All @@ -86,12 +86,12 @@ def collate_fn(batch):
is None
):
running_idx[f"cell_running_idx_number_{cell_dim}"] = (
current_number_of_cells # current_number_of_nodes
current_number_of_cells
)

else:
running_idx[f"cell_running_idx_number_{cell_dim}"] += (
current_number_of_cells # current_number_of_nodes
current_number_of_cells
)

data_list.append(data)
Expand All @@ -104,6 +104,11 @@ def collate_fn(batch):
# Add batch slices to batch
for key, value in batch_idx_dict.items():
batch[key] = torch.cat(value, dim=1).squeeze(0).long()

# Ensure shape is torch.Tensor
# "shape" describes the number of n_cells in each graph
batch["shape"] = torch.Tensor(batch["shape"]).long()
to_data_list(batch)
return batch


Expand Down

0 comments on commit ec42f1e

Please sign in to comment.