提交 71971366 编写于 作者: O overlordmax

Merge branch 'develop' of https://github.com/PaddlePaddle/models into pr_04221554

......@@ -6,18 +6,19 @@ sys.path.append(os.environ['ceroot'])
from kpi import CostKpi
from kpi import DurationKpi
each_pass_duration_card1_kpi = DurationKpi('each_pass_duration_card1', 0.08, 0, actived=True)
each_pass_duration_card1_kpi = DurationKpi(
'each_pass_duration_card1', 0.08, 0, actived=True)
train_loss_card1_kpi = CostKpi('train_loss_card1', 0.08, 0)
each_pass_duration_card4_kpi = DurationKpi('each_pass_duration_card4', 0.08, 0, actived=True)
each_pass_duration_card4_kpi = DurationKpi(
'each_pass_duration_card4', 0.08, 0, actived=True)
train_loss_card4_kpi = CostKpi('train_loss_card4', 0.08, 0)
tracking_kpis = [
each_pass_duration_card1_kpi,
train_loss_card1_kpi,
each_pass_duration_card4_kpi,
train_loss_card4_kpi,
]
each_pass_duration_card1_kpi,
train_loss_card1_kpi,
each_pass_duration_card4_kpi,
train_loss_card4_kpi,
]
def parse_log(log):
......
......@@ -79,16 +79,18 @@ def infer():
fetch_targets] = fluid.io.load_inference_model(model_path, exe)
loader = fluid.io.DataLoader.from_generator(
feed_list=[inference_program.block(0).var(e) for e in feed_target_names], capacity=10000, iterable=True)
feed_list=[
inference_program.block(0).var(e) for e in feed_target_names
],
capacity=10000,
iterable=True)
loader.set_sample_list_generator(data_reader, places=place)
loss_sum = 0.0
score = []
count = 0
for data in loader():
res = exe.run(inference_program,
feed=data,
fetch_list=fetch_targets)
res = exe.run(inference_program, feed=data, fetch_list=fetch_targets)
loss_sum += res[0]
label_data = list(np.array(data[0]["label"]))
for i in range(len(label_data)):
......
......@@ -14,6 +14,7 @@
import paddle.fluid as fluid
def din_attention(hist, target_expand, mask):
"""activation weight"""
......@@ -61,14 +62,10 @@ def network(item_count, cat_count):
name="hist_item_seq", shape=[None, seq_len], dtype="int64")
hist_cat_seq = fluid.data(
name="hist_cat_seq", shape=[None, seq_len], dtype="int64")
target_item = fluid.data(
name="target_item", shape=[None], dtype="int64")
target_cat = fluid.data(
name="target_cat", shape=[None], dtype="int64")
label = fluid.data(
name="label", shape=[None, 1], dtype="float32")
mask = fluid.data(
name="mask", shape=[None, seq_len, 1], dtype="float32")
target_item = fluid.data(name="target_item", shape=[None], dtype="int64")
target_cat = fluid.data(name="target_cat", shape=[None], dtype="int64")
label = fluid.data(name="label", shape=[None, 1], dtype="float32")
mask = fluid.data(name="mask", shape=[None, seq_len, 1], dtype="float32")
target_item_seq = fluid.data(
name="target_item_seq", shape=[None, seq_len], dtype="int64")
target_cat_seq = fluid.data(
......
......@@ -18,6 +18,7 @@ import numpy as np
import paddle
import pickle
def pad_batch_data(input, max_len):
res = np.array([x + [0] * (max_len - len(x)) for x in input])
res = res.astype("int64").reshape([-1, max_len])
......@@ -33,11 +34,9 @@ def make_data(b):
[[0] * x + [-1e9] * (max_len - x) for x in len_array]).reshape(
[-1, max_len, 1])
target_item_seq = np.array(
[[x[2]] * max_len for x in b]).astype("int64").reshape(
[-1, max_len])
[[x[2]] * max_len for x in b]).astype("int64").reshape([-1, max_len])
target_cat_seq = np.array(
[[x[3]] * max_len for x in b]).astype("int64").reshape(
[-1, max_len])
[[x[3]] * max_len for x in b]).astype("int64").reshape([-1, max_len])
res = []
for i in range(len(b)):
res.append([
......
......@@ -33,11 +33,20 @@ logger.setLevel(logging.INFO)
def parse_args():
parser = argparse.ArgumentParser("din")
parser.add_argument(
'--config_path', type=str, default='data/config.txt', help='dir of config')
'--config_path',
type=str,
default='data/config.txt',
help='dir of config')
parser.add_argument(
'--train_dir', type=str, default='data/paddle_train.txt', help='dir of train file')
'--train_dir',
type=str,
default='data/paddle_train.txt',
help='dir of train file')
parser.add_argument(
'--model_dir', type=str, default='din_amazon', help='dir of saved model')
'--model_dir',
type=str,
default='din_amazon',
help='dir of saved model')
parser.add_argument(
'--batch_size', type=int, default=16, help='number of batch size')
parser.add_argument(
......@@ -45,15 +54,19 @@ def parse_args():
parser.add_argument(
'--use_cuda', type=int, default=0, help='whether to use gpu')
parser.add_argument(
'--parallel', type=int, default=0, help='whether to use parallel executor')
'--parallel',
type=int,
default=0,
help='whether to use parallel executor')
parser.add_argument(
'--base_lr', type=float, default=0.85, help='based learning rate')
parser.add_argument(
'--num_devices', type=int, default=1, help='Number of GPU devices')
parser.add_argument(
'--enable_ce', action='store_true', help='If set, run the task with continuous evaluation logs.')
parser.add_argument(
'--batch_num', type=int, help="batch num for ce")
'--enable_ce',
action='store_true',
help='If set, run the task with continuous evaluation logs.')
parser.add_argument('--batch_num', type=int, help="batch num for ce")
args = parser.parse_args()
return args
......@@ -133,8 +146,8 @@ def train():
if (global_step > 400000 and global_step % PRINT_STEP == 0) or (
global_step <= 400000 and global_step % 50000 == 0):
save_dir = os.path.join(args.model_dir, "global_step_" + str(
global_step))
save_dir = os.path.join(args.model_dir,
"global_step_" + str(global_step))
feed_var_name = [
"hist_item_seq", "hist_cat_seq", "target_item",
"target_cat", "label", "mask", "target_item_seq",
......@@ -156,10 +169,8 @@ def train():
ce_time = total_time[-1]
except:
print("ce info error")
print("kpis\teach_pass_duration_card%s\t%s" %
(gpu_num, ce_time))
print("kpis\ttrain_loss_card%s\t%s" %
(gpu_num, ce_loss))
print("kpis\teach_pass_duration_card%s\t%s" % (gpu_num, ce_time))
print("kpis\ttrain_loss_card%s\t%s" % (gpu_num, ce_loss))
def get_cards(args):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册