Skip to content

Commit 5cd0f5e

Browse files
Christopher Whelanfacebook-github-bot
authored andcommitted
[PyFI] Update hypothesis and switch from tp2 (pytorch#41645)
Summary: Pull Request resolved: pytorch#41645 Pull Request resolved: facebookresearch/pytext#1405 Test Plan: buck test Reviewed By: thatch Differential Revision: D20323893 fbshipit-source-id: 54665d589568c4198e96a27f0ed8e5b41df7b86b
1 parent b7a9bc0 commit 5cd0f5e

File tree

171 files changed

+822
-381
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+822
-381
lines changed

caffe2/contrib/fakelowp/test/test_batchmatmul_nnpi_fp16.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TestBatchMatMul(serial.SerializedTestCase):
2929
trans_b=st.booleans(),
3030
run_ints=st.booleans()
3131
)
32+
@settings(deadline=10000)
3233
def test_batch_matmul(self, M, K, N, rand_seed, trans_a, trans_b, run_ints):
3334
np.random.seed(rand_seed)
3435
workspace.ResetWorkspace()

caffe2/contrib/fakelowp/test/test_batchnorm_nnpi_fp16.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class BatchnormTest(unittest.TestCase):
4848
size=st.integers(2, 30),
4949
input_channels=st.integers(2, 40),
5050
batch_size=st.integers(2, 20))
51-
@settings(max_examples=100)
51+
@settings(max_examples=100, deadline=1000)
5252
def test_bn(self, seed, size, input_channels, batch_size):
5353
workspace.ResetWorkspace()
5454
np.random.seed(seed)

caffe2/contrib/fakelowp/test/test_fc_nnpi_fp16.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
class FCTest(serial.SerializedTestCase):
2626
@given(seed=st.integers(0, 65534))
27+
@settings(deadline=1000)
2728
def test_clip(self, seed):
2829
np.random.seed(seed)
2930
m, n, k = 8, 8, 8
@@ -77,6 +78,7 @@ def test_clip(self, seed):
7778
np.testing.assert_allclose(Y_glow, np.full((m, n), 65504.0, dtype))
7879

7980
@given(seed=st.integers(0, 65534))
81+
@settings(deadline=1000)
8082
def test_fc_exercise(self, seed):
8183
""" Test that the matmul engine is working, this doesn't test
8284
precision
@@ -137,6 +139,7 @@ def test_fc_exercise(self, seed):
137139
assert(0)
138140

139141
@given(seed=st.integers(0, 65534))
142+
@settings(deadline=1000)
140143
def test_fc_numeric_cases(self, seed):
141144
""" Test numerics, use examples found from the unit test.
142145
Use Fp16FCAcc16NNPI as a reference.
@@ -241,12 +244,12 @@ def test_fc_numeric_cases(self, seed):
241244
if n_offenders > 0:
242245
print_test_debug_info("fc",
243246
{"seed": seed, "iter": i, "m": m, "k": k, "n": n, "X": X0,
244-
"W0": W0, "b0": b0, "Y_glow": Y_glow, "Y_c2": Y_c2,
247+
"W0": W0, "b0": b0, "Y_glow": Y_glow, "Y_c2": Y_c2,
245248
"diff": diff, "rowdiff": rowdiff})
246249
assert(0)
247250

251+
@settings(max_examples=5, deadline=None)
248252
@given(seed=st.integers(0, 65535))
249-
@settings(max_examples=5)
250253
def test_fc_num0(self, seed):
251254
""" Test numerics, fix a dimension and determine the ranges of error.
252255
Use Fp16FCAcc16 as a reference.
@@ -330,7 +333,7 @@ def test_fc_num0(self, seed):
330333
if n_offenders > 0:
331334
print_test_debug_info("fc",
332335
{"seed": seed, "iter": _, "m": m, "k": k, "n": n, "X": X0,
333-
"W0": W0, "b0": b0, "Y_glow": Y_glow, "Y_c2": Y_c2,
336+
"W0": W0, "b0": b0, "Y_glow": Y_glow, "Y_c2": Y_c2,
334337
"diff": diff, "rowdiff": rowdiff})
335338
assert(0)
336339

caffe2/contrib/fakelowp/test/test_int8_ops_nnpi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def _get_scale_zp(self, tensor):
2020
zero_point = int(round(np.clip(zero_point, 0, 255.0)))
2121
return (scale, zero_point)
2222

23+
@settings(max_examples=30, deadline=None)
2324
@given(
2425
n=st.integers(2, 1024),
2526
rand_seed=st.integers(0, 65534),
2627
non_zero_offset=st.booleans()
2728
)
28-
@settings(max_examples=100)
2929
def test_int8_quantize(self, n, rand_seed, non_zero_offset):
3030
print("n={}, rand_seed={}".format(n, rand_seed))
3131
np.random.seed(rand_seed)
@@ -125,7 +125,7 @@ def test_int8_quantize(self, n, rand_seed, non_zero_offset):
125125
rand_seed=st.integers(0, 65534),
126126
quantize_bias=st.sampled_from([False]),
127127
)
128-
@settings(max_examples=100)
128+
@settings(deadline=None, max_examples=30)
129129
def test_int8_fc(
130130
self, n, m, k, rand_seed, quantize_bias
131131
):
@@ -227,7 +227,7 @@ def test_int8_fc(
227227
n=st.integers(1, 4),
228228
rand_seed=st.integers(0, 65534)
229229
)
230-
@settings(max_examples=100)
230+
@settings(max_examples=100, deadline=1000)
231231
def test_int8_small_input(self, n, rand_seed):
232232
print("n={}, rand_seed={}".format(n, rand_seed))
233233
np.random.seed(rand_seed)

caffe2/contrib/fakelowp/test/test_layernorm_nnpi_fp16.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class LayerNorm(serial.SerializedTestCase):
3030
size=st.integers(min_value=2, max_value=128),
3131
epsilon=st.floats(min_value=1e-4, max_value=1e-3),
3232
elementwise_affine=st.booleans())
33-
@settings(max_examples=100)
33+
@settings(max_examples=100, deadline=None)
3434
def test_layernorm(self, seed, batch_size, size, epsilon, elementwise_affine):
3535
np.random.seed(seed)
3636
# Reset the workspace

caffe2/contrib/fakelowp/test/test_op_nnpi_fp16.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
class ArithmeticOpsTest(serial.SerializedTestCase):
2525
@given(seed=st.integers(0, 65534))
26+
@settings(deadline=1000)
2627
def _test_binary_op_graph(self, name, seed):
2728
np.random.seed(seed)
2829
workspace.ResetWorkspace()
@@ -92,8 +93,11 @@ def _test_binary_op_graph(self, name, seed):
9293
Y_glow[Y_glow == np.Inf] = np.finfo(np.float16).max
9394
Y_glow[Y_glow == np.NINF] = np.finfo(np.float16).min
9495

96+
# Ignore mismatches solely due to difference in precision
97+
fp16_finite = np.isfinite(A.astype(np.float16) / B.astype(np.float16))
98+
9599
# Results should be identical since we are comparing with the C2 emulation
96-
if not np.allclose(Y_c2, Y_glow):
100+
if not np.allclose(Y_c2[fp16_finite], Y_glow[fp16_finite]):
97101
diff = np.abs((Y_glow - Y_c2) / (Y_c2 + kEpsilon))
98102
print_test_debug_info(name, {
99103
"dims": dims, "iter": _, "seed": seed, "A": A, "B": B,
@@ -114,6 +118,7 @@ def test_div_graph(self):
114118

115119

116120
class UnaryOpTest(serial.SerializedTestCase):
121+
@settings(deadline=1000)
117122
def _test_unary_op(self, opname, X, rtol=1e-5, atol=1e-8):
118123
workspace.ResetWorkspace()
119124

@@ -287,6 +292,7 @@ def test_logit(self):
287292

288293
class ReluTest(serial.SerializedTestCase):
289294
@given(seed=st.integers(0, 65534))
295+
@settings(deadline=10000)
290296
def relu_test(self, inputs, gc, dc, seed):
291297
np.random.seed(seed)
292298
inputs = np.random.rand(1).astype(np.float32)

caffe2/contrib/fakelowp/test/test_sls_4bit_nnpi_fp16.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
class SparseLengthsSum4BitFakeNNPIFp16Test(serial.SerializedTestCase):
2626
@given(seed=st.integers(0, 65535))
27+
@settings(deadline=10000)
2728
def test_slws_fused_4bit_rowwise_all_same(self, seed):
2829
np.random.seed(seed)
2930
workspace.ResetWorkspace()
@@ -117,7 +118,7 @@ def test_slws_fused_4bit_rowwise_all_same(self, seed):
117118
batch_size=st.integers(1, 32),
118119
max_weight=st.integers(0, 1),
119120
)
120-
@settings(max_examples=100)
121+
@settings(deadline=10000)
121122
def test_slws_fused_4bit_rowwise(self, seed, num_rows, embedding_dim, batch_size, max_weight):
122123
workspace.ResetWorkspace()
123124
np.random.seed(seed)

caffe2/contrib/fakelowp/test/test_sls_8bit_nnpi_fp16.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Must happen before importing caffe2.python.*
66
import caffe2.python.fakelowp.init_shared_libs # noqa
77
import numpy as np
8-
from hypothesis import given
8+
from hypothesis import given, settings
99
from hypothesis import strategies as st
1010
from caffe2.proto import caffe2_pb2
1111
from caffe2.python import core, workspace
@@ -99,6 +99,7 @@ def Skip_test_SLS_NonQuantized_fp16(self):
9999
assert 0
100100

101101
@given(seed=st.integers(0, 65535))
102+
@settings(deadline=10000)
102103
def test_slws_fused_8bit_rowwise_all_same(self, seed):
103104
# Comment out for predictable debugging
104105
np.random.seed(seed)
@@ -206,6 +207,7 @@ def test_slws_fused_8bit_rowwise_all_same(self, seed):
206207
batch_size=st.integers(1, 5),
207208
max_weight=st.integers(0, 100),
208209
)
210+
@settings(deadline=10000)
209211
def test_slws_fused_8bit_rowwise(self, seed, num_rows, embedding_dim, batch_size, max_weight):
210212
np.random.seed(seed)
211213
workspace.ResetWorkspace()
@@ -302,6 +304,7 @@ def test_slws_fused_8bit_rowwise(self, seed, num_rows, embedding_dim, batch_size
302304
# Simple test to aid debugging order of operations
303305
# Minimize the case to an SLS that adds two rows
304306
@given(seed=st.integers(0, 65535))
307+
@settings(deadline=10000)
305308
def test_small_sls(self, seed):
306309
np.random.seed(seed)
307310
workspace.ResetWorkspace()

caffe2/contrib/gloo/gloo_test.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import print_function
66
from __future__ import unicode_literals
77

8-
from hypothesis import given
8+
from hypothesis import given, settings
99
import hypothesis.strategies as st
1010
from multiprocessing import Process, Queue
1111

@@ -213,10 +213,11 @@ def _test_broadcast(self,
213213
workspace.RunNet(net.Name())
214214

215215
@given(comm_size=st.integers(min_value=2, max_value=8),
216-
blob_size=st.integers(min_value=1e3, max_value=1e6),
216+
blob_size=st.integers(min_value=int(1e3), max_value=int(1e6)),
217217
num_blobs=st.integers(min_value=1, max_value=4),
218218
device_option=st.sampled_from([hu.cpu_do]),
219219
use_float16=st.booleans())
220+
@settings(deadline=10000)
220221
def test_broadcast(self, comm_size, blob_size, num_blobs, device_option,
221222
use_float16):
222223
TestCase.test_counter += 1
@@ -328,10 +329,11 @@ def _test_allreduce_multicw(self,
328329
(num_blobs * comm_size) * (num_blobs * comm_size - 1) / 2)
329330

330331
@given(comm_size=st.integers(min_value=2, max_value=8),
331-
blob_size=st.integers(min_value=1e3, max_value=1e6),
332+
blob_size=st.integers(min_value=int(1e3), max_value=int(1e6)),
332333
num_blobs=st.integers(min_value=1, max_value=4),
333334
device_option=st.sampled_from([hu.cpu_do]),
334335
use_float16=st.booleans())
336+
@settings(deadline=10000)
335337
def test_allreduce(self, comm_size, blob_size, num_blobs, device_option,
336338
use_float16):
337339
TestCase.test_counter += 1
@@ -416,10 +418,11 @@ def _test_reduce_scatter(self,
416418
workspace.RunNet(net.Name())
417419

418420
@given(comm_size=st.integers(min_value=2, max_value=8),
419-
blob_size=st.integers(min_value=1e3, max_value=1e6),
421+
blob_size=st.integers(min_value=int(1e3), max_value=int(1e6)),
420422
num_blobs=st.integers(min_value=1, max_value=4),
421423
device_option=st.sampled_from([hu.cpu_do]),
422424
use_float16=st.booleans())
425+
@settings(deadline=10000)
423426
def test_reduce_scatter(self, comm_size, blob_size, num_blobs,
424427
device_option, use_float16):
425428
TestCase.test_counter += 1
@@ -496,10 +499,11 @@ def _test_allgather(self,
496499
workspace.RunNet(net.Name())
497500

498501
@given(comm_size=st.integers(min_value=2, max_value=8),
499-
blob_size=st.integers(min_value=1e3, max_value=1e6),
502+
blob_size=st.integers(min_value=int(1e3), max_value=int(1e6)),
500503
num_blobs=st.integers(min_value=1, max_value=4),
501504
device_option=st.sampled_from([hu.cpu_do]),
502505
use_float16=st.booleans())
506+
@settings(max_examples=10, deadline=None)
503507
def test_allgather(self, comm_size, blob_size, num_blobs, device_option,
504508
use_float16):
505509
TestCase.test_counter += 1
@@ -522,6 +526,7 @@ def test_allgather(self, comm_size, blob_size, num_blobs, device_option,
522526
use_float16=use_float16)
523527

524528
@given(device_option=st.sampled_from([hu.cpu_do]))
529+
@settings(deadline=10000)
525530
def test_forked_cw(self, device_option):
526531
TestCase.test_counter += 1
527532
if os.getenv('COMM_RANK') is not None:
@@ -568,6 +573,7 @@ def _test_barrier(
568573

569574
@given(comm_size=st.integers(min_value=2, max_value=8),
570575
device_option=st.sampled_from([hu.cpu_do]))
576+
@settings(deadline=10000)
571577
def test_barrier(self, comm_size, device_option):
572578
TestCase.test_counter += 1
573579
if os.getenv('COMM_RANK') is not None:
@@ -618,6 +624,7 @@ def _test_close_connection(
618624

619625
@given(comm_size=st.integers(min_value=2, max_value=8),
620626
device_option=st.sampled_from([hu.cpu_do]))
627+
@settings(deadline=10000)
621628
def test_close_connection(self, comm_size, device_option):
622629
import time
623630
start_time = time.time()
@@ -679,6 +686,7 @@ def _test_io_error(
679686

680687
@given(comm_size=st.integers(min_value=2, max_value=8),
681688
device_option=st.sampled_from([hu.cpu_do]))
689+
@settings(deadline=10000)
682690
def test_io_error(self, comm_size, device_option):
683691
TestCase.test_counter += 1
684692
with self.assertRaises(IoError):

caffe2/contrib/nnpack/nnpack_ops_test.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,13 @@ class NNPackOpsTest(hu.HypothesisTestCase):
4848
kernel=st.integers(3, 5),
4949
size=st.integers(5, 10),
5050
input_channels=st.integers(1, 8),
51-
output_channels=st.integers(1, 8),
5251
batch_size=st.integers(1, 5),
5352
groups=st.integers(1, 2))
5453
def test_convolution_correctness(self, stride, pad, kernel, size,
55-
input_channels, output_channels,
54+
input_channels,
5655
batch_size, groups):
56+
input_channels *= groups
57+
output_channels = int(input_channels / groups)
5758
assume(input_channels % groups == 0)
5859
assume(output_channels % groups == 0)
5960
assume(output_channels == input_channels / groups)
@@ -64,7 +65,7 @@ def test_convolution_correctness(self, stride, pad, kernel, size,
6465
X = np.random.rand(
6566
batch_size, input_channels, size, size).astype(np.float32) - 0.5
6667
w = np.random.rand(
67-
output_channels, input_channels, kernel, kernel).astype(np.float32)\
68+
input_channels, output_channels, kernel, kernel).astype(np.float32)\
6869
- 0.5
6970
b = np.random.rand(output_channels).astype(np.float32) - 0.5
7071
order = "NCHW"
@@ -175,7 +176,7 @@ def test_leaky_relu_correctness(self, size, input_channels, batch_size,
175176
atol=1e-4,
176177
rtol=1e-4)
177178

178-
@settings(timeout=3600)
179+
@settings(deadline=3600)
179180
@unittest.skipIf(not os.environ.get("CAFFE2_BENCHMARK"), "Benchmark")
180181
@given(stride=st.integers(1, 1),
181182
pad=st.integers(0, 2),
@@ -213,7 +214,7 @@ def test_timings(self, stride, pad, kernel, size,
213214
print("Speedup for NNPACK: {:.2f}".format(
214215
times[""] / times["NNPACK"]))
215216

216-
@settings(timeout=3600)
217+
@settings(deadline=3600)
217218
@unittest.skipIf(not os.environ.get("CAFFE2_BENCHMARK"), "Benchmark")
218219
@given(size=st.integers(30, 90),
219220
input_channels=st.sampled_from([3, 64, 256]),

0 commit comments

Comments
 (0)