Replace use_ops("numpy") by use_ops("cpu") in the parser (#9501)

* Replace use_ops("numpy") by use_ops("cpu") in the parser

This ensures that the best available CPU implementation is chosen
(e.g. Thinc Apple Ops on macOS).

* Run spaCy tests with apple-thinc-ops on macOS
This commit is contained in:
Daniël de Kok 2021-10-21 11:22:45 +02:00 committed by GitHub
parent 28ecf399da
commit d0631e3005
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -108,3 +108,9 @@ steps:
python .github/validate_universe_json.py website/meta/universe.json
displayName: 'Test website/meta/universe.json'
condition: eq(variables['python_version'], '3.8')
- script: |
${{ parameters.prefix }} python -m pip install thinc-apple-ops
${{ parameters.prefix }} python -m pytest --pyargs spacy
displayName: "Run CPU tests with thinc-apple-ops"
condition: and(startsWith(variables['imageName'], 'macos'), eq(variables['python.version'], '3.9'))

View File

@ -84,7 +84,7 @@ def build_tb_parser_model(
)
upper = None
if use_upper:
with use_ops("numpy"):
with use_ops("cpu"):
# Initialize weights at zero, as it's a classification layer.
upper = _define_upper(nO=nO, nI=None)
return TransitionModel(tok2vec, lower, upper, resize_output)
@ -114,7 +114,7 @@ def _resize_upper(model, new_nO):
smaller = upper
nI = smaller.maybe_get_dim("nI")
with use_ops("numpy"):
with use_ops("cpu"):
larger = _define_upper(nO=new_nO, nI=nI)
# it could be that the model is not initialized yet, then skip this bit
if smaller.has_param("W"):