forked from PaddlePaddle/Paddle
-
Notifications
You must be signed in to change notification settings - Fork 2
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
Add Simple Loading for Direct Graph #1
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,16 @@ | |
#include "paddle/fluid/distributed/table/common_graph_table.h" | ||
#include <algorithm> | ||
#include <sstream> | ||
#include <time.h> | ||
#include <set> | ||
#include "paddle/fluid/distributed/common/utils.h" | ||
#include "paddle/fluid/string/printf.h" | ||
#include "paddle/fluid/string/string_helper.h" | ||
namespace paddle { | ||
namespace distributed { | ||
|
||
int GraphShard::bucket_low_bound = 11; | ||
|
||
std::vector<GraphNode *> GraphShard::get_batch(int start, int total_size) { | ||
if (start < 0) start = 0; | ||
int size = 0, cur_size; | ||
|
@@ -51,68 +55,81 @@ std::vector<GraphNode *> GraphShard::get_batch(int start, int total_size) { | |
} | ||
return res; | ||
} | ||
|
||
size_t GraphShard::get_size() { | ||
size_t res = 0; | ||
for (int i = 0; i < bucket_size; i++) { | ||
res += bucket[i].size(); | ||
} | ||
return res; | ||
} | ||
|
||
std::list<GraphNode *>::iterator GraphShard::add_node(GraphNode *node) { | ||
if (node_location.find(node->get_id()) != node_location.end()) | ||
return node_location.find(node->get_id())->second; | ||
|
||
int index = node->get_id() % shard_num % bucket_size; | ||
|
||
std::list<GraphNode *>::iterator iter = | ||
bucket[index].insert(bucket[index].end(), node); | ||
|
||
node_location[node->get_id()] = iter; | ||
return iter; | ||
} | ||
|
||
void GraphShard::add_neighboor(uint64_t id, GraphEdge *edge) { | ||
(*add_node(new GraphNode(id, std::string(""))))->add_edge(edge); | ||
} | ||
|
||
GraphNode *GraphShard::find_node(uint64_t id) { | ||
if (node_location.find(id) == node_location.end()) return NULL; | ||
return *(node_location[id]); | ||
} | ||
|
||
int32_t GraphTable::load(const std::string &path, const std::string ¶m) { | ||
auto cmd = paddle::string::split_string<std::string>(param, "|"); | ||
std::set<std::string> cmd_set(cmd.begin(), cmd.end()); | ||
bool load_edge = cmd_set.count(std::string("edge")); | ||
bool reverse_edge = cmd_set.count(std::string("reverse")); | ||
VLOG(0) << "Reverse Edge " << reverse_edge; | ||
|
||
auto paths = paddle::string::split_string<std::string>(path, ";"); | ||
VLOG(0) << paths.size(); | ||
int count = 0; | ||
|
||
for (auto path : paths) { | ||
std::ifstream file(path); | ||
std::string line; | ||
while (std::getline(file, line)) { | ||
auto values = paddle::string::split_string<std::string>(line, "\t"); | ||
count ++; | ||
if (values.size() < 2) continue; | ||
auto id = std::stoull(values[0]); | ||
size_t shard_id = id % shard_num; | ||
if (shard_id >= shard_end || shard_id < shard_start) { | ||
VLOG(0) << "will not load " << id << " from " << path | ||
auto src_id = std::stoull(values[0]); | ||
auto dst_id = std::stoull(values[1]); | ||
if(reverse_edge) { | ||
std::swap(src_id, dst_id); | ||
} | ||
double weight = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. float? |
||
if (values.size() == 3) { | ||
weight = std::stod(values[2]); | ||
} | ||
size_t src_shard_id = src_id % shard_num; | ||
|
||
if (src_shard_id >= shard_end || src_shard_id < shard_start) { | ||
VLOG(0) << "will not load " << src_id << " from " << path | ||
<< ", please check id distribution"; | ||
continue; | ||
|
||
} | ||
size_t index = shard_id - shard_start; | ||
// GraphNodeType type = GraphNode::get_graph_node_type(values[1]); | ||
// VLOG(0)<<"shards's size = "<<shards.size()<<" values' size = | ||
// "<<values.size(); | ||
// VLOG(0)<<"add to index "<<index<<" table rank = "<<_shard_idx; | ||
shards[index].add_node(new GraphNode(id, values[1])); | ||
// VLOG(0)<<"checking added of rank "<<_shard_idx<<" shard "<<index<<" | ||
// "<<cc->get_id(); | ||
for (size_t i = 2; i < values.size(); i++) { | ||
auto edge_arr = | ||
paddle::string::split_string<std::string>(values[i], ";"); | ||
if (edge_arr.size() == 2) { | ||
// VLOG(0)<<"edge content "<<edge_arr[0]<<" "<<edge_arr[1]<<" | ||
// "<<edge_arr[2]; | ||
auto edge_id = std::stoull(edge_arr[0]); | ||
auto weight = std::stod(edge_arr[1]); | ||
// VLOG(0)<<"edge_id "<<edge_id<<" weight "<<weight; | ||
GraphEdge *edge = new GraphEdge(edge_id, weight); | ||
shards[index].add_neighboor(id, edge); | ||
} | ||
} | ||
size_t index = src_shard_id - shard_start; | ||
GraphEdge *edge = new GraphEdge(dst_id, weight); | ||
shards[index].add_neighboor(src_id, edge); | ||
} | ||
for (auto &shard : shards) { | ||
} | ||
VLOG(0) << "Load Finished Total Edge Count " << count; | ||
|
||
// Build Sampler j | ||
for (auto &shard : shards) { | ||
auto bucket = shard.get_bucket(); | ||
for (int i = 0; i < bucket.size(); i++) { | ||
std::list<GraphNode *>::iterator iter = bucket[i].begin(); | ||
|
@@ -122,7 +139,6 @@ int32_t GraphTable::load(const std::string &path, const std::string ¶m) { | |
iter++; | ||
} | ||
} | ||
} | ||
} | ||
return 0; | ||
} | ||
|
@@ -144,6 +160,7 @@ int32_t GraphTable::random_sample(uint64_t node_id, int sample_size, | |
char *&buffer, int &actual_size) { | ||
return _shards_task_pool[get_thread_pool_index(node_id)] | ||
->enqueue([&]() -> int { | ||
|
||
GraphNode *node = find_node(node_id); | ||
if (node == NULL) { | ||
actual_size = 0; | ||
|
@@ -275,4 +292,4 @@ int32_t GraphTable::initialize() { | |
return 0; | ||
} | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
load_edge这个变量好像后续没用到