1adrianb / 1adrianb/pytorch-estimate-flops
some error when there is "reshape" in forward
- Ngôn ngữ chính
- Python
- Star
- 303
- Fork
- 21
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
Here I find the x is , and x.size(0) is no longer "int". It reports "TypeError: reshape(): argument 'shape' (position 2) must be tuple of ints, not tuple"
```
import numpy as np
import torchaudio
import torch
import torch
from torch import nn
from pthflops import count_ops
class CustomLayer(nn.Module):
def __init__(self):
super(CustomLayer, self).__init__()
self.conv1 = nn.Conv2d(5, 5, 1, 1, 0)
# ... other layers present inside will also be ignored
def forward(self, x):
x = torch.reshape(x, (x.size(0) , x.size(1), x.size(2), x.size(3)))
return self.conv1(x)
# Create a network and a corresponding input
inp = torch.rand(1,5,7,7)
net = nn.Sequential(
nn.Conv2d(5, 5, 1, 1, 0),
nn.ReLU(inplace=True),
CustomLayer()
)
count_ops(net, inp)
```
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
The issue is in the pthflops library's handling of torch.reshape with Proxy objects. Look at the count_ops function and how it traces operations. The error occurs when x.size(0) returns a Proxy instead of an int. Check the library's proxy handling in the codebase, likely in the core counting or graph traversal logic. The fix involves ensuring shape arguments are properly evaluated or handled during tracing.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python, pytorch
- Lĩnh vực
- machine-learning, tooling
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 40/100