mirror of https://github.com/explosion/spaCy.git
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:
parent
28ecf399da
commit
d0631e3005
|
@ -108,3 +108,9 @@ steps:
|
||||||
python .github/validate_universe_json.py website/meta/universe.json
|
python .github/validate_universe_json.py website/meta/universe.json
|
||||||
displayName: 'Test website/meta/universe.json'
|
displayName: 'Test website/meta/universe.json'
|
||||||
condition: eq(variables['python_version'], '3.8')
|
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'))
|
||||||
|
|
|
@ -84,7 +84,7 @@ def build_tb_parser_model(
|
||||||
)
|
)
|
||||||
upper = None
|
upper = None
|
||||||
if use_upper:
|
if use_upper:
|
||||||
with use_ops("numpy"):
|
with use_ops("cpu"):
|
||||||
# Initialize weights at zero, as it's a classification layer.
|
# Initialize weights at zero, as it's a classification layer.
|
||||||
upper = _define_upper(nO=nO, nI=None)
|
upper = _define_upper(nO=nO, nI=None)
|
||||||
return TransitionModel(tok2vec, lower, upper, resize_output)
|
return TransitionModel(tok2vec, lower, upper, resize_output)
|
||||||
|
@ -114,7 +114,7 @@ def _resize_upper(model, new_nO):
|
||||||
|
|
||||||
smaller = upper
|
smaller = upper
|
||||||
nI = smaller.maybe_get_dim("nI")
|
nI = smaller.maybe_get_dim("nI")
|
||||||
with use_ops("numpy"):
|
with use_ops("cpu"):
|
||||||
larger = _define_upper(nO=new_nO, nI=nI)
|
larger = _define_upper(nO=new_nO, nI=nI)
|
||||||
# it could be that the model is not initialized yet, then skip this bit
|
# it could be that the model is not initialized yet, then skip this bit
|
||||||
if smaller.has_param("W"):
|
if smaller.has_param("W"):
|
||||||
|
|
Loading…
Reference in New Issue