microsoft / nni

An open source AutoML toolkit for automate machine learning lifecycle, including feature engineering, neural architecture search, model compression and hyper-parameter tuning.
https://nni.readthedocs.io
MIT License
14.07k stars 1.82k forks source link

Replace view with reshape #3982

Closed skeletondyh closed 3 years ago

skeletondyh commented 3 years ago

Describe the issue:

I ran the darts example. When I computed top5 acc, line 19 in nni/examples/nas/oneshot/darts/utils.py raised RuntimeError:

view size is not compatible with input tensor's size and stride...

It seems after topk (line 9) and transpose (line 10) the tensor becomes non-contiguous and thus view method meets problem. This issue seems to happen with newer versions of PyTorch (1.7+) and I suggest that we replace all view with reshape in implementation. Reshape would be the same as view if the tensor is contiguous, otherwise it would return a copy

Environment:

ultmaster commented 3 years ago

I think it has already been done in master.