未验证 提交 553c279b 编写于 作者: Y Yiqun Liu 提交者: GitHub

Move tensor to numpy from print. (#4950)

上级 d60dee05
......@@ -444,8 +444,9 @@ def train_ptb_lm():
dy_loss.backward()
sgd.minimize(dy_loss)
ptb_model.clear_gradients()
global_lr = sgd._global_learning_rate().numpy()
total_loss += out_loss
iters += num_steps
total_batch_num = total_batch_num + 1 #this is for benchmark
......@@ -457,8 +458,7 @@ def train_ptb_lm():
ppl = np.exp(total_loss / iters)
print(
"-- Epoch:[%d]; Batch:[%d]; ppl: %.5f, lr: %.5f, loss: %.5f, batch_cost: %.5f sec, reader_cost: %.5f sec, ips: %.5f words/sec"
% (epoch_id, batch_id, ppl[0],
sgd._global_learning_rate().numpy(), out_loss,
% (epoch_id, batch_id, ppl[0], global_lr, out_loss,
batch_cost_avg.get_average(),
reader_cost_avg.get_average(),
batch_size / batch_cost_avg.get_average()))
......
......@@ -170,22 +170,22 @@ def main():
batch, epoch_id=epoch_id)
word_count += word_num
loss = model(input_data_feed)
# print(loss.numpy()[0])
loss.backward()
optimizer.minimize(loss)
model.clear_gradients()
total_loss += loss * batch_size
total_loss_value = total_loss.numpy()
train_batch_cost = time.time() - batch_start
batch_times.append(train_batch_cost)
batch_times.append(time.time() - batch_start)
if batch_id > 0 and batch_id % 100 == 0:
print(
"-- Epoch:[%d]; Batch:[%d]; ppl: %.5f, batch_cost: %.5f s, reader_cost: %.5f s, ips: %.5f words/s"
% (epoch_id, batch_id, np.exp(total_loss.numpy() /
"-- Epoch:[%d]; Batch:[%d]; ppl: %.5f, batch_cost: %.5f sec, reader_cost: %.5f sec, ips: %.5f words/sec"
% (epoch_id, batch_id, np.exp(total_loss_value /
word_count),
train_batch_cost, total_reader_cost / 100,
(time.time() - interval_time_start) / 100,
total_reader_cost / 100,
word_count / (time.time() - interval_time_start)))
ce_ppl.append(np.exp(total_loss.numpy() / word_count))
ce_ppl.append(np.exp(total_loss_value / word_count))
total_loss = 0.0
word_count = 0.0
total_reader_cost = 0.0
......@@ -194,7 +194,7 @@ def main():
train_epoch_cost = time.time() - epoch_start
print(
"\nTrain epoch:[%d]; epoch_cost: %.5f s; avg_batch_cost: %.5f s/step\n"
"\nTrain epoch:[%d]; epoch_cost: %.5f sec; avg_batch_cost: %.5f s/step\n"
% (epoch_id, train_epoch_cost,
sum(batch_times) / len(batch_times)))
ce_time.append(train_epoch_cost)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册