Skip to content

Commit b0f308c

Browse files
maggiemossfacebook-github-bot
authored andcommitted
Flip deep learning
Summary: X-link: pytorch/FBGEMM#2831 X-link: facebookresearch/FBGEMM#26 Reviewed By: connernilsen Differential Revision: D59653154 fbshipit-source-id: 2be7d6c6d540db34391bbd6e0dafe62eec185e82
1 parent 37fdb71 commit b0f308c

File tree

17 files changed

+207
-2
lines changed

17 files changed

+207
-2
lines changed

examples/mpc_autograd_cnn/launcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def _run_experiment(args):
8989
level=level,
9090
format="%(asctime)s - %(process)d - %(name)s - %(levelname)s - %(message)s",
9191
)
92+
# pyre-fixme[21]: Could not find module `mpc_autograd_cnn`.
9293
from mpc_autograd_cnn import run_mpc_autograd_cnn # @manual
9394

9495
run_mpc_autograd_cnn(

examples/mpc_cifar/launcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130

131131
def _run_experiment(args):
132132
# only import here to initialize crypten within the subprocesses
133+
# pyre-fixme[21]: Could not find module `mpc_cifar`.
133134
from mpc_cifar import run_mpc_cifar # @manual
134135

135136
# Only Rank 0 will display logs.

examples/mpc_imagenet/launcher.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
from deeplearning.projects.crypten.examples.multiprocess_launcher import (
2828
MultiProcessLauncher,
2929
)
30+
31+
# pyre-fixme[21]: Could not find module `mpc_imagenet`.
3032
from mpc_imagenet import run_experiment # @manual
3133

3234

examples/mpc_linear_svm/launcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def _run_experiment(args):
7474
level=level,
7575
format="%(asctime)s - %(process)d - %(name)s - %(levelname)s - %(message)s",
7676
)
77+
# pyre-fixme[21]: Could not find module `mpc_linear_svm`.
7778
from mpc_linear_svm import run_mpc_linear_svm # @manual
7879

7980
run_mpc_linear_svm(

examples/tfe_benchmarks/launcher.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139

140140
def _run_experiment(args):
141141
# only import here to initialize crypten within the subprocesses
142+
# pyre-fixme[21]: Could not find module `tfe_benchmarks`.
142143
from tfe_benchmarks import run_tfe_benchmarks # @manual
143144

144145
# Only Rank 0 will display logs.

test/test_arithmetic.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class TestArithmetic(MultiProcessTestCase):
2323
This class tests all functions of the ArithmeticSharedTensor.
2424
"""
2525

26+
# pyre-fixme[14]: `setUp` overrides method defined in `MultiProcessTestCase`
27+
# inconsistently.
2628
def setUp(self) -> None:
2729
super().setUp()
2830
# We don't want the main process (rank -1) to initialize the communcator
@@ -170,23 +172,32 @@ def test_arithmetic(self) -> None:
170172
self._check(encrypted_out, reference, "square failed")
171173

172174
# Test radd, rsub, and rmul
175+
# pyre-fixme[61]: `tensor1` is undefined, or not always defined.
173176
reference = 2 + tensor1
177+
# pyre-fixme[61]: `tensor1` is undefined, or not always defined.
174178
encrypted = ArithmeticSharedTensor(tensor1)
179+
# pyre-fixme[58]: `+` is not supported for operand types `int` and
180+
# `ArithmeticSharedTensor`.
175181
encrypted_out = 2 + encrypted
176182
self._check(encrypted_out, reference, "right add failed")
177183

184+
# pyre-fixme[61]: `tensor1` is undefined, or not always defined.
178185
reference = 2 - tensor1
179186
encrypted_out = 2 - encrypted
180187
self._check(encrypted_out, reference, "right sub failed")
181188

189+
# pyre-fixme[61]: `tensor1` is undefined, or not always defined.
182190
reference = 2 * tensor1
191+
# pyre-fixme[58]: `*` is not supported for operand types `int` and
192+
# `ArithmeticSharedTensor`.
183193
encrypted_out = 2 * encrypted
184194
self._check(encrypted_out, reference, "right mul failed")
185195

186196
def test_sum(self) -> None:
187197
"""Tests sum reduction on encrypted tensor."""
188198
tensor = get_random_test_tensor(size=(5, 100, 100), is_float=True)
189199
encrypted = ArithmeticSharedTensor(tensor)
200+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `sum`.
190201
self._check(encrypted.sum(), tensor.sum(), "sum failed")
191202

192203
for dim in [0, 1, 2]:
@@ -198,6 +209,7 @@ def test_prod(self) -> None:
198209
"""Tests prod reduction on encrypted tensor."""
199210
tensor = get_random_test_tensor(size=(3, 3), max_value=3, is_float=False)
200211
encrypted = ArithmeticSharedTensor(tensor)
212+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `prod`.
201213
self._check(encrypted.prod(), tensor.prod().float(), "prod failed")
202214

203215
# test with dim argument
@@ -231,6 +243,7 @@ def test_mean(self) -> None:
231243
"""Tests computing means of encrypted tensors."""
232244
tensor = get_random_test_tensor(size=(5, 10, 15), is_float=True)
233245
encrypted = ArithmeticSharedTensor(tensor)
246+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `mean`.
234247
self._check(encrypted.mean(), tensor.mean(), "mean failed")
235248

236249
for dim in [0, 1, 2]:
@@ -350,6 +363,7 @@ def test_dot_ger(self) -> None:
350363

351364
# dot
352365
encrypted_tensor = ArithmeticSharedTensor(tensor1)
366+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `dot`.
353367
encrypted_out = encrypted_tensor.dot(tensor2)
354368
self._check(
355369
encrypted_out,
@@ -363,6 +377,7 @@ def test_dot_ger(self) -> None:
363377

364378
# ger
365379
encrypted_tensor = ArithmeticSharedTensor(tensor1)
380+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `ger`.
366381
encrypted_out = encrypted_tensor.ger(tensor2)
367382
self._check(
368383
encrypted_out,
@@ -382,11 +397,13 @@ def test_squeeze(self) -> None:
382397
reference = tensor.unsqueeze(dim)
383398

384399
encrypted = ArithmeticSharedTensor(tensor)
400+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `unsqueeze`.
385401
encrypted_out = encrypted.unsqueeze(dim)
386402
self._check(encrypted_out, reference, "unsqueeze failed")
387403

388404
# Test squeeze
389405
encrypted = ArithmeticSharedTensor(tensor.unsqueeze(0))
406+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `squeeze`.
390407
encrypted_out = encrypted.squeeze()
391408
self._check(encrypted_out, reference.squeeze(), "squeeze failed")
392409

@@ -417,12 +434,15 @@ def test_transpose(self) -> None:
417434

418435
if len(size) == 2: # t() asserts dim == 2
419436
reference = tensor.t()
437+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `t`.
420438
encrypted_out = encrypted_tensor.t()
421439
self._check(encrypted_out, reference, "t() failed")
422440

423441
for dim0 in range(len(size)):
424442
for dim1 in range(len(size)):
425443
reference = tensor.transpose(dim0, dim1)
444+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute
445+
# `transpose`.
426446
encrypted_out = encrypted_tensor.transpose(dim0, dim1)
427447
self._check(encrypted_out, reference, "transpose failed")
428448

@@ -445,6 +465,7 @@ def test_permute(self) -> None:
445465
# test reversing the dimensions
446466
dim_arr = [x - 1 for x in range(tensor.dim(), 0, -1)]
447467
reference = tensor.permute(dim_arr)
468+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `permute`.
448469
encrypted_out = encrypted_tensor.permute(dim_arr)
449470
self._check(encrypted_out, reference, "permute failed")
450471

@@ -628,6 +649,7 @@ def test_take(self) -> None:
628649
for dimension in range(0, 4):
629650
reference = torch.from_numpy(tensor.numpy().take(index, dimension))
630651
encrypted_tensor = ArithmeticSharedTensor(tensor)
652+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `take`.
631653
encrypted_out = encrypted_tensor.take(index, dimension)
632654
self._check(encrypted_out, reference, "take function failed: dimension set")
633655

@@ -653,6 +675,8 @@ def test_get_set(self) -> None:
653675
reference = tensor[:, 0]
654676

655677
encrypted_tensor = ArithmeticSharedTensor(tensor)
678+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute
679+
# `__getitem__`.
656680
encrypted_out = encrypted_tensor[:, 0]
657681
self._check(encrypted_out, reference, "getitem failed")
658682

@@ -933,6 +957,7 @@ def test_gather(self) -> None:
933957
index = index.abs().clamp(0, 4)
934958
encrypted = ArithmeticSharedTensor(tensor)
935959
reference = tensor.gather(dim, index)
960+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `gather`.
936961
encrypted_out = encrypted.gather(dim, index)
937962
self._check(encrypted_out, reference, f"gather failed with size {size}")
938963

@@ -948,6 +973,7 @@ def test_split(self) -> None:
948973
for idx in range(6):
949974
split = (idx, 5 - idx)
950975
reference0, reference1 = tensor.split(split, dim=dim)
976+
# pyre-fixme[16]: `ArithmeticSharedTensor` has no attribute `split`.
951977
encrypted_out0, encrypted_out1 = encrypted.split(split, dim=dim)
952978

953979
self._check(

test/test_autograd.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ def test_autograd(self) -> None:
452452
# check output of forward pass:
453453
output, encr_output = outputs[-1][0], encr_outputs[-1][0]
454454
self._check(encr_output._tensor, output, "forward failed")
455+
# pyre-fixme[16]: `TestAutograd` has no attribute `assertTrue`.
455456
self.assertTrue(encr_output.requires_grad, "requires_grad incorrect")
456457

457458
# perform backward pass:
@@ -477,6 +478,7 @@ def test_autograd_repetition(self) -> None:
477478
output = input.exp().sum()
478479
encr_output = encr_input.exp().sum()
479480
self._check(encr_output._tensor, output, "forward failed")
481+
# pyre-fixme[16]: `TestAutograd` has no attribute `assertTrue`.
480482
self.assertTrue(encr_output.requires_grad, "requires_grad incorrect")
481483

482484
# perform backward computation:
@@ -487,7 +489,10 @@ def test_autograd_repetition(self) -> None:
487489

488490
# Run all unit tests with both TFP and TTP providers
489491
class TestTFP(MultiProcessTestCase, TestAutograd):
492+
# pyre-fixme[14]: `setUp` overrides method defined in `MultiProcessTestCase`
493+
# inconsistently.
490494
def setUp(self) -> None:
495+
# pyre-fixme[16]: `CrypTenConfig` has no attribute `mpc`.
491496
self._original_provider = cfg.mpc.provider
492497
cfg.mpc.provider = "TFP"
493498
super(TestTFP, self).setUp()
@@ -498,7 +503,10 @@ def tearDown(self) -> None:
498503

499504

500505
class TestTTP(MultiProcessTestCase, TestAutograd):
506+
# pyre-fixme[14]: `setUp` overrides method defined in `MultiProcessTestCase`
507+
# inconsistently.
501508
def setUp(self) -> None:
509+
# pyre-fixme[16]: `CrypTenConfig` has no attribute `mpc`.
502510
self._original_provider = cfg.mpc.provider
503511
cfg.mpc.provider = "TTP"
504512
super(TestTTP, self).setUp()

test/test_binary.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class TestBinary(MultiProcessTestCase):
2121
This class tests all functions of BinarySharedTensor.
2222
"""
2323

24+
# pyre-fixme[14]: `setUp` overrides method defined in `MultiProcessTestCase`
25+
# inconsistently.
2426
def setUp(self) -> None:
2527
super().setUp()
2628
# We don't want the main process (rank -1) to initialize the communcator
@@ -112,12 +114,14 @@ def test_transpose(self) -> None:
112114

113115
if len(size) == 2: # t() asserts dim == 2
114116
reference = tensor.t()
117+
# pyre-fixme[16]: `BinarySharedTensor` has no attribute `t`.
115118
encrypted_out = encrypted_tensor.t()
116119
self._check(encrypted_out, reference, "t() failed")
117120

118121
for dim0 in range(len(size)):
119122
for dim1 in range(len(size)):
120123
reference = tensor.transpose(dim0, dim1)
124+
# pyre-fixme[16]: `BinarySharedTensor` has no attribute `transpose`.
121125
encrypted_out = encrypted_tensor.transpose(dim0, dim1)
122126
self._check(encrypted_out, reference, "transpose failed")
123127

@@ -140,6 +144,7 @@ def test_permute(self) -> None:
140144
# test reversing the dimensions
141145
dim_arr = [x - 1 for x in range(tensor.dim(), 0, -1)]
142146
reference = tensor.permute(dim_arr)
147+
# pyre-fixme[16]: `BinarySharedTensor` has no attribute `permute`.
143148
encrypted_out = encrypted_tensor.permute(dim_arr)
144149
self._check(encrypted_out, reference, "permute failed")
145150

@@ -243,6 +248,8 @@ def test_add(self) -> None:
243248
reference = tensor + tensor2
244249
encrypted_tensor = BinarySharedTensor(tensor)
245250
encrypted_tensor2 = tensor_type(tensor2)
251+
# pyre-fixme[58]: `+` is not supported for operand types
252+
# `BinarySharedTensor` and `Any`.
246253
encrypted_out = encrypted_tensor + encrypted_tensor2
247254
self._check(encrypted_out, reference, "%s add failed" % tensor_type)
248255

@@ -281,6 +288,7 @@ def test_get_set(self) -> None:
281288
reference = tensor[:, 0]
282289

283290
encrypted_tensor = BinarySharedTensor(tensor)
291+
# pyre-fixme[16]: `BinarySharedTensor` has no attribute `__getitem__`.
284292
encrypted_out = encrypted_tensor[:, 0]
285293
self._check(encrypted_out, reference, "getitem failed")
286294

@@ -462,6 +470,7 @@ def test_gather(self) -> None:
462470
index = index.abs().clamp(0, 4)
463471
encrypted = BinarySharedTensor(tensor)
464472
reference = tensor.gather(dim, index)
473+
# pyre-fixme[16]: `BinarySharedTensor` has no attribute `gather`.
465474
encrypted_out = encrypted.gather(dim, index)
466475
self._check(encrypted_out, reference, f"gather failed with size {size}")
467476

@@ -516,6 +525,7 @@ def test_split(self) -> None:
516525
for idx in range(6):
517526
split = (idx, 5 - idx)
518527
reference0, reference1 = tensor.split(split, dim=dim)
528+
# pyre-fixme[16]: `BinarySharedTensor` has no attribute `split`.
519529
encrypted_out0, encrypted_out1 = encrypted.split(split, dim=dim)
520530

521531
self._check(

0 commit comments

Comments
 (0)