Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#48 from FrostML/pe-print
Browse files Browse the repository at this point in the history
alter pe print
  • Loading branch information
guoshengCS authored Mar 2, 2021
2 parents 33f5073 + 62ba288 commit 054c95e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions benchmark/transformer/static/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
logging.basicConfig(level=logging.INFO, format=FORMAT)
logger = logging.getLogger(__name__)


def cast_parameters_to_fp32(place, program, scope=None):
all_parameters = []
for block in program.blocks:
Expand All @@ -33,6 +34,7 @@ def cast_parameters_to_fp32(place, program, scope=None):
data = np.array(tensor)
tensor.set(np.float32(data), place)


def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
Expand Down
10 changes: 7 additions & 3 deletions benchmark/transformer/static/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def do_train(args):

if args.use_amp:
optimizer.amp_init(places[0])

# the best cross-entropy value with label smoothing
loss_normalizer = -(
(1. - args.label_smooth_eps) * np.log(
Expand Down Expand Up @@ -181,6 +181,9 @@ def do_train(args):
'lbl_word': data[i][2],
} for i in range(trainer_count)],
fetch_list=[sum_cost.name, token_num.name])
train_batch_cost = time.time() - batch_start
batch_ips_avg.record(train_batch_cost,
np.asarray(outs[1]).sum())
else:
outs = exe.run(compiled_train_program,
feed=[{
Expand All @@ -189,12 +192,13 @@ def do_train(args):
'lbl_word': data[i][2],
} for i in range(trainer_count)],
fetch_list=[sum_cost.name, token_num.name])
train_batch_cost = time.time() - batch_start
batch_ips_avg.record(train_batch_cost,
np.asarray(outs[1]).sum() / trainer_count)
scheduler.step()

train_batch_cost = time.time() - batch_start
reader_cost_avg.record(train_reader_cost)
batch_cost_avg.record(train_batch_cost)
batch_ips_avg.record(train_batch_cost, np.asarray(outs[1]).sum())

if step_idx % args.print_step == 0:
sum_cost_val, token_num_val = np.array(outs[0]), np.array(outs[
Expand Down

0 comments on commit 054c95e

Please sign in to comment.