carpedm20 / ENAS-pytorch

PyTorch implementation of "Efficient Neural Architecture Search via Parameters Sharing"
Apache License 2.0
2.69k stars 492 forks source link

Can't run the code, SyntaxError: invalid syntax #17

Closed harewei closed 6 years ago

harewei commented 6 years ago

I suppose I'm the only one with this problem, seeing everyone else can actually run the program.

I tried both

python3 main.py --network_type rnn --dataset ptb --controller_optim adam --controller_lr 0.00035 \
               --shared_optim sgd --shared_lr 20.0 --entropy_coeff 0.0001

python3 main.py --network_type rnn --dataset wikitext

but an error comes out with

File "main.py", line 28
    raise NotImplementedError(f"{args.dataset} is not supported")
                                                               ^
SyntaxError: invalid syntax

Does anyone have any idea why? I'm using Ubuntu on Docker, with PyTorch installed (as well as those listed in requirement.txt, except pygraphviz (due to installation error, but this shouldn't raise any errors until it's actually called in utils.py, which I commented out anyway).

beduffy commented 6 years ago

f"{args.dataset} is not supported"

This is Python 3.6+ syntax. Trying removing the f or upgrading your python

harewei commented 6 years ago

@beduffy Thank you, this does indeed resolve the problem (upgrading to Python3.6). Guess I missed out on the Python 3.6+ prerequisites. These is another problem though, when I run the command to train, the following error occurs

2018-04-26 06:21:46,123:INFO::[*] Make directories : logs/ptb_2018-04-26_06-21-46
2018-04-26 06:21:53,140:INFO::regularizing:
2018-04-26 06:22:00,341:INFO::# of parameters: 146,014,000
2018-04-26 06:22:00,447:INFO::[*] MODEL dir: logs/ptb_2018-04-26_06-21-46
2018-04-26 06:22:00,447:INFO::[*] PARAM path: logs/ptb_2018-04-26_06-21-46/params.json
Traceback (most recent call last):
  File "main.py", line 48, in <module>
    main(args)
  File "main.py", line 34, in main
    trnr.train()
  File "/home/username/Projects/ENAS-pytorch/trainer.py", line 216, in train
    self.train_shared()
  File "/home/username/Projects/ENAS-pytorch/trainer.py", line 297, in train_shared
    hidden = utils.detach(hidden)
  File "/home/username/Projects/ENAS-pytorch/utils.py", line 131, in detach
    return tuple(detach(v) for v in h)
  File "/home/username/Projects/ENAS-pytorch/utils.py", line 131, in <genexpr>
    return tuple(detach(v) for v in h)
  File "/home/username/Projects/ENAS-pytorch/utils.py", line 131, in detach
    return tuple(detach(v) for v in h)
  File "/home/username/Projects/ENAS-pytorch/utils.py", line 131, in <genexpr>
    return tuple(detach(v) for v in h)
  File "/home/username/Projects/ENAS-pytorch/utils.py", line 131, in detach
    return tuple(detach(v) for v in h)
  File "/usr/local/lib/python3.6/dist-packages/torch/tensor.py", line 360, in __iter__
    raise TypeError('iteration over a 0-d tensor')
TypeError: iteration over a 0-d tensor
beduffy commented 6 years ago

PyTorch 0.4.0 was released the other day with the addition of 0 dimensional tensors. In general, this will probably break all PyTorch tutorials and code.

I assume because of that error you have 0.4.0 but I could be wrong.

harewei commented 6 years ago

@beduffy That is indeed the issue. The program now runs fine when I use PyTorch 0.3.1 instead of 0.4.0. Thank you.