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

Fix heterogeneous temporal sampling #102

Merged
merged 2 commits into from
Sep 12, 2022
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
### Added
- Added CSC mode to `pyg::sampler::neighbor_sample` and `pyg::sampler::hetero_neighbor_sample` ([#95](https://github.com/pyg-team/pyg-lib/pull/95), [#96](https://github.com/pyg-team/pyg-lib/pull/96))
- Speed up `pyg::sampler::neighbor_sample` via `IndexTracker` implementation ([#84](https://github.com/pyg-team/pyg-lib/pull/84))
- Added `pyg::sampler::hetero_neighbor_sample` implementation ([#90](https://github.com/pyg-team/pyg-lib/pull/90), [#92](https://github.com/pyg-team/pyg-lib/pull/92), [#94](https://github.com/pyg-team/pyg-lib/pull/94), [#97](https://github.com/pyg-team/pyg-lib/pull/97), [#98](https://github.com/pyg-team/pyg-lib/pull/98), [#99](https://github.com/pyg-team/pyg-lib/pull/99))
- Added `pyg::sampler::hetero_neighbor_sample` implementation ([#90](https://github.com/pyg-team/pyg-lib/pull/90), [#92](https://github.com/pyg-team/pyg-lib/pull/92), [#94](https://github.com/pyg-team/pyg-lib/pull/94), [#97](https://github.com/pyg-team/pyg-lib/pull/97), [#98](https://github.com/pyg-team/pyg-lib/pull/98), [#99](https://github.com/pyg-team/pyg-lib/pull/99), [#102](https://github.com/pyg-team/pyg-lib/pull/102))
- Added `pyg::utils::to_vector` implementation ([#88](https://github.com/pyg-team/pyg-lib/pull/88))
- Added support for PyTorch 1.12 ([#57](https://github.com/pyg-team/pyg-lib/pull/57), [#58](https://github.com/pyg-team/pyg-lib/pull/58))
- Added `grouped_matmul` and `segment_matmul` CUDA implementations via `cutlass` ([#51](https://github.com/pyg-team/pyg-lib/pull/51), [#56](https://github.com/pyg-team/pyg-lib/pull/56), [#61](https://github.com/pyg-team/pyg-lib/pull/61), [#64](https://github.com/pyg-team/pyg-lib/pull/64), [#69](https://github.com/pyg-team/pyg-lib/pull/69))
Expand Down
28 changes: 27 additions & 1 deletion pyg_lib/csrc/sampler/cpu/neighbor_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ sample(const at::Tensor& rowptr,
TORCH_CHECK(!time.has_value() || disjoint,
"Temporal sampling needs to create disjoint subgraphs");

TORCH_CHECK(rowptr.is_contiguous(), "Non-contiguous 'rowptr' vector");
TORCH_CHECK(col.is_contiguous(), "Non-contiguous 'col' vector");
TORCH_CHECK(seed.is_contiguous(), "Non-contiguous 'seed' vector");
if (time.has_value()) {
TORCH_CHECK(time.value().is_contiguous(), "Non-contiguous 'time' vector");
}

at::Tensor out_row, out_col, out_node_id;
c10::optional<at::Tensor> out_edge_id = c10::nullopt;

Expand Down Expand Up @@ -295,6 +302,25 @@ sample(const std::vector<node_type>& node_types,
TORCH_CHECK(!time_dict.has_value() || disjoint,
"Temporal sampling needs to create disjoint subgraphs");

for (const auto& kv : rowptr_dict) {
const at::Tensor& rowptr = kv.value();
TORCH_CHECK(rowptr.is_contiguous(), "Non-contiguous 'rowptr' vector");
}
for (const auto& kv : col_dict) {
const at::Tensor& col = kv.value();
TORCH_CHECK(col.is_contiguous(), "Non-contiguous 'col' vector");
}
for (const auto& kv : seed_dict) {
const at::Tensor& seed = kv.value();
TORCH_CHECK(seed.is_contiguous(), "Non-contiguous 'seed' vector");
}
if (time_dict.has_value()) {
for (const auto& kv : time_dict.value()) {
const at::Tensor& time = kv.value();
TORCH_CHECK(time.is_contiguous(), "Non-contiguous 'time' vector");
}
}

c10::Dict<rel_type, at::Tensor> out_row_dict, out_col_dict;
c10::Dict<node_type, at::Tensor> out_node_id_dict;
c10::optional<c10::Dict<node_type, at::Tensor>> out_edge_id_dict;
Expand Down Expand Up @@ -370,7 +396,7 @@ sample(const std::vector<node_type>& node_types,
for (size_t j = 0; j < seed.numel(); j++) {
sampled_nodes.push_back({i, seed_data[j]});
mapper.insert({i, seed_data[j]});
seed_times.push_back(time_data[j]);
seed_times.push_back(time_data[seed_data[j]]);
i++;
}
}
Expand Down