MCPcopy Create free account
hub / github.com/Tencent/embedx / FetchServerDistribution

Function FetchServerDistribution

src/graph/client/resource_post_initializer.cc:43–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

41}
42
43bool FetchServerDistribution(int shard_num, int* ns_size, vec_float_t* probs) {
44 std::vector<vec_int_t> node_freqs_list;
45 auto* op = graph_op::DistGSOpFactory::GetInstance()->LookupOrCreate(
46 "DistMetaLookuper");
47 DXCHECK(op != nullptr);
48 if (!dynamic_cast<graph_op::DistMetaLookuper*>(op)->Run(&node_freqs_list)) {
49 DXERROR("Failed to fetch server distribution.");
50 return false;
51 }
52
53 DXINFO("Fetching server distribution...");
54 *ns_size = (int)node_freqs_list.size();
55 float_t freq_sum = 0;
56 vec_float_t freq_sums(shard_num, 0);
57 for (int i = 0; i < shard_num; ++i) {
58 for (int j = 0; j < *ns_size; ++j) {
59 freq_sum += node_freqs_list[j][i];
60 freq_sums[i] += node_freqs_list[j][i];
61 }
62 }
63
64 // fill
65 probs->resize(shard_num, 0.0);
66 for (int i = 0; i < shard_num; ++i) {
67 if (freq_sum != 0) {
68 (*probs)[i] = 1.0f * freq_sums[i] / freq_sum;
69 DXINFO("Server prob[%d] is: %f.", i, (*probs)[i]);
70 }
71 }
72
73 DXINFO("Done.");
74 return true;
75}
76
77} // namespace
78

Callers 1

Calls 2

LookupOrCreateMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected