12 #include <sys/timeb.h> 18 void add_float(
float& c1,
const float& c2) { c1 += c2; }
23 float* local_grad =
new float[length];
26 for (uint64_t i = 0; i < length; i++)
29 for (uint64_t i = 0; i < length; i++)
32 all_reduce<float, add_float>(all, local_grad, length);
35 for (uint64_t i = 0; i < length; i++)
38 for (uint64_t i = 0; i < length; i++)
46 float temp = local_sum;
47 all_reduce<float, add_float>(all, &temp, 1);
55 float* local_grad =
new float[length];
58 for (uint64_t i = 0; i < length; i++)
61 for (uint64_t i = 0; i < length; i++)
64 all_reduce<float, add_float>(all, local_grad, length);
67 for (uint64_t i = 0; i < length; i++)
70 for (uint64_t i = 0; i < length; i++)
79 for (
int i = 1; i < length; i++)
88 for (
int i = 1; i < length; i++)
89 if (arr[i] < min && arr[i] > 0.001)
95 void do_weighting(
vw& all, uint64_t length,
float* local_weights, T& weights)
97 for (uint64_t i = 0; i < length; i++)
99 float*
weight = &weights[i << weights.stride_shift()];
100 if (local_weights[i] > 0)
102 float ratio = weight[1] / local_weights[i];
103 local_weights[i] = weight[0] * ratio;
111 local_weights[i] = 0;
121 all.
trace_message <<
"Weighted averaging is implemented only for adaptive gradient, use accumulate_avg instead\n";
125 uint32_t length = 1 << all.
num_bits;
126 float* local_weights =
new float[length];
129 for (uint64_t i = 0; i < length; i++)
132 for (uint64_t i = 0; i < length; i++)
136 all_reduce<float, add_float>(all, local_weights, length);
144 std::cout <<
"sparse parameters not supported with parallel computation!" << std::endl;
146 all_reduce<float, add_float>(
148 delete[] local_weights;
float max_elem(float *arr, int length)
void accumulate_weighted_avg(vw &all, parameters &weights)
void accumulate(vw &all, parameters &weights, size_t offset)
uint32_t stride_shift() const
float min_elem(float *arr, int length)
void do_weighting(vw &all, uint64_t length, float *local_weights, T &weights)
void accumulate_avg(vw &all, parameters &weights, size_t offset)
dense_parameters dense_weights
void add_float(float &c1, const float &c2)
constexpr uint64_t UINT64_ONE
sparse_parameters sparse_weights
float accumulate_scalar(vw &all, float local_sum)
uint32_t stride_shift() const