Make single array for features, to reduce GPU copies

This commit is contained in:
Matthew Honnibal 2017-05-22 04:47:47 -05:00
parent bc2294d7f1
commit c998776c25

View File

@ -136,7 +136,8 @@ def Tok2Vec(width, embed_size, preprocess=None):
tok2vec = (
with_flatten(
(lower | prefix | suffix | shape )
asarray(Model.ops, dtype='uint64')
>> (lower | prefix | suffix | shape )
>> Maxout(width, width*4, pieces=3)
>> Residual(ExtractWindow(nW=1) >> Maxout(width, width*3))
>> Residual(ExtractWindow(nW=1) >> Maxout(width, width*3))
@ -151,6 +152,12 @@ def Tok2Vec(width, embed_size, preprocess=None):
return tok2vec
def asarray(ops, dtype):
def forward(X, drop=0.):
return ops.asarray(X, dtype=dtype), None
return layerize(forward)
def foreach(layer):
def forward(Xs, drop=0.):
results = []
@ -234,9 +241,7 @@ def doc2feats(cols=None):
def forward(docs, drop=0.):
feats = []
for doc in docs:
feats.append(
model.ops.asarray(doc.to_array(cols),
dtype='uint64'))
feats.append(doc.to_array(cols))
return feats, None
model = layerize(forward)
model.cols = cols