Code needs to be updated to make sure it runs without errors
The function accumulate_grad() inside Trainer() class in train_distilled_image.py needs to be updated as follows:
def accumulate_grad(self, grad_infos):
bwd_out = []
bwd_grad = []
for datas, gdatas, lrs, glrs in grad_infos:
bwd_out.extend(lrs)
bwd_grad.extend(glrs)
for d, g in zip(datas, gdatas):
if d.grad is not None:
d.grad.add_(g)
else:
d.grad = g
if bwd_out:
torch.autograd.backward(bwd_out, grad_tensors=bwd_grad)
With the current code, I get the following error:
Traceback (most recent call last):
File "./dataset_distillation/dataset-distillation/main.py", line 402, in <module>
main(options.get_state())
File "./dataset_distillation/dataset-distillation/main.py", line 131, in main
steps = train_distilled_image.distill(state, state.models)
File "./dataset_distillation/dataset-distillation/train_distilled_image.py", line 290, in distill
return Trainer(state, models).train()
File "./dataset_distillation/dataset-distillation/train_distilled_image.py", line 248, in train
self.accumulate_grad(grad_infos)
File "./dataset_distillation/dataset-distillation/train_distilled_image.py", line 176, in accumulate_grad
d.grad.add_(g)
AttributeError: 'NoneType' object has no attribute 'add_'
I request the code authors to kindly have a look at this once and rectify it as per my suggestion if they think this modification looks OK. Thanks.
PS: I would like to mention @jundeli who helped me in figuring out the issue. Thanks to him for that!
@KoustubhPhalak Have you figured out the way to rectify it?
@KoustubhPhalak Have you figured out the way to rectify it?
Hi @karan-kumawat17 , if you replace the code for accumulate_grad() function as I have shown above, it should work. For reference I will attach it here again:
def accumulate_grad(self, grad_infos):
bwd_out = []
bwd_grad = []
for datas, gdatas, lrs, glrs in grad_infos:
bwd_out.extend(lrs)
bwd_grad.extend(glrs)
for d, g in zip(datas, gdatas):
if d.grad is not None:
d.grad.add_(g)
else:
d.grad = g
if bwd_out:
torch.autograd.backward(bwd_out, grad_tensors=bwd_grad)
FYI, I did not update the code, instead, I installed an older version of dependencies, you can check my fork here: https://github.com/kowyo/dataset-distillation/tree/fixed-dep
FYI, I did not update the code, instead, I installed an older version of dependencies, you can check my fork here: https://github.com/kowyo/dataset-distillation/tree/fixed-dep
That makes sense. I would imagine that the code was made on older version of dependencies, and something might have been updated in the dependencies after which the code started throwing error. Shifting back to older versions of these dependencies should also do the trick, rather than modifying code like I have done.
Thanks for sharing @kowyo !
FYI, I did not update the code, instead, I installed an older version of dependencies, you can check my fork here: https://github.com/kowyo/dataset-distillation/tree/fixed-dep
this link doesn't work
I opened a PR https://github.com/ssnl/dataset-distillation/pull/64 and this has been merged into main branch