From 5165c4c2a6d1e97a742178641db2ff9ab9f659e5 Mon Sep 17 00:00:00 2001 From: guosheng Date: Fri, 10 Aug 2018 00:05:58 +0800 Subject: [PATCH] Fix ce for multi-devices in Transformer --- .../transformer/_ce.py | 20 +++++++++++++------ .../transformer/train.py | 6 +++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/fluid/neural_machine_translation/transformer/_ce.py b/fluid/neural_machine_translation/transformer/_ce.py index e64d372d..49e67a63 100644 --- a/fluid/neural_machine_translation/transformer/_ce.py +++ b/fluid/neural_machine_translation/transformer/_ce.py @@ -7,14 +7,22 @@ from kpi import CostKpi, DurationKpi, AccKpi #### NOTE kpi.py should shared in models in some way!!!! -train_cost_kpi = CostKpi('train_cost', 0.01, 0, actived=True) -test_cost_kpi = CostKpi('test_cost', 0.005, 0, actived=True) -train_duration_kpi = DurationKpi('train_duration', 0.06, 0, actived=True) +train_cost_card1_kpi = CostKpi('train_cost_card1', 0.01, 0, actived=True) +test_cost_card1_kpi = CostKpi('test_cost_card1', 0.005, 0, actived=True) +train_duration_card1_kpi = DurationKpi( + 'train_duration_card1', 0.06, 0, actived=True) +train_cost_card4_kpi = CostKpi('train_cost_card4', 0.01, 0, actived=True) +test_cost_card4_kpi = CostKpi('test_cost_card4', 0.005, 0, actived=True) +train_duration_card4_kpi = DurationKpi( + 'train_duration_card4', 0.06, 0, actived=True) tracking_kpis = [ - train_cost_kpi, - test_cost_kpi, - train_duration_kpi, + train_cost_card1_kpi, + test_cost_card1_kpi, + train_duration_card1_kpi, + train_cost_card4_kpi, + test_cost_card4_kpi, + train_duration_card4_kpi, ] diff --git a/fluid/neural_machine_translation/transformer/train.py b/fluid/neural_machine_translation/transformer/train.py index beb2b7d3..1148fe58 100644 --- a/fluid/neural_machine_translation/transformer/train.py +++ b/fluid/neural_machine_translation/transformer/train.py @@ -463,9 +463,9 @@ def train_loop(exe, train_progm, dev_count, sum_cost, avg_cost, lr_scheduler, "pass_" + str(pass_id) + ".infer.model"), data_input_names[:-2] + util_input_names, [predict], exe) if args.enable_ce: # For CE - print("kpis\ttrain_cost\t%f" % total_avg_cost) - print("kpis\ttest_cost\t%f" % val_avg_cost) - print("kpis\ttrain_duration\t%f" % time_consumed) + print("kpis\ttrain_cost_card%d\t%f" % (dev_count, total_avg_cost)) + print("kpis\ttest_cost_card%d\t%f" % (dev_count, val_avg_cost)) + print("kpis\ttrain_duration_card%d\t%f" % (dev_count, time_consumed)) def train(args): -- GitLab