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

Biased RW implementation and test #4499

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
12af533
Biased RW implementation and test
Jun 24, 2024
fd7f7fc
Updated per specifications in PR
Jun 26, 2024
e44890e
Biased RW implementation and test
Jun 24, 2024
03eb26b
Merge branch 'branch-24.08' into branch-24.08_RandomWalks
G-Cornett Jul 1, 2024
171aef8
WIP Node2Vec and main branch merge
G-Cornett Jul 2, 2024
322f129
Merge branch 'branch-24.08' into branch-24.08_RandomWalks
G-Cornett Jul 2, 2024
24135b8
Update new files to take rng_state
G-Cornett Jul 2, 2024
ffa1219
removed old files
G-Cornett Jul 2, 2024
3b4716d
Merge branch 'branch-24.08' into branch-24.08_RandomWalks
G-Cornett Jul 8, 2024
a3592ff
Minor change to allow const iterator compatability
G-Cornett Jul 8, 2024
650c5dd
Merge branch 'branch-24.08' into branch-24.08_RandomWalks
G-Cornett Jul 9, 2024
4cd2d06
SG Node2Vec (pre-generic refactoring)
G-Cornett Jul 11, 2024
fe41bf1
Merge branch 'branch-24.08' into branch-24.08_RandomWalks
G-Cornett Jul 11, 2024
5672493
Merge branch 'branch-24.08' into branch-24.08_RandomWalks
G-Cornett Jul 16, 2024
57b83b9
Merge branch 'branch-24.08' into branch-24.08_RandomWalks
G-Cornett Jul 17, 2024
80be067
Generic RW refactor to allow node2vec correct shuffling. Biased RW S…
G-Cornett Jul 23, 2024
d13dd95
Merge branch 'branch-24.08' into branch-24.08_RandomWalks
G-Cornett Jul 23, 2024
a55d88c
Merge branch 'rapidsai:branch-24.08' into branch-24.08_RandomWalks
G-Cornett Jul 26, 2024
597530b
Bug fixes
G-Cornett Jul 31, 2024
941086e
Merge branch 'branch-24.10' into branch-24.08_RandomWalks
G-Cornett Aug 8, 2024
a7c6a22
Node2Vec MG retool and bug fixes
G-Cornett Aug 8, 2024
b57fcb7
rng_state repositioning and changes per PR review
G-Cornett Aug 9, 2024
c50165a
Merge branch 'branch-24.10' into branch-24.08_RandomWalks
G-Cornett Aug 13, 2024
3f300c2
PR review changes (full)
G-Cornett Aug 15, 2024
d791b95
Merge branch 'branch-24.10' into branch-24.08_RandomWalks
G-Cornett Aug 15, 2024
28ef4f2
Fixed SG/MG compatability issue
G-Cornett Aug 16, 2024
0a34c25
Merge branch 'branch-24.10' into branch-24.08_RandomWalks
G-Cornett Aug 21, 2024
30815d5
PR review changes, general polishing, SG uniform unblocked
G-Cornett Aug 29, 2024
35cd032
Merge branch 'branch-24.10' into branch-24.08_RandomWalks
G-Cornett Aug 29, 2024
c88144b
Merge branch 'branch-24.10' into branch-24.08_RandomWalks
G-Cornett Aug 30, 2024
c5eac6a
Merge branch 'rapidsai:branch-24.10' into branch-24.08_RandomWalks
G-Cornett Sep 3, 2024
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
78 changes: 75 additions & 3 deletions cpp/src/sampling/random_walks_impl.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "detail/graph_partition_utils.cuh"
#include "prims/per_v_random_select_transform_outgoing_e.cuh"
#include "prims/vertex_frontier.cuh"
#include "prims/property_op_utils.cuh"

#include <cugraph/algorithms.hpp>
#include <cugraph/detail/shuffle_wrappers.hpp>
Expand All @@ -29,6 +30,7 @@
#include <cugraph/partition_manager.hpp>
#include <cugraph/utilities/host_scalar_comm.hpp>
#include <cugraph/utilities/shuffle_comm.cuh>
#include <cugraph/graph_functions.hpp>

#include <raft/core/handle.hpp>
#include <raft/random/rng.cuh>
Expand Down Expand Up @@ -70,6 +72,18 @@ struct sample_edges_op_t {
}
};

template <typename vertex_t, typename bias_t>
struct e_bias_op_t {

raft::device_span<bias_t const> vertex_weight_sum{};

__device__ bias_t
operator()(vertex_t src, vertex_t, thrust::nullopt_t, thrust::nullopt_t, bias_t weight) const
{
G-Cornett marked this conversation as resolved.
Show resolved Hide resolved
return weight / vertex_weight_sum[src];
}
};
G-Cornett marked this conversation as resolved.
Show resolved Hide resolved
G-Cornett marked this conversation as resolved.
Show resolved Hide resolved

template <typename weight_t>
struct uniform_selector {
raft::random::RngState rng_state_;
Expand Down Expand Up @@ -139,7 +153,9 @@ struct uniform_selector {

template <typename weight_t>
struct biased_selector {
uint64_t seed_{0};
raft::random::RngState rng_state_;
G-Cornett marked this conversation as resolved.
Show resolved Hide resolved

biased_selector(uint64_t seed) : rng_state_(seed) {}
G-Cornett marked this conversation as resolved.
Show resolved Hide resolved

template <typename GraphViewType>
std::tuple<rmm::device_uvector<typename GraphViewType::vertex_type>,
Expand All @@ -156,7 +172,63 @@ struct biased_selector {
// instead of making a decision based on the index I need to find
// upper_bound (or is it lower_bound) of the random number and
// the cumulative weight.
CUGRAPH_FAIL("biased sampling not implemented");

// Create vertex frontier
using vertex_t = typename GraphViewType::vertex_type;

using tag_t = void;

cugraph::vertex_frontier_t<vertex_t, tag_t, GraphViewType::is_multi_gpu, false> vertex_frontier(handle, 1);

vertex_frontier.bucket(0).insert(current_vertices.begin(), current_vertices.end());

// Create data structs for results
rmm::device_uvector<vertex_t> minors(0, handle.get_stream());
// Should this be optional? Necessary for biased
std::optional<rmm::device_uvector<weight_t>> weights{std::nullopt};

if (edge_weight_view) {
auto vertex_weight_sum = compute_out_weight_sums(handle, graph_view, *edge_weight_view);
auto [sample_offsets, sample_e_op_results] =
cugraph::per_v_random_select_transform_outgoing_e(
handle,
graph_view,
vertex_frontier.bucket(0),
cugraph::edge_src_dummy_property_t{}.view(),
cugraph::edge_dst_dummy_property_t{}.view(),
*edge_weight_view,
e_bias_op_t<vertex_t, weight_t>{
raft::device_span<weight_t const>(vertex_weight_sum.data(), vertex_weight_sum.size())},
sample_edges_op_t<vertex_t, weight_t>{},
rng_state_,
size_t{1},
true,
std::make_optional(
thrust::make_tuple(vertex_t{cugraph::invalid_vertex_id<vertex_t>::value}, weight_t{0.0})));
minors = std::move(std::get<0>(sample_e_op_results));
weights = std::move(std::get<1>(sample_e_op_results));
} else {
// Just uniform random walk
G-Cornett marked this conversation as resolved.
Show resolved Hide resolved
auto [sample_offsets, sample_e_op_results] =
cugraph::per_v_random_select_transform_outgoing_e(
handle,
graph_view,
vertex_frontier.bucket(0),
cugraph::edge_src_dummy_property_t{}.view(),
cugraph::edge_dst_dummy_property_t{}.view(),
cugraph::edge_dummy_property_t{}.view(),
sample_edges_op_t<vertex_t, void>{},
rng_state_,
size_t{1},
true,
std::make_optional(vertex_t{cugraph::invalid_vertex_id<vertex_t>::value}));

minors = std::move(sample_e_op_results);
}

// Return results
return std::make_tuple(std::move(minors), std::move(weights));

}
};

Expand Down Expand Up @@ -483,7 +555,7 @@ biased_random_walks(raft::handle_t const& handle,
std::optional<edge_property_view_t<edge_t, weight_t const*>>{edge_weight_view},
start_vertices,
max_length,
detail::biased_selector<weight_t>{(seed == 0 ? detail::get_current_time_nanoseconds() : seed)});
detail::biased_selector<weight_t>((seed == 0 ? detail::get_current_time_nanoseconds() : seed)));
G-Cornett marked this conversation as resolved.
Show resolved Hide resolved
}

template <typename vertex_t, typename edge_t, typename weight_t, bool multi_gpu>
Expand Down
4 changes: 2 additions & 2 deletions cpp/tests/sampling/mg_random_walks_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct BiasedRandomWalks_Usecase {
}

// FIXME: Not currently implemented
bool expect_throw() { return true; }
bool expect_throw() { return !test_weighted; }
};

struct Node2VecRandomWalks_Usecase {
Expand Down Expand Up @@ -295,7 +295,7 @@ INSTANTIATE_TEST_SUITE_P(
cugraph::test::File_Usecase("test/datasets/web-Google.mtx"),
cugraph::test::File_Usecase("test/datasets/ljournal-2008.mtx"),
cugraph::test::File_Usecase("test/datasets/webbase-1M.mtx"))));

INSTANTIATE_TEST_SUITE_P(
simple_test,
Tests_BiasedRandomWalks_File,
Expand Down
2 changes: 1 addition & 1 deletion cpp/tests/sampling/sg_random_walks_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct BiasedRandomWalks_Usecase {
}

// FIXME: Not currently implemented
bool expect_throw() { return true; }
bool expect_throw() { return !test_weighted; }
};

struct Node2VecRandomWalks_Usecase {
Expand Down
Loading