From d0631e3005db1b4a0eab8aed3fb3711c81ff94cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Thu, 21 Oct 2021 11:22:45 +0200 Subject: [PATCH] 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 --- .github/azure-steps.yml | 6 ++++++ spacy/ml/models/parser.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/azure-steps.yml b/.github/azure-steps.yml index f19236dc8..8501b2abe 100644 --- a/.github/azure-steps.yml +++ b/.github/azure-steps.yml @@ -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')) diff --git a/spacy/ml/models/parser.py b/spacy/ml/models/parser.py index aaa6b6b81..63284e766 100644 --- a/spacy/ml/models/parser.py +++ b/spacy/ml/models/parser.py @@ -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"):