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.05k stars 1.82k forks source link

Encounter ModuleNotFoundError when run Darts from Example #5329

Closed YichaoCode closed 1 year ago

YichaoCode commented 1 year ago

Describe the issue:

Encounter ModuleNotFoundError when run Darts Demo code from Example folders (/examples/nas/oneshot/darts/search.py)

Environment:

Configuration:

Log message:

root@Ubuntu:~/home/nni_repo/nni/examples/nas/oneshot/darts$ python search.py
Traceback (most recent call last):
  File "~/home/nni_repo/nni/examples/nas/oneshot/darts/search.py", line 14, in <module>
    from nni.nas.pytorch.callbacks import ArchitectureCheckpoint, LRSchedulerCallback
ModuleNotFoundError: No module named 'nni.nas.pytorch'

How to reproduce it?: Run the original code without making any changes

matluster commented 1 year ago

Please use nni/examples/tutorials/darts.py. The examples in nas/oneshot should've been removed.

YichaoCode commented 1 year ago

Thanks for your reply.

When I try to run the code in nni/examples/tutorials/darts.py , I encountered another issue.

/home/root/anaconda3/envs/nas_dev/bin/python /home/root/nas_dev/nni_repo/nni/examples/tutorials/darts.py 
Files already downloaded and verified
[2023-02-01 18:40:22] "/home/root/.cache/nni/nashub/darts-v2-5465b0d2.pth" already exists. Checking hash.
Accuracy: 0.9737
Files already downloaded and verified
Traceback (most recent call last):
  File "/home/root/nas_dev/nni_repo/nni/examples/tutorials/darts.py", line 219, in <module>
    evaluator = Classification(
  File "/home/root/anaconda3/envs/nas_dev/lib/python3.10/site-packages/nni/nas/evaluator/pytorch/lightning.py", line 371, in __init__
    module = ClassificationModule(criterion=criterion, learning_rate=learning_rate,
  File "/home/root/anaconda3/envs/nas_dev/lib/python3.10/site-packages/nni/common/serializer.py", line 508, in __init__
    super().__init__(symbol=base, args=args, kwargs=kwargs, call_super=call_super)
  File "/home/root/anaconda3/envs/nas_dev/lib/python3.10/site-packages/nni/common/serializer.py", line 133, in __init__
    super().__init__(
  File "/home/root/anaconda3/envs/nas_dev/lib/python3.10/site-packages/nni/nas/evaluator/pytorch/lightning.py", line 308, in __init__
    super().__init__(criterion, {'acc': AccuracyWithLogits},
  File "/home/root/anaconda3/envs/nas_dev/lib/python3.10/site-packages/nni/nas/evaluator/pytorch/lightning.py", line 224, in __init__
    self.metrics = nn.ModuleDict({name: cls() for name, cls in metrics.items()})
  File "/home/root/anaconda3/envs/nas_dev/lib/python3.10/site-packages/nni/nas/evaluator/pytorch/lightning.py", line 224, in <dictcomp>
    self.metrics = nn.ModuleDict({name: cls() for name, cls in metrics.items()})
TypeError: Accuracy.__new__() missing 1 required positional argument: 'task'

Process finished with exit code 1

Which step is wrong?

ultmaster commented 1 year ago

Your torchmetrics is too new. Try to downgrade it.

YichaoCode commented 1 year ago

I am using torchmetric version 0.11.0 Is there a recommended version of torchmetric? And is there a recommended environment for running this code, such as a pytorch version, etc.?

ultmaster commented 1 year ago

0.10

Latest version is supported via #5256

Lijiaoa commented 1 year ago

hi @YatchiuLau It looks like the issue had been resolved. Could you help close this issue?