未验证 提交 6c14f65e 编写于 作者: Z zhang wenhui 提交者: GitHub

update1.7 save/load & fluid.data (#4283)

上级 768938c1
......@@ -47,8 +47,7 @@ def infer(args, vocab_size, test_reader, use_cuda):
for epoch in range(start_index, last_index + 1):
copy_program = main_program.clone()
model_path = model_dir + "/epoch_" + str(epoch)
fluid.io.load_params(
executor=exe, dirname=model_path, main_program=copy_program)
fluid.load(copy_program, model_path, exe)
accum_num_recall = 0.0
accum_num_sum = 0.0
t0 = time.time()
......
......@@ -121,7 +121,7 @@ def train():
print("epoch:%d num_steps:%d time_cost(s):%f" %
(epoch_idx, i, total_time / epoch_idx))
save_dir = "%s/epoch_%d" % (model_dir, epoch_idx)
fluid.io.save_params(executor=exe, dirname=save_dir)
fluid.save(fluid.default_main_program(), model_path=save_dir)
print("model saved in %s" % save_dir)
print("finish training")
......
......@@ -59,27 +59,14 @@ def mmoe_layer(inputs, expert_num=8, gate_num=3):
def model(dict_dim, emb_dim):
label_like = fluid.layers.data(
name="label_like",
shape=[-1, 1],
dtype="int64",
lod_level=0,
append_batch_size=False)
label_comment = fluid.layers.data(
name="label_comment",
shape=[-1, 1],
dtype="int64",
lod_level=0,
append_batch_size=False)
label_share = fluid.layers.data(
name="label_share",
shape=[-1, 1],
dtype="int64",
lod_level=0,
append_batch_size=False)
a_data = fluid.layers.data(
name="a", shape=[-1, 1], dtype="int64", append_batch_size=False)
label_like = fluid.data(
name="label_like", shape=[-1, 1], dtype="int64", lod_level=0)
label_comment = fluid.data(
name="label_comment", shape=[-1, 1], dtype="int64", lod_level=0)
label_share = fluid.data(
name="label_share", shape=[-1, 1], dtype="int64", lod_level=0)
a_data = fluid.data(name="a", shape=[-1, 1], dtype="int64")
emb = fluid.layers.embedding(input=a_data, size=[dict_dim, emb_dim])
outs = mmoe_layer(emb, expert_num=8, gate_num=3)
......
......@@ -121,7 +121,7 @@ def train_loop(main_program, avg_cost, acc, train_input_data, place, args,
print("epoch:%d num_steps:%d time_cost(s):%f" %
(epoch_idx, i, total_time / epoch_idx))
save_dir = "%s/epoch_%d" % (args.model_dir, epoch_idx)
fluid.io.save_params(executor=exe, dirname=save_dir)
fluid.save(fluid.default_main_program(), save_dir)
print("model saved in %s" % save_dir)
# only for ce
......
......@@ -84,8 +84,7 @@ def infer(args, vocab_size, test_reader):
for epoch in range(start_index, last_index + 1):
copy_program = main_program.clone()
model_path = model_dir + "/epoch_" + str(epoch)
fluid.io.load_params(
executor=exe, dirname=model_path, main_program=copy_program)
fluid.load(copy_program, model_path, exe)
accum_num_recall = 0.0
accum_num_sum = 0.0
t0 = time.time()
......
......@@ -121,7 +121,7 @@ def train(args):
print("epoch:%d num_steps:%d time_cost(s):%f" %
(epoch_idx, i, total_time / epoch_idx))
save_dir = "%s/epoch_%d" % (args.model_dir, epoch_idx)
fluid.io.save_params(executor=exe, dirname=save_dir)
fluid.save(fluid.default_main_program(), model_path=save_dir)
print("model saved in %s" % save_dir)
# only for ce
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册