mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-24 17:06:29 +03:00
Fix parser @ GPU (#5210)
* ensure self.bias is numpy array in parser model * 2 more little bug fixes for parser on GPU * removing testing GPU statement * remove commented code
This commit is contained in:
parent
9b412516e7
commit
1f9852abc3
|
@ -79,7 +79,7 @@ def _backprop_precomputable_affine_padding(model, dY, ids):
|
|||
# for b in range(nB):
|
||||
# for f in range(nF):
|
||||
# if ids[b, f] < 0:
|
||||
# d_padding[0, f] += dY[b]
|
||||
# d_pad[0, f] += dY[b]
|
||||
#
|
||||
# Which can be rewritten as:
|
||||
#
|
||||
|
@ -88,9 +88,13 @@ def _backprop_precomputable_affine_padding(model, dY, ids):
|
|||
#
|
||||
# I don't know how to avoid the loop without building a whole array :(.
|
||||
# Cursed numpy.
|
||||
#
|
||||
# Note by Sofie: rewritten to longer loop because "CuPy only supports slices that consist of one boolean array."
|
||||
d_pad = model.ops.alloc((1, nF, nO, nP))
|
||||
for b in range(nB):
|
||||
d_pad[0, ids[b] < 0] += dY[b]
|
||||
for f in range(nF):
|
||||
if ids[b, f] < 0:
|
||||
d_pad[0, f] += dY[b]
|
||||
return d_pad
|
||||
|
||||
|
||||
|
|
|
@ -371,8 +371,6 @@ class ParserStepModel(Model):
|
|||
self.ops.scatter_add(d_tokvecs, ids,
|
||||
d_state_features)
|
||||
# Padded -- see update()
|
||||
if isinstance(self.ops, CupyOps):
|
||||
d_tokvecs = self.ops.to_numpy(d_tokvecs)
|
||||
self.bp_tokvecs(d_tokvecs[:-1])
|
||||
return d_tokvecs
|
||||
|
||||
|
@ -445,8 +443,7 @@ cdef class precompute_hiddens:
|
|||
else:
|
||||
cached = gpu_cached
|
||||
if not isinstance(lower_model.get_param("b"), numpy.ndarray):
|
||||
# self.bias = lower_model.get_param("b").get(stream=cuda_stream) ???
|
||||
self.bias = lower_model.get_param("b")
|
||||
self.bias = lower_model.get_param("b").get(stream=cuda_stream)
|
||||
else:
|
||||
self.bias = lower_model.get_param("b")
|
||||
self.nF = cached.shape[1]
|
||||
|
|
Loading…
Reference in New Issue
Block a user