Skip to content

Commit 2106e1c

Browse files
CEQ151CEQ151
authored andcommitted
test(mlwm): avoid training dependency in runtime attack tests
1 parent 69fbb0f commit 2106e1c

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

blind_watermark/tests/test_mlwm_attacks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import numpy as np
55

66
from blind_watermark.mlwm.attacks import AttackConfig, apply_random_attack_chain
7-
from blind_watermark.mlwm.train import attack_batch
87

98
try:
109
import torch
@@ -28,6 +27,11 @@ def test_enabled_ops_limits_attack_choices(self):
2827

2928
@unittest.skipIf(torch is None, 'PyTorch is not installed')
3029
def test_attack_batch_uses_straight_through_gradient(self):
30+
try:
31+
from blind_watermark.mlwm.train import attack_batch
32+
except ImportError as exc:
33+
self.skipTest(f'ML training dependencies are not installed: {exc}')
34+
3135
image = torch.rand(1, 3, 40, 40, requires_grad=True)
3236
out = attack_batch(torch, image, AttackConfig(ops_per_sample_min=1, ops_per_sample_max=1), 'medium')
3337
self.assertTrue(out.requires_grad)

0 commit comments

Comments
 (0)