mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 10:16:27 +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 b in range(nB):
|
||||||
# for f in range(nF):
|
# for f in range(nF):
|
||||||
# if ids[b, f] < 0:
|
# if ids[b, f] < 0:
|
||||||
# d_padding[0, f] += dY[b]
|
# d_pad[0, f] += dY[b]
|
||||||
#
|
#
|
||||||
# Which can be rewritten as:
|
# 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 :(.
|
# I don't know how to avoid the loop without building a whole array :(.
|
||||||
# Cursed numpy.
|
# 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))
|
d_pad = model.ops.alloc((1, nF, nO, nP))
|
||||||
for b in range(nB):
|
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
|
return d_pad
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -371,8 +371,6 @@ class ParserStepModel(Model):
|
||||||
self.ops.scatter_add(d_tokvecs, ids,
|
self.ops.scatter_add(d_tokvecs, ids,
|
||||||
d_state_features)
|
d_state_features)
|
||||||
# Padded -- see update()
|
# Padded -- see update()
|
||||||
if isinstance(self.ops, CupyOps):
|
|
||||||
d_tokvecs = self.ops.to_numpy(d_tokvecs)
|
|
||||||
self.bp_tokvecs(d_tokvecs[:-1])
|
self.bp_tokvecs(d_tokvecs[:-1])
|
||||||
return d_tokvecs
|
return d_tokvecs
|
||||||
|
|
||||||
|
@ -445,8 +443,7 @@ cdef class precompute_hiddens:
|
||||||
else:
|
else:
|
||||||
cached = gpu_cached
|
cached = gpu_cached
|
||||||
if not isinstance(lower_model.get_param("b"), numpy.ndarray):
|
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").get(stream=cuda_stream)
|
||||||
self.bias = lower_model.get_param("b")
|
|
||||||
else:
|
else:
|
||||||
self.bias = lower_model.get_param("b")
|
self.bias = lower_model.get_param("b")
|
||||||
self.nF = cached.shape[1]
|
self.nF = cached.shape[1]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user