Skip to content

Commit 8b64ad5

Browse files
craymichaelfacebook-github-bot
authored andcommitted
Add remote execution on GPUs for skipped CUDA unit tests (meta-pytorch#1552)
Summary: Pull Request resolved: meta-pytorch#1552 Various tests are being skipped as their configuration does not specify that a GPU is required for execution. Examples: https://www.internalfb.com/omh/view/ai_platform_devx/tests This adds proper configuration for the targets in `//pytorch/captum/tests/module:` PACKAGE file specified in line with documentation https://www.internalfb.com/wiki/Remote_Execution/users/gpu/gpu_contbuild_migration/ Reviewed By: cyrjano Differential Revision: D73871122 fbshipit-source-id: c8dd7adf988863ec8f98aaad7926c473713a0f7b
1 parent e30ad1f commit 8b64ad5

File tree

5 files changed

+22
-92
lines changed

5 files changed

+22
-92
lines changed

tests/module/__init__.py

Whitespace-only changes.

tests/module/test_binary_concrete_stochastic_gates.py

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,19 @@
88
from captum.module.binary_concrete_stochastic_gates import BinaryConcreteStochasticGates
99
from captum.testing.helpers import BaseTest
1010
from captum.testing.helpers.basic import assertTensorAlmostEqual
11-
from parameterized import parameterized_class
1211

1312

14-
@parameterized_class(
15-
[
16-
{"testing_device": "cpu"},
17-
{"testing_device": "cuda"},
18-
]
19-
)
2013
class TestBinaryConcreteStochasticGates(BaseTest):
21-
# pyre-fixme[13]: Attribute `testing_device` is never initialized.
22-
testing_device: str
14+
testing_device: str = "cpu"
2315

2416
def setUp(self) -> None:
2517
super().setUp()
26-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
27-
# `testing_device`.
2818
if self.testing_device == "cuda" and not torch.cuda.is_available():
2919
raise unittest.SkipTest("Skipping GPU test since CUDA not available.")
3020

3121
def test_bcstg_1d_input(self) -> None:
3222

3323
dim = 3
34-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
35-
# `testing_device`.
3624
bcstg = BinaryConcreteStochasticGates(dim).to(self.testing_device)
3725
input_tensor = torch.tensor(
3826
[
@@ -57,8 +45,6 @@ def test_bcstg_1d_input_with_reg_reduction(self) -> None:
5745

5846
dim = 3
5947
mean_bcstg = BinaryConcreteStochasticGates(dim, reg_reduction="mean").to(
60-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
61-
# `testing_device`.
6248
self.testing_device
6349
)
6450
none_bcstg = BinaryConcreteStochasticGates(dim, reg_reduction="none").to(
@@ -82,8 +68,6 @@ def test_bcstg_1d_input_with_reg_reduction(self) -> None:
8268
def test_bcstg_1d_input_with_n_gates_error(self) -> None:
8369

8470
dim = 3
85-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
86-
# `testing_device`.
8771
bcstg = BinaryConcreteStochasticGates(dim).to(self.testing_device)
8872
input_tensor = torch.tensor([0.0, 0.1, 0.2]).to(self.testing_device)
8973

@@ -95,14 +79,10 @@ def test_bcstg_num_mask_not_equal_dim_error(self) -> None:
9579
mask = torch.tensor([0, 0, 1]) # only two distinct masks, but given dim is 3
9680

9781
with self.assertRaises(AssertionError):
98-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
99-
# `testing_device`.
10082
BinaryConcreteStochasticGates(dim, mask=mask).to(self.testing_device)
10183

10284
def test_gates_values_matching_dim_when_eval(self) -> None:
10385
dim = 3
104-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
105-
# `testing_device`.
10686
bcstg = BinaryConcreteStochasticGates(dim).to(self.testing_device)
10787
input_tensor = torch.tensor(
10888
[
@@ -118,8 +98,6 @@ def test_gates_values_matching_dim_when_eval(self) -> None:
11898
def test_bcstg_1d_input_with_mask(self) -> None:
11999

120100
dim = 2
121-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
122-
# `testing_device`.
123101
mask = torch.tensor([0, 0, 1]).to(self.testing_device)
124102
bcstg = BinaryConcreteStochasticGates(dim, mask=mask).to(self.testing_device)
125103
input_tensor = torch.tensor(
@@ -144,8 +122,6 @@ def test_bcstg_1d_input_with_mask(self) -> None:
144122
def test_bcstg_2d_input(self) -> None:
145123

146124
dim = 3 * 2
147-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
148-
# `testing_device`.
149125
bcstg = BinaryConcreteStochasticGates(dim).to(self.testing_device)
150126

151127
# shape(2,3,2)
@@ -185,8 +161,6 @@ def test_bcstg_2d_input(self) -> None:
185161
def test_bcstg_2d_input_with_n_gates_error(self) -> None:
186162

187163
dim = 5
188-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
189-
# `testing_device`.
190164
bcstg = BinaryConcreteStochasticGates(dim).to(self.testing_device)
191165
input_tensor = torch.tensor(
192166
[
@@ -210,8 +184,6 @@ def test_bcstg_2d_input_with_mask(self) -> None:
210184
[1, 1],
211185
[0, 2],
212186
]
213-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
214-
# `testing_device`.
215187
).to(self.testing_device)
216188
bcstg = BinaryConcreteStochasticGates(dim, mask=mask).to(self.testing_device)
217189

@@ -252,8 +224,6 @@ def test_bcstg_2d_input_with_mask(self) -> None:
252224
def test_get_gate_values_1d_input(self) -> None:
253225

254226
dim = 3
255-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
256-
# `testing_device`.
257227
bcstg = BinaryConcreteStochasticGates(dim).to(self.testing_device)
258228
input_tensor = torch.tensor(
259229
[
@@ -273,8 +243,6 @@ def test_get_gate_values_1d_input_with_mask(self) -> None:
273243

274244
dim = 2
275245
mask = torch.tensor([0, 1, 1])
276-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
277-
# `testing_device`.
278246
bcstg = BinaryConcreteStochasticGates(dim, mask=mask).to(self.testing_device)
279247
input_tensor = torch.tensor(
280248
[
@@ -293,8 +261,6 @@ def test_get_gate_values_1d_input_with_mask(self) -> None:
293261
def test_get_gate_values_2d_input(self) -> None:
294262

295263
dim = 3 * 2
296-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
297-
# `testing_device`.
298264
bcstg = BinaryConcreteStochasticGates(dim).to(self.testing_device)
299265

300266
# shape(2,3,2)
@@ -326,8 +292,6 @@ def test_get_gate_values_clamp(self) -> None:
326292
torch.tensor([10.0, -10.0, 10.0]),
327293
lower_bound=-2,
328294
upper_bound=2,
329-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
330-
# `testing_device`.
331295
).to(self.testing_device)
332296

333297
clamped_gate_values = bcstg.get_gate_values().cpu().tolist()
@@ -350,8 +314,6 @@ def test_get_gate_values_2d_input_with_mask(self) -> None:
350314
[0, 2],
351315
]
352316
)
353-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
354-
# `testing_device`.
355317
bcstg = BinaryConcreteStochasticGates(dim, mask=mask).to(self.testing_device)
356318

357319
input_tensor = torch.tensor(
@@ -379,8 +341,6 @@ def test_get_gate_values_2d_input_with_mask(self) -> None:
379341
def test_get_gate_active_probs_1d_input(self) -> None:
380342

381343
dim = 3
382-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
383-
# `testing_device`.
384344
bcstg = BinaryConcreteStochasticGates(dim).to(self.testing_device)
385345
input_tensor = torch.tensor(
386346
[
@@ -402,8 +362,6 @@ def test_get_gate_active_probs_1d_input_with_mask(self) -> None:
402362

403363
dim = 2
404364
mask = torch.tensor([0, 1, 1])
405-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
406-
# `testing_device`.
407365
bcstg = BinaryConcreteStochasticGates(dim, mask=mask).to(self.testing_device)
408366
input_tensor = torch.tensor(
409367
[
@@ -424,8 +382,6 @@ def test_get_gate_active_probs_1d_input_with_mask(self) -> None:
424382
def test_get_gate_active_probs_2d_input(self) -> None:
425383

426384
dim = 3 * 2
427-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
428-
# `testing_device`.
429385
bcstg = BinaryConcreteStochasticGates(dim).to(self.testing_device)
430386

431387
# shape(2,3,2)
@@ -463,8 +419,6 @@ def test_get_gate_active_probs_2d_input_with_mask(self) -> None:
463419
[0, 2],
464420
]
465421
)
466-
# pyre-fixme[16]: `TestBinaryConcreteStochasticGates` has no attribute
467-
# `testing_device`.
468422
bcstg = BinaryConcreteStochasticGates(dim, mask=mask).to(self.testing_device)
469423

470424
input_tensor = torch.tensor(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python3
2+
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
3+
4+
# pyre-strict
5+
6+
from .test_binary_concrete_stochastic_gates import TestBinaryConcreteStochasticGates
7+
8+
9+
class TestBinaryConcreteStochasticGatesCUDA(TestBinaryConcreteStochasticGates):
10+
testing_device: str = "cuda"

tests/module/test_gaussian_stochastic_gates.py

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,19 @@
99
from captum.module.gaussian_stochastic_gates import GaussianStochasticGates
1010
from captum.testing.helpers import BaseTest
1111
from captum.testing.helpers.basic import assertTensorAlmostEqual
12-
from parameterized import parameterized_class
1312

1413

15-
@parameterized_class(
16-
[
17-
{"testing_device": "cpu"},
18-
{"testing_device": "cuda"},
19-
]
20-
)
2114
class TestGaussianStochasticGates(BaseTest):
22-
# pyre-fixme[13]: Attribute `testing_device` is never initialized.
23-
testing_device: str
15+
testing_device: str = "cpu"
2416

2517
def setUp(self) -> None:
2618
super().setUp()
27-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
28-
# `testing_device`.
2919
if self.testing_device == "cuda" and not torch.cuda.is_available():
3020
raise unittest.SkipTest("Skipping GPU test since CUDA not available.")
3121

3222
def test_gstg_1d_input(self) -> None:
3323

3424
dim = 3
35-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
36-
# `testing_device`.
3725
gstg = GaussianStochasticGates(dim).to(self.testing_device)
3826

3927
input_tensor = torch.tensor(
@@ -58,8 +46,6 @@ def test_gstg_1d_input(self) -> None:
5846
def test_gstg_1d_input_with_reg_reduction(self) -> None:
5947
dim = 3
6048
mean_gstg = GaussianStochasticGates(dim, reg_reduction="mean").to(
61-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
62-
# `testing_device`.
6349
self.testing_device
6450
)
6551
none_gstg = GaussianStochasticGates(dim, reg_reduction="none").to(
@@ -84,8 +70,6 @@ def test_gstg_1d_input_with_reg_reduction(self) -> None:
8470
def test_gstg_1d_input_with_n_gates_error(self) -> None:
8571

8672
dim = 3
87-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
88-
# `testing_device`.
8973
gstg = GaussianStochasticGates(dim).to(self.testing_device)
9074
input_tensor = torch.tensor([0.0, 0.1, 0.2]).to(self.testing_device)
9175

@@ -95,8 +79,6 @@ def test_gstg_1d_input_with_n_gates_error(self) -> None:
9579
def test_gstg_1d_input_with_mask(self) -> None:
9680

9781
dim = 2
98-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
99-
# `testing_device`.
10082
mask = torch.tensor([0, 0, 1]).to(self.testing_device)
10183
gstg = GaussianStochasticGates(dim, mask=mask).to(self.testing_device)
10284
input_tensor = torch.tensor(
@@ -120,8 +102,6 @@ def test_gstg_1d_input_with_mask(self) -> None:
120102

121103
def test_gates_values_matching_dim_when_eval(self) -> None:
122104
dim = 3
123-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
124-
# `testing_device`.
125105
gstg = GaussianStochasticGates(dim).to(self.testing_device)
126106
input_tensor = torch.tensor(
127107
[
@@ -137,8 +117,6 @@ def test_gates_values_matching_dim_when_eval(self) -> None:
137117
def test_gstg_2d_input(self) -> None:
138118

139119
dim = 3 * 2
140-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
141-
# `testing_device`.
142120
gstg = GaussianStochasticGates(dim).to(self.testing_device)
143121

144122
# shape(2,3,2)
@@ -178,8 +156,6 @@ def test_gstg_2d_input(self) -> None:
178156
def test_gstg_2d_input_with_n_gates_error(self) -> None:
179157

180158
dim = 5
181-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
182-
# `testing_device`.
183159
gstg = GaussianStochasticGates(dim).to(self.testing_device)
184160
input_tensor = torch.tensor(
185161
[
@@ -203,8 +179,6 @@ def test_gstg_2d_input_with_mask(self) -> None:
203179
[1, 1],
204180
[0, 2],
205181
]
206-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
207-
# `testing_device`.
208182
).to(self.testing_device)
209183
gstg = GaussianStochasticGates(dim, mask=mask).to(self.testing_device)
210184

@@ -245,8 +219,6 @@ def test_gstg_2d_input_with_mask(self) -> None:
245219
def test_get_gate_values_1d_input(self) -> None:
246220

247221
dim = 3
248-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
249-
# `testing_device`.
250222
gstg = GaussianStochasticGates(dim).to(self.testing_device)
251223
input_tensor = torch.tensor(
252224
[
@@ -265,8 +237,6 @@ def test_get_gate_values_1d_input_with_mask(self) -> None:
265237

266238
dim = 2
267239
mask = torch.tensor([0, 1, 1])
268-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
269-
# `testing_device`.
270240
gstg = GaussianStochasticGates(dim, mask=mask).to(self.testing_device)
271241
input_tensor = torch.tensor(
272242
[
@@ -284,8 +254,6 @@ def test_get_gate_values_1d_input_with_mask(self) -> None:
284254
def test_get_gate_values_2d_input(self) -> None:
285255

286256
dim = 3 * 2
287-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
288-
# `testing_device`.
289257
gstg = GaussianStochasticGates(dim).to(self.testing_device)
290258

291259
# shape(2,3,2)
@@ -320,8 +288,6 @@ def test_get_gate_values_2d_input_with_mask(self) -> None:
320288
[0, 2],
321289
]
322290
)
323-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
324-
# `testing_device`.
325291
gstg = GaussianStochasticGates(dim, mask=mask).to(self.testing_device)
326292

327293
input_tensor = torch.tensor(
@@ -348,8 +314,6 @@ def test_get_gate_values_2d_input_with_mask(self) -> None:
348314
def test_get_gate_values_clamp(self) -> None:
349315
gstg = GaussianStochasticGates._from_pretrained(
350316
torch.tensor([2.0, -2.0, 2.0])
351-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
352-
# `testing_device`.
353317
).to(self.testing_device)
354318

355319
clamped_gate_values = gstg.get_gate_values().cpu().tolist()
@@ -365,8 +329,6 @@ def test_get_gate_values_clamp(self) -> None:
365329
def test_get_gate_active_probs_1d_input(self) -> None:
366330

367331
dim = 3
368-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
369-
# `testing_device`.
370332
gstg = GaussianStochasticGates(dim).to(self.testing_device)
371333
input_tensor = torch.tensor(
372334
[
@@ -387,8 +349,6 @@ def test_get_gate_active_probs_1d_input_with_mask(self) -> None:
387349

388350
dim = 2
389351
mask = torch.tensor([0, 1, 1])
390-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
391-
# `testing_device`.
392352
gstg = GaussianStochasticGates(dim, mask=mask).to(self.testing_device)
393353
input_tensor = torch.tensor(
394354
[
@@ -409,8 +369,6 @@ def test_get_gate_active_probs_1d_input_with_mask(self) -> None:
409369
def test_get_gate_active_probs_2d_input(self) -> None:
410370

411371
dim = 3 * 2
412-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
413-
# `testing_device`.
414372
gstg = GaussianStochasticGates(dim).to(self.testing_device)
415373

416374
# shape(2,3,2)
@@ -448,8 +406,6 @@ def test_get_gate_active_probs_2d_input_with_mask(self) -> None:
448406
[0, 2],
449407
]
450408
)
451-
# pyre-fixme[16]: `TestGaussianStochasticGates` has no attribute
452-
# `testing_device`.
453409
gstg = GaussianStochasticGates(dim, mask=mask).to(self.testing_device)
454410

455411
input_tensor = torch.tensor(
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env fbpython
2+
# (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
3+
4+
# pyre-strict
5+
6+
from .test_gaussian_stochastic_gates import TestGaussianStochasticGates
7+
8+
9+
class TestGaussianStochasticGatesCUDA(TestGaussianStochasticGates):
10+
testing_device: str = "cuda"

0 commit comments

Comments
 (0)