Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

It can't use GPU in DeepFM with paddlepaddle?

Open burness opened this issue 8 years ago • 6 comments

Hi, paddler:

When I test your demo in deep_fm demo, When I change the use_gpu=True, It will break down with something not support. It seems that the fm is designed for sparse matrix which the gpu is not supported now? If yes, can I put the deep layers such fc1, fc2 fc3 to gpu and the fm to cpu ?

burness avatar Dec 25 '17 13:12 burness

Hi burness,

When the input is sparse, the fm layer can only run in CPU. When the input is dense vector, the fm layer can run on both GPU and CPU.

Currently, paddle does not support that part of the network runs on CPU and the other part runs on GPU.

will-am avatar Dec 25 '17 14:12 will-am

@will-am How I can set the input to be dense, my data dim is not very high, maybe I can replace the representation with dense matrix

burness avatar Dec 25 '17 14:12 burness

@will-am It seems

        sparse_input = paddle.layer.data(
        name="sparse_input",
        type=paddle.data_type.sparse_binary_vector(sparse_feature_dim))

Could I use the dense matrix to represent the sparse one-hot ? If not it seem that we can't use gpu in deep_fm

burness avatar Dec 25 '17 14:12 burness

Yes, you can change the

sparse_input = paddle.layer.data(
        name="sparse_input",
        type=paddle.data_type.sparse_binary_vector(sparse_feature_dim))

to

sparse_input = paddle.layer.data(
        name="sparse_input",
        type=paddle.data_type.dense_vector(sparse_feature_dim))

and adjust the yield value in reader.py, then this demo would run in GPU.

will-am avatar Dec 25 '17 14:12 will-am

You can change the reader.py as following to change the yield value to be dense:

import numpy as np

class Dataset:
    def _reader_creator(self, path, is_infer):
        def reader():
            with open(path, 'r') as f:
                for line in f:
                    features = line.rstrip('\n').split('\t')
                    dense_feature = map(float, features[0].split(','))
                    sparse_feature = map(int, features[1].split(','))
                    sparse_to_dense = np.zeros(117568)
                    sparse_to_dense[sparse_feature] = 1
                    if not is_infer:
                        label = [float(features[2])]
                        yield [dense_feature, sparse_to_dense
                               ] + sparse_feature + [label]
                    else:
                        yield [dense_feature, sparse_to_dense] + sparse_feature

        return reader

    def train(self, path):
        return self._reader_creator(path, False)

    def test(self, path):
        return self._reader_creator(path, False)

    def infer(self, path):
        return self._reader_creator(path, True)


feeding = {
    'dense_input': 0,
    'sparse_input': 1,
    'C1': 2,
    'C2': 3,
    'C3': 4,
    'C4': 5,
    'C5': 6,
    'C6': 7,
    'C7': 8,
    'C8': 9,
    'C9': 10,
    'C10': 11,
    'C11': 12,
    'C12': 13,
    'C13': 14,
    'C14': 15,
    'C15': 16,
    'C16': 17,
    'C17': 18,
    'C18': 19,
    'C19': 20,
    'C20': 21,
    'C21': 22,
    'C22': 23,
    'C23': 24,
    'C24': 25,
    'C25': 26,
    'C26': 27,
    'label': 28
}

will-am avatar Dec 25 '17 14:12 will-am

改成dense_vector不行,直接闪退。

xiaolv3366 avatar Jun 22 '18 09:06 xiaolv3366