-
Notifications
You must be signed in to change notification settings - Fork 1.8k
update nnicli #2713
update nnicli #2713
Conversation
docs/en_US/nnicli_ref.md
Outdated
|
||
nc.start_experiment('nni/examples/trials/mnist-pytorch/config.yml', port=9090) # start an experiment | ||
|
||
nc.set_endpoint('http://localhost:9090') # set the experiment's endpoint, i.e., the url of Web UI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is this API used for? after an experiment is created, the endpoint is fixed, right? why we need to set it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i see, need to set this endpoint in order to query restful APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to automatically detect this endpoint? because it is counter intuitive that user is required to set endpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with you. Maybe we can get the endpoint when user use start_experiment
. But if user wants to conduct some operation on other experiments, they still need to set the endpoint by their own.
docs/en_US/nnicli_ref.md
Outdated
@@ -0,0 +1,41 @@ | |||
# NNI Client | |||
|
|||
NNI client is a python API of `nnictl`, which implements the most common used commands. Users can use this API to control their experiments, collect experiment results and conduct advanced analyses based on experiment results in python code directly instead of using command line. Here is an example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
common used -> commonly used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@JunweiSUN this pr looks good. we can schedule a quick meeting to see how to further improve nnicli |
@QuanluZhang Sure. I'll make arrangements for this. |
src/sdk/pycli/nnicli/nni_client.py
Outdated
if _create_process(cmd) != 0: | ||
raise RuntimeError('Failed to start experiment, please check your config.') | ||
else: | ||
if port: | ||
self.port = port | ||
else: | ||
self.port = 8080 | ||
self.endpoint = 'http://localhost:{}'.format(self.port) | ||
self.exp_id = self.get_experiment_profile()['id'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to put this part into a dedicated private member function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a new private function _exec_command
tools/nni_cmd/updater.py
Outdated
@@ -14,7 +14,7 @@ | |||
def validate_digit(value, start, end): | |||
'''validate if a digit is valid''' | |||
if not str(value).isdigit() or int(value) < start or int(value) > end: | |||
raise ValueError('%s must be a digit from %s to %s' % (value, start, end)) | |||
raise ValueError('%s must be a digit from %s to %s' % ('value', start, end)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is strange that you add quote on value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there used to be a typo here. If the value is 1, it's strange to raise a error like ValueError('1 must be a digit from 1 to 1000' % (value, start, end)). Instead, it should be ValueError('value must be a digit from 1 to 1000' % (value, start, end))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then it should be raise ValueError('value must be a digit from %s to %s' % (start, end))
. i still suggest the following:
raise ValueError('value (%s) must be a digit from %s to %s' % (value, start, end))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Goog idea. Will fix.
test/config/integration_tests.yml
Outdated
@@ -135,17 +135,6 @@ testCases: | |||
validator: | |||
class: ExportValidator | |||
|
|||
- name: nnicli |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove all the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used to think that it is difficult to split the test to launchCommand
and stopCommand
since we use an instance to handle an experiment. Maybe I could connect to an existing experiment in stopCommand
. Will add the tests again.
@JunweiSUN this pr looks good now, please resolve the comments. |
src/sdk/pycli/nnicli/nni_client.py
Outdated
hyper parameters for this trial | ||
value: | ||
final result | ||
id: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the relation between this id and trialJobId
in NNITrialMetricData
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I follow the keys defined in the api, here they should be same value.
src/sdk/pycli/nnicli/nni_client.py
Outdated
|
||
Attributes | ||
---------- | ||
parameter: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add type for attributes and parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is the relation between parameter
and NNITrialHyperParameters
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parameter
in TrialResult
is the same as parameters
in TrialHyperParameters
docs/en_US/nnicli_ref.md
Outdated
NNI client is a python API of `nnictl`, which implements the most commonly used commands. Users can use this API to control their experiments, collect experiment results and conduct advanced analyses based on experiment results in python code directly instead of using command line. Here is an example: | ||
|
||
``` | ||
from nnicli import NNIExperiment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer Experiment
instead of NNIExperiment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. Will change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.
src/sdk/pycli/nnicli/nni_client.py
Outdated
|
||
Attributes | ||
---------- | ||
parameter: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add types for attributes and parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
src/sdk/pycli/nnicli/nni_client.py
Outdated
self.sequence = None | ||
self.data = None | ||
for key in json_obj.keys(): | ||
self.__setattr__(key, json_obj[key]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setattr(self, key,
self.startTime, self.endTime, self.finalMetricData, self.stderrPath) | ||
|
||
class NNIExperiment: | ||
def __init__(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest ban this __init__
method and implement several class methods including start_experiment
, from_existing_experiment
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not suggest to use class methods, member function is enough, which is simpler
cmd += '--port {}'.format(port).split(' ') | ||
if debug: | ||
cmd += ['--debug'] | ||
self._exec_command(cmd, port) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better if this is a classmethod that creates and returns a new experiment object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is okay to write in this way :)
src/sdk/pycli/nnicli/nni_client.py
Outdated
|
||
class NNIExperiment: | ||
def __init__(self): | ||
self.endpoint = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
endpoint, port, exp_id should be properties that does not allow external modification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
src/sdk/pycli/nnicli/nni_client.py
Outdated
parameter index | ||
""" | ||
def __init__(self, json_obj): | ||
self.id = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these all should be properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should allow users to modify these "data".
src/sdk/pycli/nnicli/nni_client.py
Outdated
self.finalMetricData = None | ||
self.stderrPath = None | ||
for key in json_obj.keys(): | ||
self.__setattr__(key, json_obj[key]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check hasattr(self, key)
before setattr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
@@ -110,8 +110,8 @@ testCases: | |||
config: | |||
maxTrialNum: 4 | |||
trialConcurrency: 4 | |||
launchCommand: python3 -c 'import nnicli as nc; nc.start_nni("$configFile")' | |||
stopCommand: python3 -c 'import nnicli as nc; nc.stop_nni()' | |||
launchCommand: python3 -c 'from nnicli import NNIExperiment; exp = NNIExperiment(); exp.start_experiment("$configFile")' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nnicli.Experiment.start_experiment(...)
preferred.
launchCommand: python3 -c 'import nnicli as nc; nc.start_nni("$configFile")' | ||
stopCommand: python3 -c 'import nnicli as nc; nc.stop_nni()' | ||
launchCommand: python3 -c 'from nnicli import NNIExperiment; exp = NNIExperiment(); exp.start_experiment("$configFile")' | ||
stopCommand: python3 -c 'from nnicli import NNIExperiment; exp = NNIExperiment(); exp.connect_experiment("http://localhost:8080/"); exp.stop_experiment()' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nnicli.Experiment.from_existing_experiment(...).stop()
preferred.
|
test/nni_test/nnitest/validators.py
Outdated
exp.connect_experiment(rest_endpoint) | ||
print(exp.get_job_statistics()) | ||
print(exp.get_experiment_status()) | ||
print(exp.list_trial_jobs()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing end of line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
(cherry picked from commit f82ef62)
update nnicli with more flexibility. Add nnicli docs