-
Notifications
You must be signed in to change notification settings - Fork 1.8k
The AGP_Pruner example provided can not run successfully, An error occurred: TypeError: unsupported operand type (s) for *: 'Tensor' and 'dict' #2035
Comments
Hi @yeliang2258 , thanks for bringing up this issue!Could you try using nni v1.4? This is fixed in latest version. |
Hello, using cpu, AGP can work normally, but using cuda will report an error, the error message is as follows. The code is the provided example, I changed cpu to cuda, Thanks! |
Hi, @yeliang2258 , could you try add |
Still not working, the error message is as follows: The function pruner.export_model ()) in the example has no effect. Thanks! |
Hi @yeliang2258, could you change |
I modified it and found two problems. First, the pruner.export_model () function did not generate the corresponding file. Second, cuda still couldn't be used, and the same error was reported. my torch is 1.2.0,and nni is V1.4 |
Hi @yeliang2258, after some debugging, it turns out there is a bug in code for transfering buffers between device. Since most examples set origin buffers on cuda, the bug is not spotted. Anyway, I will fix this issue later and inform you after this issue is fixed and tested. |
Ok! thank you very much! Also, the pruner.export_model () function in AGP does not seem to work, it does not generate the corresponding file. |
Hi, @yeliang2258 , the file is generated in the same directory as the directory you run the python command. example: |
Closing as the original problem is fixed. thanks @yeliang2258 and @Cjkkkk |
The error is:
The first epoch can run, but the second epoch reports an error.
The code is from the sample main_torch_pruner.py(https://github.com/microsoft/nni/blob/master/examples/model_compress/main_torch_pruner.py)
code:
from nni.compression.torch import AGP_Pruner
import torch
import torch.nn.functional as F
from torchvision import datasets, transforms
class Mnist(torch.nn.Module):
def init(self):
super().init()
self.conv1 = torch.nn.Conv2d(1, 20, 5, 1)
self.conv2 = torch.nn.Conv2d(20, 50, 5, 1)
self.fc1 = torch.nn.Linear(4 * 4 * 50, 500)
self.fc2 = torch.nn.Linear(500, 10)
def train(model, device, train_loader, optimizer):
model.train()
for batch_idx, (data, target) in enumerate(train_loader):
data, target = data.to(device), target.to(device)
optimizer.zero_grad()
output = model(data)
loss = F.nll_loss(output, target)
loss.backward()
optimizer.step()
if batch_idx % 100 == 0:
print('{:2.0f}% Loss {}'.format(100 * batch_idx / len(train_loader), loss.item()))
def test(model, device, test_loader):
model.eval()
test_loss = 0
correct = 0
with torch.no_grad():
for data, target in test_loader:
data, target = data.to(device), target.to(device)
output = model(data)
test_loss += F.nll_loss(output, target, reduction='sum').item()
pred = output.argmax(dim=1, keepdim=True)
correct += pred.eq(target.view_as(pred)).sum().item()
test_loss /= len(test_loader.dataset)
def main():
torch.manual_seed(0)
device = torch.device('cpu')
if name == 'main':
main()
Thanks!
The text was updated successfully, but these errors were encountered: