Skip to content

Commit

Permalink
[PSLIB] Add Metrics Module, Support User-defined Add Metric (PaddlePa…
Browse files Browse the repository at this point in the history
…ddle#38789)

* [PSLIB] Add Metrics Module, Support User-defined Add Metric

* [PSLIB] Modify According to CI

* [PSLIB] Modify According to CI

* [PSLIB] Modify According to CI

* [PSLIB] Modify According to CI Coverage

* [PSLIB] Modify According to CI

* [PSLIB] Modify According to CI

* [PSLIB] Modify According to CI

* [PSLIB] Modify According to CI

* [PSLIB] Modify According to CI

* [PSLIB] Modify According to CI Coverage

* [PSLIB] Modify According to CI Coverage

* [PSLIB] Modify According to CI Coverage

* modify role_maker

* update CMakeLists.txt
  • Loading branch information
WorgenZhang committed Jan 28, 2022
1 parent 8894d78 commit dfe01b8
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
1 change: 0 additions & 1 deletion paddle/fluid/framework/data_feed.cc
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,6 @@ bool MultiSlotInMemoryDataFeed::ParseOneInstanceFromPipe(Record* instance) {
uint64_t feasign = (uint64_t)strtoull(uidptr, &uidptr, 10);
instance->uid_ = feasign;
}

if (idx != -1) {
if (all_slots_type_[i][0] == 'f') { // float
for (int j = 0; j < num; ++j) {
Expand Down
2 changes: 2 additions & 0 deletions paddle/fluid/framework/fleet/metrics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ void BasicAucCalculator::compute() {
}

void BasicAucCalculator::calculate_bucket_error() {
#if defined(PADDLE_WITH_GLOO)
double last_ctr = -1;
double impression_sum = 0;
double ctr_sum = 0.0;
Expand Down Expand Up @@ -234,6 +235,7 @@ void BasicAucCalculator::calculate_bucket_error() {
}
}
_bucket_error = error_count > 0 ? error_sum / error_count : 0.0;
#endif
}

void BasicAucCalculator::reset_records() {
Expand Down
30 changes: 23 additions & 7 deletions paddle/fluid/framework/fleet/metrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,16 +650,32 @@ class Metric {
metric_return_values_[1] = auc_cal_->size();
metric_return_values_[2] = auc_cal_->uauc();
metric_return_values_[3] = auc_cal_->wuauc();
metric_return_values_[4] =
metric_return_values_[2] / (metric_return_values_[0] + 1e-10);
metric_return_values_[5] =
metric_return_values_[3] / (metric_return_values_[1] + 1e-10);

#if defined(PADDLE_WITH_GLOO)
auto gloo_wrapper = paddle::framework::GlooWrapper::GetInstance();
auto global_metric_return_values_ =
gloo_wrapper->AllReduce(metric_return_values_, "sum");
global_metric_return_values_[4] = global_metric_return_values_[2] /
(global_metric_return_values_[0] + 1e-10);
global_metric_return_values_[5] = global_metric_return_values_[3] /
(global_metric_return_values_[1] + 1e-10);
if (gloo_wrapper->Size() > 1) {
auto global_metric_return_values_ =
gloo_wrapper->AllReduce(metric_return_values_, "sum");
global_metric_return_values_[4] =
global_metric_return_values_[2] /
(global_metric_return_values_[0] + 1e-10);
global_metric_return_values_[5] =
global_metric_return_values_[3] /
(global_metric_return_values_[1] + 1e-10);
auc_cal_->reset_records();
return global_metric_return_values_;
} else {
auc_cal_->reset_records();
return metric_return_values_;
}
#else
auc_cal_->reset_records();
return global_metric_return_values_;
return metric_return_values_;
#endif
}

private:
Expand Down
3 changes: 0 additions & 3 deletions paddle/fluid/pybind/metrics_py.cc
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
/* Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
8 changes: 8 additions & 0 deletions python/paddle/fluid/tests/unittests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ def test_config(self):
self.assertTrue(dataset.parse_ins_id)
self.assertTrue(dataset.parse_content)

def test_shuffle_by_uid(self):
"""
Testcase for shuffle_by_uid.
"""
dataset = paddle.distributed.InMemoryDataset()
dataset._set_uid_slot('6048')
dataset._set_shuffle_by_uid(True)

def test_run_with_dump(self):
"""
Testcase for InMemoryDataset from create to run.
Expand Down

0 comments on commit dfe01b8

Please sign in to comment.