Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cupy.cublas import #921

Merged
merged 3 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ jobs:

- name: Run mypy
run: python -m mypy thinc --no-implicit-reexport
if: matrix.python_version != '3.6'
if: |
matrix.python_version != '3.6' &&
matrix.python_version != '3.7'

- name: Delete source directory
run: rm -rf thinc
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pytest-cov>=2.7.0,<5.0.0
coverage>=5.0.0,<8.0.0
mock>=2.0.0,<3.0.0
flake8>=3.5.0,<3.6.0
mypy>=1.0.0,<1.1.0; python_version >= "3.7"
mypy>=1.5.0,<1.6.0; platform_machine != "aarch64" and python_version >= "3.8"
types-mock>=0.1.1
types-contextvars>=0.1.2; python_version < "3.7"
types-dataclasses>=0.1.3; python_version < "3.7"
Expand Down
4 changes: 2 additions & 2 deletions thinc/backends/cupy_ops.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy

from .. import registry
from ..compat import cupy, cupyx
from ..compat import cublas, cupy, cupyx
from ..types import DeviceTypes
from ..util import (
is_cupy_array,
Expand Down Expand Up @@ -257,7 +257,7 @@ def clip_gradient(self, gradient, threshold):
# implementation.
def frobenius_norm(X):
X_vec = X.reshape(-1)
return cupy.cublas.nrm2(X_vec)
return cublas.nrm2(X_vec)

grad_norm = cupy.maximum(frobenius_norm(gradient), 1e-12)
gradient *= cupy.minimum(threshold, grad_norm) / grad_norm
Expand Down
3 changes: 3 additions & 0 deletions thinc/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

try: # pragma: no cover
import cupy
import cupy.cublas
import cupyx

has_cupy = True
cublas = cupy.cublas
cupy_version = Version(cupy.__version__)
try:
cupy.cuda.runtime.getDeviceCount()
Expand All @@ -20,6 +22,7 @@
else:
cupy_from_dlpack = cupy.fromDlpack
except (ImportError, AttributeError):
cublas = None
cupy = None
cupyx = None
cupy_version = Version("0.0.0")
Expand Down
2 changes: 1 addition & 1 deletion thinc/shims/torchscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TorchScriptShim(PyTorchShim):

def __init__(
self,
model: Optional["torch.ScriptModule"],
model: Optional["torch.jit.ScriptModule"],
config=None,
optimizer: Any = None,
mixed_precision: bool = False,
Expand Down
Loading