Skip to content

Commit

Permalink
PyUpgrade 3.8 updates (#55)
Browse files Browse the repository at this point in the history
Co-authored-by: UltralyticsAssistant <[email protected]>
  • Loading branch information
glenn-jocher and UltralyticsAssistant authored Sep 1, 2024
1 parent a39771d commit 4c04d0b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion benchmark/evaluate_famous_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
dsize = (1, 3, 299, 299)
inputs = torch.randn(dsize).to(device)
total_ops, total_params = profile(model, (inputs,), verbose=False)
print("%s | %.2f | %.2f" % (name, total_params / (1000**2), total_ops / (1000**3)))
print(f"{name} | {total_params / (1000**2):.2f} | {total_ops / (1000**3):.2f}")
except Exception as e:
print(f"Warning: failed to process {e}")
8 changes: 1 addition & 7 deletions benchmark/evaluate_rnn_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@
total_ops, total_params = profile(model, (inputs[0],), verbose=False)
else:
total_ops, total_params = profile(model, (inputs,), verbose=False)
print(
"{} | {:.2f} | {:.2f}".format(
name,
total_params / 1e6,
total_ops / 1e9,
)
)
print(f"{name} | {total_params / 1e6:.2f} | {total_ops / 1e9:.2f}")

# validate batch_first support
inputs = torch.randn(100, 32, input_size)
Expand Down
4 changes: 2 additions & 2 deletions thop/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def add_hooks(m):

if hasattr(m, "total_ops") or hasattr(m, "total_params"):
logging.warning(
"Either .total_ops or .total_params is already defined in %s. "
"Be careful, it might change your code's behavior." % str(m)
f"Either .total_ops or .total_params is already defined in {str(m)}. "
"Be careful, it might change your code's behavior."
)

m.register_buffer("total_ops", torch.zeros(1, dtype=default_dtype))
Expand Down
2 changes: 1 addition & 1 deletion thop/vision/basic_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def count_convNd_ver2(m: _ConvNd, x, y: torch.Tensor):
x = x[0]

# N x H x W (exclude Cout)
output_size = torch.zeros((y.size()[:1] + y.size()[2:])).numel()
output_size = torch.zeros(y.size()[:1] + y.size()[2:]).numel()
# # Cout x Cin x Kw x Kh
# kernel_ops = m.weight.nelement()
# if m.bias is not None:
Expand Down

0 comments on commit 4c04d0b

Please sign in to comment.