Skip to content

Commit

Permalink
Make mypy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerwooo committed Feb 1, 2025
1 parent fefe882 commit 5e45a6a
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 6 deletions.
40 changes: 39 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# This file was autogenerated by uv via the following command:
# uv pip compile pyproject.toml -o requirements.txt
filelock==3.16.1
# via torch
# via
# torch
# triton
fsspec==2024.10.0
# via torch
jinja2==3.1.4
Expand All @@ -17,10 +19,44 @@ numpy==2.2.0
# torchattack (pyproject.toml)
# scipy
# torchvision
nvidia-cublas-cu12==12.4.5.8
# via
# nvidia-cudnn-cu12
# nvidia-cusolver-cu12
# torch
nvidia-cuda-cupti-cu12==12.4.127
# via torch
nvidia-cuda-nvrtc-cu12==12.4.127
# via torch
nvidia-cuda-runtime-cu12==12.4.127
# via torch
nvidia-cudnn-cu12==9.1.0.70
# via torch
nvidia-cufft-cu12==11.2.1.3
# via torch
nvidia-curand-cu12==10.3.5.147
# via torch
nvidia-cusolver-cu12==11.6.1.9
# via torch
nvidia-cusparse-cu12==12.3.1.170
# via
# nvidia-cusolver-cu12
# torch
nvidia-nccl-cu12==2.21.5
# via torch
nvidia-nvjitlink-cu12==12.4.127
# via
# nvidia-cusolver-cu12
# nvidia-cusparse-cu12
# torch
nvidia-nvtx-cu12==12.4.127
# via torch
pillow==11.0.0
# via torchvision
scipy==1.14.1
# via torchattack (pyproject.toml)
setuptools==75.8.0
# via torch
sympy==1.13.1
# via torch
torch==2.5.1
Expand All @@ -29,5 +65,7 @@ torch==2.5.1
# torchvision
torchvision==0.20.1
# via torchattack (pyproject.toml)
triton==3.1.0
# via torch
typing-extensions==4.12.2
# via torch
2 changes: 1 addition & 1 deletion torchattack/att.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(
elif hasattr(model, 'model_name'):
# If model is initialized via `torchattack.AttackModel`, the model_name
# is automatically attached to the model during instantiation.
self.hook_cfg = model.model_name
self.hook_cfg = model.model_name # type: ignore

self.eps = eps
self.steps = steps
Expand Down
3 changes: 3 additions & 0 deletions torchattack/decowa.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
# Compute gradient
loss.backward()

if delta.grad is None:
continue

# Accumulate gradient
g += delta.grad

Expand Down
2 changes: 1 addition & 1 deletion torchattack/dr.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(
# If model is initialized via `torchattack.AttackModel`, infer its model_name
# from automatically attached attribute during instantiation.
if not model_name and hasattr(model, 'model_name'):
model_name = model.model_name
model_name = model.model_name # type: ignore

self.eps = eps
self.steps = steps
Expand Down
2 changes: 1 addition & 1 deletion torchattack/pna_patchout.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(
elif hasattr(model, 'model_name'):
# If model is initialized via `torchattack.AttackModel`, the model_name
# is automatically attached to the model during instantiation.
self.hook_cfg = model.model_name
self.hook_cfg = model.model_name # type: ignore

self.eps = eps
self.steps = steps
Expand Down
3 changes: 3 additions & 0 deletions torchattack/ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:
# Compute gradient
loss.backward()

if delta.grad is None:
continue

# Accumulate gradient
g += delta.grad

Expand Down
2 changes: 1 addition & 1 deletion torchattack/tgr.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
elif hasattr(model, 'model_name'):
# If model is initialized via `torchattack.AttackModel`, the model_name
# is automatically attached to the model during instantiation.
self.hook_cfg = model.model_name
self.hook_cfg = model.model_name # type: ignore

self.eps = eps
self.steps = steps
Expand Down
2 changes: 1 addition & 1 deletion torchattack/vdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(
elif hasattr(model, 'model_name'):
# If model is initialized via `torchattack.AttackModel`, the model_name
# is automatically attached to the model during instantiation.
self.hook_cfg = model.model_name
self.hook_cfg = model.model_name # type: ignore

self.eps = eps
self.steps = steps
Expand Down
3 changes: 3 additions & 0 deletions torchattack/vmifgsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:

neighbor_loss.backward()

if neighbors.grad is None:
continue

gv_grad += neighbors.grad

# Accumulate gradient variance into v
Expand Down
3 changes: 3 additions & 0 deletions torchattack/vnifgsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ def forward(self, x: torch.Tensor, y: torch.Tensor) -> torch.Tensor:

neighbor_loss.backward()

if neighbors.grad is None:
continue

gv_grad += neighbors.grad

# Accumulate gradient variance into v
Expand Down

0 comments on commit 5e45a6a

Please sign in to comment.