Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGSEGV (@0x7f4bcf2d1cb0) received by PID 31502 (TID 0x7f460dd5b700) from PID 18446744072890424496; stack trace #31390

Closed
lixinsu opened this issue Mar 3, 2021 · 3 comments
Assignees

Comments

@lixinsu
Copy link

lixinsu commented Mar 3, 2021

  • 版本、环境信息:
       1)PaddlePaddle版本:1.7.1
       3)GPU:P40
       4)系统环境:Linux yq01-inf-nmg01-hlan1.yq01.baidu.com 3.10.0_3-0-0-7 Support numpy dense #207 SMP Wed Jul 26 13:22:55 CST 2017 x86_64 x86_64 x86_64 GNU/Linux

  • 训练信息
       1)单机单卡
       2)显存信息
       3)Operator信息

  • 复现信息:如为报错,请给出复现环境、复现步骤

  • 问题描述:请详细描述您的问题,同步贴出报错信息、日志、可复现的代码片段
    `#########################################################

Embedding + MatchMatrix + CNN

############################ScoreModel#############################
import paddle as paddle
import paddle.fluid as fluid
import paddle.fluid.layers as layers

def EmbeddingLayer(input_ids, conf, name="Embedding"):
num_voc = conf['num_voc']
num_emb = conf['num_emb']
emb = layers.embedding(input=input_ids,
size=[num_voc, num_emb],
param_attr = fluid.ParamAttr(name=name, learning_rate=0.5),
padding_idx = 0)
return emb

def ConvPoolLayer(input_matrix, config, name='ConvPoolLayer'):
"""Convolution Layer."""
num_filters = config['num_filters']
filter_size = config['filter_size']

conv_res = layers.conv2d(input       = input_matrix,
                         num_filters = num_filters,
                         filter_size = filter_size,
                         padding     = "SAME",
                         param_attr  = fluid.ParamAttr(name = name + '.w'),
                         bias_attr   = fluid.ParamAttr(name = name + '.b'),
                         name        = name)
return conv_res

def Matrix_ExactMatch(x_ids, y_ids):
"""Matrix based on exact match."""
x_ids_expand = layers.expand(x_ids, [1, 1, y_ids.shape[1]])
y_ids_expand = layers.expand(y_ids, [1, 1, x_ids.shape[1]])
match_matrix = layers.equal(x_ids_expand, layers.transpose(y_ids_expand, [0, 2, 1]))
match_matrix = layers.cast(match_matrix, 'float32')
return match_matrix

def Matrix_EmbDot(x_emb, y_emb):
"""Matrix based on embeddings"""
match_matrix = layers.matmul(x_emb, y_emb, transpose_y = True)
return match_matrix

def Matrix_LSTM(x_emb, y_emb, x_mask, y_mask, config):
"""Matrix based on LSTM representations."""
RnnCell = fluid.layers.LSTMCell(hidden_size = config['LSTM_n_hidden'],
param_attr = fluid.ParamAttr(name = 'RnnCell.w'),
bias_attr = fluid.ParamAttr(name = 'RnnCell.b'),
name = "RnnCell")

RnnCell_back = fluid.layers.LSTMCell(hidden_size=config['LSTM_n_hidden'], 
                                     param_attr=fluid.ParamAttr(name = 'RnnCell.back.w'),
                                     bias_attr=fluid.ParamAttr(name = 'RnnCell.back.b'),
                                     name="RnnCell_back")
x_sequence_length = layers.cast(layers.reduce_sum(x_mask, dim = 1), 'int64')
x_rnn_emb, _ = fluid.layers.rnn(cell=RnnCell, 
                                inputs=x_emb,
                                sequence_length=x_sequence_length)
x_rnn_emb_back, _ = fluid.layers.rnn(cell=RnnCell_back, 
                                     inputs=x_emb,
                                     is_reverse=False,
                                     sequence_length=x_sequence_length)

y_sequence_length = layers.cast(layers.reduce_sum(y_mask, dim=1), 'int64')
y_rnn_emb, _ = fluid.layers.rnn(cell=RnnCell, 
                                inputs=y_emb,
                                sequence_length=y_sequence_length)
y_rnn_emb_back, _ = fluid.layers.rnn(cell=RnnCell, 
                                     inputs=y_emb,
                                     is_reverse=False,
                                     sequence_length=y_sequence_length)
x_rnn_emb = layers.concat([x_rnn_emb, x_rnn_emb_back], axis=-1)
y_rnn_emb = layers.concat([y_rnn_emb, y_rnn_emb_back], axis=-1)
match_matrix = layers.matmul(x_rnn_emb, y_rnn_emb, transpose_y=True)
return match_matrix

def CNN_Layer(match_matrix, x_mask, y_mask, config):
"""CNN & topk & LSTM."""
x_mask = layers.unsqueeze(x_mask, axes = [1, 3])
y_mask = layers.unsqueeze(y_mask, axes = [1, 2])
conv_pool_1 = ConvPoolLayer(input_matrix = match_matrix,
config = config['ConvPoolConfig'],
name = 'conv_pool')

conv_res = layers.relu(conv_pool_1)
conv_res = layers.elementwise_mul(conv_res, y_mask)
conv_res = layers.elementwise_mul(conv_res, x_mask)
conv_res, _ = layers.topk(conv_res, config['topk'])
RnnCell_topk = fluid.layers.LSTMCell(hidden_size = config['LSTM_n_hidden_topk'], 
                                param_attr  = fluid.ParamAttr(name = 'RnnCell.topk.w'),
                                bias_attr   = fluid.ParamAttr(name = 'RnnCell.topk.b'),
                                name        = "RnnCell_topk")

RnnCell_back_topk = fluid.layers.LSTMCell(hidden_size=config['LSTM_n_hidden_topk'], 
                                     param_attr=fluid.ParamAttr(name = 'RnnCell.back.topk.w'),
                                     bias_attr=fluid.ParamAttr(name = 'RnnCell.back.topk.b'),
                                     name="RnnCell_back_topk")
sequence_length = layers.cast(layers.reduce_sum(x_mask, dim = 1), 'int64')

C = config['ConvPoolConfig']['num_filters']
K = config['topk']
x_mask = layers.squeeze(x_mask, axes = [3])
x_mask = layers.expand(x_mask, [1, C, 1])
x_mask = layers.reshape(x_mask, [-1, x_mask.shape[-1]])
expand_sequence_length = layers.reduce_sum(x_mask, dim = 1)
conv_res = layers.reshape(conv_res, [-1, conv_res.shape[-2], K])
topk_rnn, (_, topk_rnn_final) = fluid.layers.rnn(cell=RnnCell_topk, 
                                inputs=conv_res,
                                sequence_length=expand_sequence_length)
topk_rnn_back, (_, topk_rnn_back_final) = fluid.layers.rnn(cell=RnnCell_back_topk, 
                                     inputs=conv_res,
                                     is_reverse=False,
                                     sequence_length=expand_sequence_length)
topk_rnn = layers.concat([topk_rnn_final, topk_rnn_back_final], axis=1)
conv_res = layers.reshape(topk_rnn, [-1, C * 2 * config['LSTM_n_hidden_topk']])
return conv_res

def Matrix_Layer(x_ids, y_ids, x_emb, y_emb, x_mask, y_mask, config):
"""Construct matching matrix."""
if "ExeactMatch" in config['match_matrix_type']:
matrix_ExeactMatch=Matrix_ExactMatch(x_ids, y_ids)

if "EmbDot" in config['match_matrix_type']:
    matrix_EmbDot = Matrix_EmbDot(x_emb, y_emb)

if "LSTM" in config['match_matrix_type']:
    matrix_LSTM = Matrix_LSTM(x_emb, y_emb, x_mask, y_mask, config)

if config['match_matrix_type'] == "ExeactMatch+EmbDot+LSTM":
    match_matrix = layers.stack(x    = [matrix_ExeactMatch, matrix_EmbDot, matrix_LSTM], 
                                axis = 1)
if config['match_matrix_type'] == "ExeactMatch+EmbDot":
    match_matrix = layers.stack(x    = [matrix_ExeactMatch, matrix_EmbDot], 
                                axis = 1)
if config['match_matrix_type'] == "ExeactMatch+LSTM":
    match_matrix = layers.stack(x    = [matrix_ExeactMatch, matrix_LSTM], 
                                axis = 1)
if config['match_matrix_type'] == "ExeactMatch":
    match_matrix = layers.stack(x    = [matrix_ExeactMatch], 
                                axis = 1)        
if config['match_matrix_type'] == "EmbDot":
    match_matrix = layers.stack(x    = [matrix_EmbDot], 
                                axis = 1)        
if config['match_matrix_type'] == "LSTM":
    match_matrix = layers.stack(x=[matrix_LSTM], 
                                axis=1)        
return match_matrix

##################################### RE2 ########################################################################

def CovEmbLayer(input_emb, config, name="CovEmbedding"):
input_emb = layers.unsqueeze(input_emb, axes = [1])
num_filters = config['num_filters']
filter_size = config['filter_size']

conv_res = layers.conv2d(input = input_emb,
                         num_filters = num_filters,
                         filter_size = filter_size,
                         padding     = "SAME",
                         stride      = (1, 256),
                         param_attr  = fluid.ParamAttr(name = name + '.w'),
                         bias_attr   = fluid.ParamAttr(name = name + '.b'),
                         name        = name)

conv_res = layers.squeeze(conv_res, axes = [3])
conv_res = layers.transpose(conv_res, perm = [0, 2, 1])
return conv_res

def Matrix_RE2(x_emb, y_emb, x_mask, y_mask):

matrix      = layers.matmul(x_emb,  y_emb,  transpose_y = True)    

matrix_mask = layers.matmul(layers.unsqueeze(x_mask, axes = [2]), 
                            layers.unsqueeze(y_mask, axes = [1]))

matrix = matrix_mask * matrix + (1 - matrix_mask) * float(-999999)

attention_x = layers.softmax(matrix, axis = 1)
attention_y = layers.softmax(matrix, axis = 2)

feature_x = layers.matmul(attention_y, y_emb)
feature_y = layers.matmul(attention_x, x_emb, transpose_x = True)

return feature_x, feature_y

def Fusion_Layer(x_emb, y_emb, x_feature, y_feature, config):

def fusion(emb, feature, config):
    repr_1 = layers.concat([emb, feature], axis=-1)
    repr_1 = layers.fc(input=repr_1, 
                         size=64, 
                         act='relu', 
                         num_flatten_dims=2,
                         param_attr=fluid.ParamAttr(name = 'fusion_ori.w'),
                         bias_attr=fluid.ParamAttr(name='fusion_ori.b')) 

    repr_2 = layers.concat([emb, emb - feature], axis=-1)
    repr_2 = layers.fc(input = repr_2, 
                         size = 64, 
                         act = 'relu', 
                         num_flatten_dims = 2,
                         param_attr = fluid.ParamAttr(name='fusion_sub.w'),
                         bias_attr = fluid.ParamAttr(name='fusion_sub.b')) 

    repr_3 = layers.concat([emb, emb * feature], axis=-1)
    repr_3 = layers.fc(input = repr_3, 
                         size = 64, 
                         act = 'relu', 
                         num_flatten_dims = 2,
                         param_attr = fluid.ParamAttr( name = 'fusion_mul.w'),
                         bias_attr  = fluid.ParamAttr( name = 'fusion_mul.b') ) 


    reprs = layers.concat([repr_1, repr_2, repr_3], axis=-1)
    reprs = layers.fc(input = reprs, 
                       size = 64, 
                       act = 'relu', 
                       num_flatten_dims = 2,
                       param_attr = fluid.ParamAttr(name = 'fusion_repr.w'),
                       bias_attr = fluid.ParamAttr(name = 'fusion_repr.b') ) 
    return reprs

x_repr = fusion(x_emb, x_feature, config)
y_repr = fusion(y_emb, y_feature, config)

return x_repr, y_repr

def Predict_Layer(x_repr, y_repr, config):
reprs = layers.concat([x_repr, y_repr, x_repr * y_repr, y_repr - x_repr],
axis = -1)
reprs = layers.fc(input = reprs,
size = 64,
act = 'relu',
param_attr = fluid.ParamAttr(name = 'predict_fc1.w'),
bias_attr = fluid.ParamAttr(name = 'predict_fc1.b'))

score = layers.fc(input = reprs, 
                  size = 1, 
                  act = 'relu', 
                  param_attr = fluid.ParamAttr(name = 'predict_fc2.w'),
                  bias_attr = fluid.ParamAttr(name = 'predict_fc2.b')) 

return score

#########################################################################################################################

class ScoreModel(object):
"""Calc score for query title and content."""
def init(self, query_input_ids, title_input_ids, content_input_ids, config, is_training=True):
self._build_model(query_input_ids, title_input_ids, content_input_ids, config, is_training=is_training)

def _build_model(self, query_input_ids, title_input_ids, content_input_ids, config, is_training=True):
    
    query_emb = EmbeddingLayer(query_input_ids, config['EmbeddingConfig'])
    title_emb = EmbeddingLayer(title_input_ids, config['EmbeddingConfig'])
    content_emb = EmbeddingLayer(content_input_ids, config['EmbeddingConfig'])
    DROPRATE = 0.3
    SEED = 2333
    if is_training:
        query_emb = layers.dropout(query_emb, DROPRATE, is_test=(not is_training), seed=SEED)
        title_emb = layers.dropout(title_emb, DROPRATE, is_test=(not is_training), seed=SEED)
        content_emb = layers.dropout(content_emb, DROPRATE, is_test=(not is_training), seed=SEED)
    
    query_mask = layers.reshape(layers.cast(query_input_ids > 0, 'float32'), [-1, 128])
    title_mask = layers.reshape(layers.cast(title_input_ids > 0, 'float32'), [-1, 128])
    content_mask = layers.reshape(layers.cast(content_input_ids > 0, 'float32'), [-1, 128])
    
    if  config['model_type'] == "SimpleRE2":
        query_cnn_emb = CovEmbLayer(query_emb, config['ConvEmbConfig'], name="CovEmbedding")
        content_cnn_emb = CovEmbLayer(content_emb, config['ConvEmbConfig'], name="CovEmbedding")
        
        query_feature, content_feature = Matrix_RE2(layers.concat([query_emb, query_cnn_emb], axis=-1), 
                                                    layers.concat([content_emb, content_cnn_emb], axis=-1), 
                                                    query_mask, 
                                                    content_mask)
        
        query_repr, content_repr = Fusion_Layer(layers.concat([query_emb, query_cnn_emb], axis=-1),
                                                layers.concat([content_emb, content_cnn_emb], axis=-1),
                                                query_feature, 
                                                content_feature, 
                                                config)
        query_repr = layers.reduce_max(query_repr * query_mask, dim=1)
        content_repr = layers.reduce_max(content_repr * content_mask, dim=1)
        self.score = Predict_Layer(query_repr, content_repr, config)
        
    if  config['model_type'] == "MatchMatrix+CNN":
        if 'qt' in config['interaction_type']:
            query_title_matrix = Matrix_Layer(query_input_ids, title_input_ids, 
                                                    query_emb, title_emb,
                                                    query_mask, title_mask,
                                                    config)
            if config['repr_type'] == 'cnn':
                query_title_conv_res   = CNN_Layer(query_title_matrix, query_mask, title_mask, config)


        if 'qc' in config['interaction_type']:
            query_content_matrix = Matrix_Layer(query_input_ids, content_input_ids, 
                                                      query_emb, content_emb,
                                                      query_mask, content_mask,
                                                      config)
            if config['repr_type'] == 'cnn':
                query_content_conv_res = CNN_Layer(query_content_matrix, query_mask, content_mask, config)

        if 'tc' in config['interaction_type']:
            title_content_matrix = Matrix_Layer(title_input_ids, content_input_ids, 
                                                      title_emb, content_emb,
                                                      title_mask, content_mask,
                                                      config)
            if config['repr_type'] == 'cnn':
                title_content_conv_res = CNN_Layer(title_content_matrix, title_mask, content_mask, config)

        if config['interaction_type'] == 'qt+qc+tc':
            interaction_res = layers.concat([query_title_conv_res, query_content_conv_res, title_content_conv_res], axis=1)

        if config['interaction_type'] == 'qt+qc':
            interaction_res = layers.concat([query_title_conv_res, query_content_conv_res], axis=1)

        if config['interaction_type'] == 'qt':
            interaction_res = query_title_conv_res

        if config['interaction_type'] == 'qc':
            interaction_res = query_content_conv_res


        if config['infer_type'] == 'mlp-64-1':
            fc_1 = layers.fc(input = interaction_res, 
                             size = 64, 
                             act = 'relu', 
                             param_attr = fluid.ParamAttr( name = 'fc_1.w'),
                             bias_attr  = fluid.ParamAttr( name = 'fc_1.b') ) 
            fc_2 = layers.fc(input = fc_1, 
                             size = 1, 
                             param_attr = fluid.ParamAttr( name = 'fc_2.w'),
                             bias_attr  = fluid.ParamAttr( name = 'fc_2.b') )  
            self.score = fc_2
            
   
  
def get_output(self):
    return self.score

class LossModel(object):

def __init__(self, pos_score, neg_score, config):
    self._build_model(pos_score, neg_score, config)
   
def _build_model(self, pos_score, neg_score, config):
    # LOSS origin
    # prob_pair = layers.sigmoid(pos_score - neg_score, name='prob_pair')
    # self.loss = layers.mean(-layers.log(prob_pair))
    # self.acc = layers.mean(layers.cast(prob_pair > 0.5, 'float32'))

    # LOSS hinge
    # dynamic_margin = layers.cast(layers.elementwise_sub(pos_labels, neg_labels), "float32")
    # margins = layers.unsqueeze(layers.fill_constant(shape=[1], value=1, dtype='float32'), axes=[-1])
    # ce_loss = layers.elementwise_add(margins, layers.elementwise_sub(neg_score, pos_score))
    # ce_loss = layers.elementwise_max(
    #     ce_loss,
    # layers.fill_constant_batch_size_like(neg_score, shape=neg_score.shape,
    #                                             dtype="float32", value=0.0))
    # self.loss = layers.mean(ce_loss)
    # pos_num = layers.cast(pos_score > neg_score, 'float32')
    # self.acc = layers.mean(pos_num)
    

    # LOSS from fengge
    logits = layers.concat([pos_score, neg_score], axis=-1)
    labels = layers.cast(layers.zeros_like(pos_score), dtype='int64')
    loss, prob = layers.softmax_with_cross_entropy(logits=logits, label=labels, return_softmax=True)
    pos_prob = layers.unsqueeze(prob[:, 0], 1)
    focal_loss = layers.elementwise_mul(layers.pow(1 - pos_prob, 2), loss)
    self.loss = layers.mean(focal_loss)
    # self.loss = layers.mean(loss)
    pos_num = layers.cast(pos_score > neg_score, 'float32')
    self.acc = layers.mean(pos_num)


def get_output(self):
    """Output."""
    return self.loss, self.acc

`

image

@paddle-bot-old
Copy link

paddle-bot-old bot commented Mar 3, 2021

您好,我们已经收到了您的问题,会安排技术人员尽快解答您的问题,请耐心等待。请您再次检查是否提供了清晰的问题描述、复现代码、环境&版本、报错信息等。同时,您也可以通过查看官网API文档常见问题历史IssueAI社区来寻求解答。祝您生活愉快~

Hi! We've received your issue and please be patient to get responded. We will arrange technicians to answer your questions as soon as possible. Please make sure that you have posted enough message to demo your request. You may also check out the APIFAQGithub Issue and AI community to get the answer.Have a nice day!

@GaoWei8
Copy link
Contributor

GaoWei8 commented Mar 3, 2021

是使用了ernie的repo的代码吗

@paddle-bot-old
Copy link

Since you haven't replied for more than a year, we have closed this issue/pr.
If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up.
由于您超过一年未回复,我们将关闭这个issue/pr。
若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants