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.02k stars 1.81k forks source link

failed to use annotation #4519

Closed bl6g6 closed 2 years ago

bl6g6 commented 2 years ago

I am using docker on remote mode. I used

python3 -m pip install --upgrade pip setuptools
python3 setup.py develop

to install environment. When I am in v2.6 branch, I used nnictl --version , it shows 999.dev0. Then I ran mnist-annotation example, the following error message displayed:

root@c30d89d3f9c9:/app/nni/nni-2.6# nnictl create --config examples/trials/mnist-annotation/config.yml -p 8880
Traceback (most recent call last):
  File "/app/nni/nni-2.6/nni/tools/annotation/__init__.py", line 112, in _expand_file_annotations
    annotated_code = code_generator.parse(src.read(), nas_mode)
  File "/usr/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 707: ordinal not in range(128)

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/usr/local/bin/nnictl", line 8, in <module>
    sys.exit(parse_args())
  File "/app/nni/nni-2.6/nni/tools/nnictl/nnictl.py", line 286, in parse_args
    args.func(args)
  File "/app/nni/nni-2.6/nni/tools/nnictl/launcher.py", line 83, in create_experiment
    code_dir = expand_annotations(config.trial_code_directory, path)
  File "/app/nni/nni-2.6/nni/tools/annotation/__init__.py", line 97, in expand_annotations
    annotated |= _expand_file_annotations(src_path, dst_path, nas_mode)
  File "/app/nni/nni-2.6/nni/tools/annotation/__init__.py", line 121, in _expand_file_annotations
    raise RuntimeError(src_path + ' ' + '\n'.join(str(arg) for arg in exc.args))
RuntimeError: ./test/ut/sdk/test_protocol.py ascii
b"# Copyright (c) Microsoft Corporation.\n# Licensed under the MIT license.\n\nfrom nni.runtime import protocol\nfrom nni.runtime.protocol import CommandType, send, receive\n\nfrom io import BytesIO\nfrom unittest import TestCase, main\n\n\ndef _prepare_send():\n    protocol._out_file = BytesIO()\n    return protocol._out_file\n\ndef _prepare_receive(data):\n    protocol._in_file = BytesIO(data)\n\n\nclass ProtocolTestCase(TestCase):\n    def test_send_en(self):\n        out_file = _prepare_send()\n        send(CommandType.NewTrialJob, 'CONTENT')\n        self.assertEqual(out_file.getvalue(), b'TR00000000000007CONTENT')\n\n    def test_send_zh(self):\n        out_file = _prepare_send()\n        send(CommandType.NewTrialJob, '\xe4\xbd\xa0\xe5\xa5\xbd')\n        self.assertEqual(out_file.getvalue(), 'TR00000000000006\xe4\xbd\xa0\xe5\xa5\xbd'.encode('utf8'))\n\n    def test_receive_en(self):\n        _prepare_receive(b'IN00000000000005hello')\n        command, data = receive()\n        self.assertIs(command, CommandType.Initialize)\n        self.assertEqual(data, 'hello')\n\n    def test_receive_zh(self):\n        _prepare_receive('IN00000000000006\xe4\xb8\x96\xe7\x95\x8c'.encode('utf8'))\n        command, data = receive()\n        self.assertIs(command, CommandType.Initialize)\n        self.assertEqual(data, '\xe4\xb8\x96\xe7\x95\x8c')\n\n\nif __name__ == '__main__':\n    main()\n"
707
708
ordinal not in range(128)

WhenI switched to v2.5 and ran mnist-annotation, the following error displayed:

'Module' object has no attribute 'last_line'

Is this a bug or is the way I installed it not correct? Did anyone meet the same issue?

Moreover, I have a tiny question about Assessor-curve-fitting. The epoch_num parameter is the epoch number of total training, correct? Since larger epoch_num than training epoch still works.

QuanluZhang commented 2 years ago

@bl6g6 thanks for reporting this issue. do you encounter the same error when using local mode with v2.6? or the error only occurs in remote mode?

For your second question about assessor, epoch_num means the total epoch number, the curve-fitting assessor will predict trial's performance on this epoch. It is not supposed to set a number larger than total epoch number (though this assessor still works, it will predict the performance on your specified epoch number by assuming the trial will run such many of epochs).

bl6g6 commented 2 years ago

I was using local mode with V2.5 nni on my local machine(ubuntu18). The error was

'Module' object has no attribute 'last_line'

I cannot updated to v2.6 since when I switched to v2.6 branch and ran

python3 -m pip install --upgrade pip setuptools
python3 setup.py develop

it shows

running develop
error: [Errno 17] File exists: 'nni_node'

And thanks for your answer about assessor!

QuanluZhang commented 2 years ago

To resolve the error File exists: 'nni_node', you should first uninstall the old version, then run python3 setup.py clean --all, then install the new version again. it should work.

bl6g6 commented 2 years ago

I updated to v2.6 and found that it was the problem of loading mnist data(my TensorFlow version was so high that cannot locate mnist dataset by default code). Both local and remote could use annotation perfectly. Thank you!