Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

v2版本使用factorization_machine出错

Open zyz282994112 opened this issue 8 years ago • 2 comments

数据输入为sparse_binary_vector时,代码可以正常运行,将多个sparse_binary_vector concat后,运行时会出“F1122 11:02:32.585233 6142 BaseMatrix.cu:91] Check failed: !b.isSparse() Sparse Matrix/Vector is not supported.F1122 11:02:32.591529 6143 BaseMatrix.cu:91] Check failed: !b.isSparse() Sparse Matrix/Vector is not supported.F1122 11:02:32.596053 6144 BaseMatrix.cu:91] Check failed: !b.isSparse() Sparse Matrix/Vector is not supported.”错误。出错代码片段如下:

def fm_layer(self, input_data, factor_size, fm_param_attr):
    first_order = paddle.layer.fc(input=input_data,
                                  size=1,
                                  act=paddle.activation.Linear())
    second_order = paddle.layer.factorization_machine(
        input=input_data,
        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 network(self, is_predict=False):
    word_dict_size = self._word_dict_size
    vocab_dict_size = self._vocab_dict_size
    hidden_size = self._hidden_size
    ########################
    reset_parser()
    month = paddle.layer.data(name="month", type=paddle.data_type.sparse_binary_vector(12))
    year = paddle.layer.data(name="year", type=paddle.data_type.sparse_binary_vector(2))
    vocab = paddle.layer.data(name="vocab", type=paddle.data_type.sparse_binary_vector(vocab_dict_size))
    comb_layer = paddle.layer.concat(input=[vocab, month, year])
    vocab_layer = self.fm_layer(comb_layer, 16, fm_param_attr=paddle.attr.Param(name="VocabFactors"))

    feature_concat_layer = paddle.layer.concat(input=[lstm_max_query, lstm_max_query_time, time_layer, vocab_layer])
    feature_concat_layer = paddle.layer.batch_norm(input=feature_concat_layer, act=paddle.activation.Relu())  
    weight = paddle.layer.data(name="weight", type=paddle.data_type.dense_vector(1))
    label = paddle.layer.data(name="label", type=paddle.data_type.integer_value(2))
    cost = paddle.layer.classification_cost(input=output, label=label, weight=weight)
    return cost

zyz282994112 avatar Nov 22 '18 03:11 zyz282994112

https://github.com/PaddlePaddle/Paddle/blob/e26f51ce74e998c4119fc2c3145aa7c1224c2170/doc/v2/faq/local/index_cn.rst#加速训练速度

请参考这里,把fc的参数更新方式设成sparse_update=True试试

kuke avatar Nov 22 '18 08:11 kuke

您好,此issue在近一个月内暂无更新,我们将于今天内关闭。若在关闭后您仍需跟进提问,可重新开启此问题,我们将在24小时内回复您。因关闭带来的不便我们深表歉意,请您谅解~感谢您对PaddlePaddle的支持

lucywsq avatar Dec 20 '18 14:12 lucywsq