Don't assume blas methods are present

This commit is contained in:
Matthew Honnibal 2018-03-16 02:48:20 +01:00
parent e85dd038fe
commit 648532d647
1 changed files with 10 additions and 10 deletions

View File

@ -28,7 +28,7 @@ from thinc.neural.ops import CupyOps
from thinc.neural.util import get_array_module from thinc.neural.util import get_array_module
from thinc.linalg cimport Vec, VecVec from thinc.linalg cimport Vec, VecVec
from thinc.openblas cimport simple_gemm, simple_axpy from thinc.linalg cimport MatVec, VecVec
from .._ml import zero_init, PrecomputableAffine, Tok2Vec, flatten from .._ml import zero_init, PrecomputableAffine, Tok2Vec, flatten
from .._ml import link_vectors_to_models, create_default_optimizer from .._ml import link_vectors_to_models, create_default_optimizer
@ -172,9 +172,8 @@ cdef void sum_state_features(float* output,
else: else:
idx = token_ids[f] * F * O + f*O idx = token_ids[f] * F * O + f*O
feature = &cached[idx] feature = &cached[idx]
simple_axpy(output, O, feature, 1.) VecVec.add_i(output,
#for i in range(O): feature, 1., O)
# output[i] += feature[i]
output += O output += O
token_ids += F token_ids += F
@ -267,7 +266,7 @@ cdef class Parser:
with Model.use_device('cpu'): with Model.use_device('cpu'):
upper = chain( upper = chain(
clone(LayerNorm(Maxout(hidden_width, hidden_width)), depth-1), clone(Maxout(hidden_width, hidden_width), depth-1),
zero_init(Affine(nr_class, hidden_width, drop_factor=0.0)) zero_init(Affine(nr_class, hidden_width, drop_factor=0.0))
) )
@ -456,19 +455,20 @@ cdef class Parser:
memset(unmaxed, 0, nr_hidden * nr_piece * sizeof(float)) memset(unmaxed, 0, nr_hidden * nr_piece * sizeof(float))
sum_state_features(unmaxed, sum_state_features(unmaxed,
feat_weights, token_ids, 1, nr_feat, nr_hidden * nr_piece) feat_weights, token_ids, 1, nr_feat, nr_hidden * nr_piece)
simple_axpy(unmaxed, nr_hidden*nr_piece, bias, 1.0) VecVec.add_i(unmaxed,
bias, 1., nr_hidden*nr_piece)
state_vector = &vectors[i*nr_hidden] state_vector = &vectors[i*nr_hidden]
for j in range(nr_hidden): for j in range(nr_hidden):
index = j * nr_piece index = j * nr_piece
which = Vec.arg_max(&unmaxed[index], nr_piece) which = Vec.arg_max(&unmaxed[index], nr_piece)
state_vector[j] = unmaxed[index + which] state_vector[j] = unmaxed[index + which]
# Compute hidden-to-output # Compute hidden-to-output
simple_gemm(scores, nr_todo, nr_class, MatVec.batch_dot(scores,
vectors, nr_todo, nr_hidden, hW, vectors, nr_class, nr_hidden, nr_todo)
hW, nr_hidden, nr_class, 0, 0)
# Add bias # Add bias
for i in range(nr_todo): for i in range(nr_todo):
simple_axpy(&scores[i*nr_class], nr_class, hb, 1.0) VecVec.add_i(&scores[i*nr_class],
hb, 1., nr_class)
# Validate actions, argmax, take action. # Validate actions, argmax, take action.
for i in range(nr_todo): for i in range(nr_todo):
state = states[i] state = states[i]