It can't use GPU in DeepFM with paddlepaddle?
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 ?
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 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
@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
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.
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
}
改成dense_vector不行,直接闪退。