"src/include/vscode:/vscode.git/clone" did not exist on "ba07b221460227e15dd29c3b64f1955652917ba4"
CustomizeAdvisor.md 1.76 KB
Newer Older
QuanluZhang's avatar
QuanluZhang committed
1
2
# **How To** - Customize Your Own Advisor

3
*Warning: API is subject to change in future releases.*
QuanluZhang's avatar
QuanluZhang committed
4

5
Advisor targets the scenario that the automl algorithm wants the methods of both tuner and assessor. Advisor is similar to tuner on that it receives trial parameters request, final results, and generate trial parameters. Also, it is similar to assessor on that it receives intermediate results, trial's end state, and could send trial kill command. Note that, if you use Advisor, tuner and assessor are not allowed to be used at the same time.
QuanluZhang's avatar
QuanluZhang committed
6

7
If a user want to implement a customized Advisor, she/he only needs to:
QuanluZhang's avatar
QuanluZhang committed
8

9
**1. Define an Advisor inheriting from the MsgDispatcherBase class.** For example:
Chi Song's avatar
Chi Song committed
10

QuanluZhang's avatar
QuanluZhang committed
11
12
13
14
15
16
17
18
```python
from nni.msg_dispatcher_base import MsgDispatcherBase

class CustomizedAdvisor(MsgDispatcherBase):
    def __init__(self, ...):
        ...
```

19
**2. Implement the methods with prefix `handle_` except `handle_request`**.. You might find [docs](https://nni.readthedocs.io/en/latest/sdk_reference.html#nni.msg_dispatcher_base.MsgDispatcherBase) for `MsgDispatcherBase` helpful.
QuanluZhang's avatar
QuanluZhang committed
20

21
**3. Configure your customized Advisor in experiment YAML config file.**
QuanluZhang's avatar
QuanluZhang committed
22

23
Similar to tuner and assessor. NNI needs to locate your customized Advisor class and instantiate the class, so you need to specify the location of the customized Advisor class and pass literal values as parameters to the `__init__` constructor.
QuanluZhang's avatar
QuanluZhang committed
24

Yan Ni's avatar
Yan Ni committed
25
```yaml
QuanluZhang's avatar
QuanluZhang committed
26
27
28
29
30
advisor:
  codeDir: /home/abc/myadvisor
  classFileName: my_customized_advisor.py
  className: CustomizedAdvisor
  # Any parameter need to pass to your advisor class __init__ constructor
31
  # can be specified in this optional classArgs field, for example
QuanluZhang's avatar
QuanluZhang committed
32
33
34
  classArgs:
    arg1: value1
```
35
36
37
38

## Example

Here we provide an [example](../../../examples/tuners/mnist_keras_customized_advisor).