diff --git a/thinc/tests/backends/test_ops.py b/thinc/tests/backends/test_ops.py index 5d9f17524..c8cb6a9df 100644 --- a/thinc/tests/backends/test_ops.py +++ b/thinc/tests/backends/test_ops.py @@ -216,7 +216,7 @@ def test_seq2col_window_one_small(ops): @given(X=strategies.arrays_BOP()) def test_maxout(ops, dtype, X): X = ops.asarray(X, dtype=dtype) - expected_best = X.max(axis=-1) + expected_best = X.max(axis=-1).astype(dtype) predicted_best, which = ops.maxout(X) assert predicted_best.dtype == dtype ops.xp.testing.assert_allclose( @@ -1259,22 +1259,19 @@ def test_ngrams(): def test_compare_activations_to_torch(ops, dtype, x, torch_func): import torch - def cast_torch(scalar: float): - return torch.tensor([scalar], requires_grad=True) - func_name, pytorch_func = torch_func forward = getattr(ops, func_name) backward = getattr(ops, "backprop_" + func_name) # The tolerance of isclose is set to 1e-06 instead of # the default 1e-08 due to the GELU x_thinc = ops.asarray([x], dtype=dtype) - x_torch = cast_torch(x) + x_torch = xp2torch(x_thinc, requires_grad=True) y = pytorch_func(x_torch) y_thinc = forward(x_thinc) y.backward() assert x_thinc.dtype == y_thinc.dtype assert ops.xp.isclose(y_thinc, forward(x_thinc, inplace=True), atol=1e-06) - assert ops.xp.isclose(y_thinc, y.detach().numpy(), atol=1e-06) + assert ops.xp.isclose(y_thinc, y.detach(), atol=1e-06) x_thinc = ops.asarray([x], dtype=dtype) dY_thinc = ops.asarray([1.0], dtype=dtype) dY_thinc_inplace = dY_thinc.copy()