Segmentation fault (core dumped) in deepfm
运行过程出现这个错误
PC: @ 0x0 (unknown)
*** SIGSEGV (@0x7fec4140800c) received by PID 24967 (TID 0x7fec150b1700) from PID 1094746124; stack trace: ***
@ 0x318b20f500 (unknown)
@ 0x7fec581065e0 sgemm_itcopy_SANDYBRIDGE
@ 0x7fec56cc1fb3 inner_thread
@ 0x7fec56ccb52f blas_thread_server
@ 0x318b207851 (unknown)
@ 0x318aee767d (unknown)
@ 0x0 (unknown)
查看之前issue,有说是输入数据格式错误。我试着把输入数据拆成几个部分单独去跑,都没问题,甚至出错时候输入的那条单独跑也没问题。
请问下,有什么可能的原因吗?
能详细描述一下背景吗,任务类型,网络配置的情况
@QiJune 我改造了下deepfm这个示例,网络结构如下,主要的变动是把integer_value,改成了integer_value_sequence
import paddle.v2 as paddle
from paddle.v2.layer import parse_network
def fm_layer(input, factor_size, fm_param_attr):
first_order = paddle.layer.fc(
input=input, size=1, act=paddle.activation.Linear())
second_order = paddle.layer.factorization_machine(
input=input,
factor_size=factor_size,
act=paddle.activation.Linear(),
param_attr=fm_param_attr)
out = paddle.layer.addto(
input=[first_order, second_order],
act=paddle.activation.Linear(),
bias_attr=False)
return out
def DeepFM(factor_size, sparse_feature_dim, infer=False):
sparse_input = paddle.layer.data(
name="sparse_input",
type=paddle.data_type.sparse_binary_vector(sparse_feature_dim))
sparse_input_ids = [
paddle.layer.data(
name="C" + str(i),
type=paddle.data_type.integer_value_sequence(sparse_feature_dim))
for i in range(2, 60)
]
sparse_fm = fm_layer(
sparse_input,
factor_size,
fm_param_attr=paddle.attr.Param(name="SparseFeatFactors"))
def embedding_layer(input):
emb = paddle.layer.embedding(input=input, size=factor_size, param_attr=paddle.attr.Param(name="SparseFeatFactors"))
avg_emb = paddle.layer.pooling(input=emb, pooling_type=paddle.pooling.Avg())
return avg_emb
sparse_embed_seq = map(embedding_layer, sparse_input_ids)
sparse_embed = paddle.layer.concat(sparse_embed_seq)
fc1 = paddle.layer.fc(input=sparse_embed, size=512, act=paddle.activation.Relu())
fc2 = paddle.layer.fc(input=fc1, size=256, act=paddle.activation.Relu())
predict = paddle.layer.fc(
input=[sparse_fm, fc2],
size=1,
act=paddle.activation.Sigmoid())
if not infer:
label = paddle.layer.data(
name="label", type=paddle.data_type.dense_vector(1))
cost = paddle.layer.multi_binary_label_cross_entropy_cost(
input=predict, label=label)
paddle.evaluator.classification_error(
name="classification_error", input=predict, label=label)
paddle.evaluator.auc(name="auc", input=predict, label=label)
return cost
else:
return predict
if __name__ == "__main__":
print(parse_network(DeepFM(15,1300000)))
是运行一段时间后报错,还是立马报错呢
是运行一段时间,过程中我把reader到的数据都打印出来了,打了几十条后就报错了
我是指训练有没有开始?这里reader的数据可能是在准备第一个batch的训练数据,而第一个batch的训练还没有开始。 如果是第一个batch的训练就报错,那么应该是这些数据的格式与网络配置中定义的输入格式不一致。
@QiJune 看起来应该是第一个batch开始了,有生成最终模型文件 现在问题比较奇怪,我调小batchsize到20,是能跑过的,但是batchsize到100的时候很大概率会出错。 有时候是第一轮pass跑完没有出错,开始跑第二个pass的时候出错
有时候跑还会出现这个问题
*** Aborted at 1514440805 (unix time) try "date -d @1514440805" if you are using GNU date ***
PC: @ 0x0 (unknown)
*** SIGFPE (@0x7f824139d793) received by PID 22665 (TID 0x7f81faf7b700) from PID 1094309779; stack trace: ***
@ 0x318b20f500 (unknown)
@ 0x7f824139d793 paddle::AssignCpuEvaluate<>()
@ 0x7f824139e99c paddle::AssignEvaluate<>()
@ 0x7f824139964b paddle::adamApply()
@ 0x7f8241396c76 paddle::AdamParameterOptimizer::update()
@ 0x7f824138118f paddle::SgdThreadUpdater::threadUpdateDense()
@ 0x7f824138233f _ZNSt17_Function_handlerIFvimEZN6paddle16SgdThreadUpdater11finishBatchEfEUlimE_E9_M_invokeERKSt9_Any_dataim
@ 0x7f823fbf827c _ZNSt6thread5_ImplISt12_Bind_simpleIFZN6paddle14SyncThreadPool5startEvEUliE_mEEE6_M_runEv
@ 0x318eab6470 (unknown)
@ 0x318b207851 (unknown)
@ 0x318aee767d (unknown)
@ 0x0 (unknown)
Floating point exception (core dumped)
请给几条输入数据的样例吧,你的配置中修改成integer_value_sequence格式,输入数据能否对得上?
@QiJune 输入数据样例: [[191258, 2947, 143, 66, 191239, 2556, 119, 184397, 184425, 55, 554, 598, 420, 174, 820, 6083, 187822, 18528, 194, 20503, 8912, 726, 53796, 33789, 12461, 74, 191, 222, 63, 72, 6059, 187836, 7003, 68, 73, 62, 65, 408, 410, 104, 247, 99, 230, 213, 225, 20999, 13458, 6550, 70002, 305304, 7352, 559, 32492, 23530, 124, 138, 84, 21000, 13459, 6551, 70019, 13145, 84546, 35745, 12825, 1017, 32450, 26087, 9551], [0.0], [191258], [2947], [143], [66], [191239], [11], [2556], [178], [119], [184397], [184425], [55], [554], [598], [420], [174], [820], [6083, 187822, 18528], [194], [6], [0], [20503, 8912, 726, 53796, 33789, 12461], [74, 191, 222], [63], [347], [72], [57], [14], [6059, 187836, 7003], [68], [73], [62], [65], [408], [410], [104], [247], [99], [230], [213], [225], [4], [20999, 13458, 6550, 70002], [305304], [7352], [559], [32492, 23530], [124], [138], [84], [5], [21000, 13459, 6551, 70019], [13145], [84546], [16], [15], [35745, 12825, 1017], [32450, 26087, 9551]]
feeding = {
'sparse_input': 0,
'label': 1,
'C2': 2,
'C3': 3,
'C4': 4,
'C5': 5,
'C6': 6,
'C7': 7,
'C8': 8,
'C9': 9,
'C10': 10,
'C11': 11,
'C12': 12,
'C13': 13,
'C14': 14,
'C15': 15,
'C16': 16,
'C17': 17,
'C18': 18,
'C19': 19,
'C20': 20,
'C21': 21,
'C22': 22,
'C23': 23,
'C24': 24,
'C25': 25,
'C26': 26,
'C27': 27,
'C28': 28,
'C29': 29,
'C30': 30,
'C31': 31,
'C32': 32,
'C33': 33,
'C34': 34,
'C35': 35,
'C36': 36,
'C37': 37,
'C38': 38,
'C39': 39,
'C40': 40,
'C41': 41,
'C42': 42,
'C43': 43,
'C44': 44,
'C45': 45,
'C46': 46,
'C47': 47,
'C48': 48,
'C49': 49,
'C50': 50,
'C51': 51,
'C52': 52,
'C53': 53,
'C54': 54,
'C55': 55,
'C56': 56,
'C57': 57,
'C58': 58,
'C59': 59
}
我看这里的feeding数据,是说总共有60个数据源吗?你网络配置里面的feeding_dict是否能对得上?能把完整的训练脚本贴一下吗
@QiJune 我的训练代码
import os
import gzip
import logging
import argparse
import cPickle
import paddle.v2 as paddle
from network_conf import DeepFM
import reader
logging.basicConfig()
logger = logging.getLogger("paddle")
logger.setLevel(logging.INFO)
def parse_args():
parser = argparse.ArgumentParser(description="PaddlePaddle DeepFM example")
parser.add_argument(
'--dict_path',
type=str,
required=True,
help="The path of dict")
parser.add_argument(
'--train_data_path',
type=str,
required=True,
help="The path of training dataset")
parser.add_argument(
'--test_data_path',
type=str,
required=True,
help="The path of testing dataset")
parser.add_argument(
'--batch_size',
type=int,
default=1000,
help="The size of mini-batch (default:1000)")
parser.add_argument(
'--num_passes',
type=int,
default=10,
help="The number of passes to train (default: 10)")
parser.add_argument(
'--factor_size',
type=int,
default=10,
help="The factor size for the factorization machine (default:10)")
parser.add_argument(
'--model_output_dir',
type=str,
default='models',
help='The path for model to store (default: models)')
return parser.parse_args()
def train():
args = parse_args()
if not os.path.isdir(args.model_output_dir):
os.mkdir(args.model_output_dir)
paddle.init(use_gpu=False, trainer_count=1)
dataset = reader.Dataset()
dict_path = args.dict_path
slot_feature_dict_path = dict_path + "/" + "slot_feature_dict.pkl"
with open(slot_feature_dict_path) as f:
slot_feature_dict = cPickle.load(f)
dicts = dict()
dicts['slot_feature_dict'] = slot_feature_dict
sparse_feature_dim = len(slot_feature_dict)
print sparse_feature_dim
optimizer = paddle.optimizer.Adam(learning_rate=1e-4)
model = DeepFM(args.factor_size, sparse_feature_dim)
params = paddle.parameters.create(model)
trainer = paddle.trainer.SGD(
cost=model, parameters=params, update_equation=optimizer)
print "after SGD"
def __event_handler__(event):
if isinstance(event, paddle.event.EndIteration):
num_samples = event.batch_id * args.batch_size
if event.batch_id % 100 == 0:
logger.warning("Pass %d, Batch %d, Samples %d, Cost %f, %s" %
(event.pass_id, event.batch_id, num_samples,
event.cost, event.metrics))
if event.batch_id % 100 == 0:
# if args.test_data_path:
# result = trainer.test(
# reader=paddle.batch(
# dataset.test(dicts, args.test_data_path),
# batch_size=args.batch_size),
# feeding=reader.feeding)
# logger.warning("Test %d-%d, Cost %f, %s" %
# (event.pass_id, event.batch_id, result.cost,
# result.metrics))
path = "{}/model-pass-{}-batch-{}.tar.gz".format(
args.model_output_dir, event.pass_id, event.batch_id)
with gzip.open(path, 'w') as f:
trainer.save_parameter_to_tar(f)
trainer.train(
reader=paddle.batch(
paddle.reader.shuffle(
dataset.train(dicts, args.train_data_path),
buf_size=1),
batch_size=args.batch_size),
feeding=reader.feeding,
event_handler=__event_handler__,
num_passes=args.num_passes)
if __name__ == '__main__':
train()
reader的代码
import sys
import cPickle
class Dataset:
def _reader_creator(self, dicts, path, is_infer):
def reader():
print "in reader"
slot_feature_dict = dicts['slot_feature_dict']
files = os.listdir(path)
for fi in files:
with open(path+ '/' + fi, "r") as f:
UNK = '<unk>'
print fi
for line in f:
line_split = line.rstrip('\n').split('\t')
if len(line_split) < 60:
continue
label = [float(line_split[1])]
sparse_feature = []
all_sparse_ids = []
for i in range(2, 60):
slot_val = []
slot_id = i-2
if line_split[i] == '':
key = str(slot_id)+":"+UNK
slot_val.append(slot_feature_dict.get(key))
all_sparse_ids.append(slot_val)
continue
mini_seg_array = line_split[i].split('-')
for mini_seg in mini_seg_array:
key = str(slot_id)+":"+mini_seg
key_unk = str(slot_id)+":"+UNK
slot_val.append(slot_feature_dict.get(key, slot_feature_dict.get(key_unk)))
if slot_feature_dict.has_key(key):
sparse_feature.append(slot_feature_dict.get(key))
all_sparse_ids.append(slot_val)
if not is_infer:
print "input"
print all_sparse_ids
print label
print [sparse_feature]
print "line"
print line
yield [sparse_feature] + [label] + all_sparse_ids
else:
yield [sparse_feature] + [label] + all_sparse_ids
return reader
def train(self, dicts, path):
return self._reader_creator(dicts, path, False)
def test(self, dicts, path):
return self._reader_creator(dicts, path, False)
def infer(self, dicts, path):
return self._reader_creator(dicts, path, True)
if __name__ == "__main__":
dict_path = sys.argv[1]
train_path = sys.argv[2]
slot_feature_dict_path = dict_path + "/" + "slot_feature_dict.pkl"
with open(slot_feature_dict_path) as f:
slot_feature_dict = cPickle.load(f)
dicts = dict()
dicts['slot_feature_dict'] = slot_feature_dict
dataset = Dataset()
for dat in dataset.train(dicts, train_path)():
print dat
feeding = {
'sparse_input': 0,
'label': 1,
'C2': 2,
'C3': 3,
'C4': 4,
'C5': 5,
'C6': 6,
'C7': 7,
'C8': 8,
'C9': 9,
'C10': 10,
'C11': 11,
'C12': 12,
'C13': 13,
'C14': 14,
'C15': 15,
'C16': 16,
'C17': 17,
'C18': 18,
'C19': 19,
'C20': 20,
'C21': 21,
'C22': 22,
'C23': 23,
'C24': 24,
'C25': 25,
'C26': 26,
'C27': 27,
'C28': 28,
'C29': 29,
'C30': 30,
'C31': 31,
'C32': 32,
'C33': 33,
'C34': 34,
'C35': 35,
'C36': 36,
'C37': 37,
'C38': 38,
'C39': 39,
'C40': 40,
'C41': 41,
'C42': 42,
'C43': 43,
'C44': 44,
'C45': 45,
'C46': 46,
'C47': 47,
'C48': 48,
'C49': 49,
'C50': 50,
'C51': 51,
'C52': 52,
'C53': 53,
'C54': 54,
'C55': 55,
'C56': 56,
'C57': 57,
'C58': 58,
'C59': 59
}
输入数据格式(60个字段,第二个是标签,后面58个代表不同的slot,-号分割的代表是多值属性):
1 0 23262982 30 eeda8427 1022 150012305402050 文化历史>考古 2 铭记历史教训 2824796987 15 7 7 9 11 1011 67764372-67784055-67703478 1 67756996-67763217-67752932-67810753-67780977-68194121 1016-1033-1011 null 0 67764372-67784055-67752368 1 1 1 1 11 9 2 3 2 3 8 7 69064706-67756996-67763217-0 151321476207597 贴吧女仆长 1033 67756996-67763217 0 4 1 69064706-67756996-67763217-0 67764372 67756996 67756996-67763217-67752932 69064706-67756996-67763217
在这里
sparse_input_ids = [
paddle.layer.data(
name="C" + str(i),
type=paddle.data_type.integer_value_sequence(sparse_feature_dim))
for i in range(2, 60)
]
sparse_feature_dim是1300000,输入数据的字典满足这个要求吗? 可以把batch size设置为1,跑跑看,定位出错误的数据在哪里
@QiJune 我是实际把字典表大小传入网络的
print sparse_feature_dim
optimizer = paddle.optimizer.Adam(learning_rate=1e-4)
model = DeepFM(args.factor_size, sparse_feature_dim)
主要是我改成batch size为1,他能跑过,batch size改大了,就出现错误。而且也不是每次都出现错误,有很小几率即使是改大了,也能跑过。或者是第一个pass能过,第二个不能过
那这里报错是什么错误,浮点异常吗?还是段错误?
是段错误,浮点异常后面没出现过,当时用错了一个字典
段错误一般是内存访问越界 字典大小为1300000,请在python端传入数据的时候check这个事情,保证输入的id都小于字典大小
我确认了下,id都是小于字典大小的。这边我把deep部分不输入网络,只有fm部分的话,也是可以运行通过的。我先试试最初下载的样例deepfm还能不能跑起来。 改了以下代码,把fc2去掉,是可以跑过的
input=[sparse_fm],
size=1,
act=paddle.activation.Sigmoid())
调整deep部分的size试试呢
fc1 = paddle.layer.fc(input=sparse_embed, size=512, act=paddle.activation.Relu())
fc2 = paddle.layer.fc(input=fc1, size=256, act=paddle.activation.Relu())
我看models目录下面的两个size是一致的
都改成400,还是会出错呢,段错误
def embedding_layer(input):
emb = paddle.layer.embedding(input=input, size=factor_size, param_attr=paddle.attr.Param(name="SparseFeatFactors"))
avg_emb = paddle.layer.pooling(input=emb, pooling_type=paddle.pooling.Avg())
return avg_emb
sparse_embed_seq = map(embedding_layer, sparse_input_ids)
sparse_embed = paddle.layer.concat(sparse_embed_seq)
在这里,embedding之后的输出,不同slot得到的大小是不一样的。 比如说某个slot只有一个id,那么得到的就是一个向量;而另外一个slot有两个id,那么得到的就是一个2*dim的矩阵了。直接concat貌似会维度对应不上呢? 能否确认段错误是发生在哪个layer?
这边应该是没有问题的,有pooling操作,会归一化到定长的吧 实际这边我也改成过和demo一样的非sequence输入(一个slot下只取第一个id),但也会报错。 所以我先看看原来的demo现在能否运行成功