howto_3_CustomizedAdvisor.md 1.87 KB
Newer Older
QuanluZhang's avatar
QuanluZhang committed
1
2
# **How To** - Customize Your Own Advisor

Chi Song's avatar
Chi Song committed
3
*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
4
5
6

So, if user want to implement a customized Advisor, she/he only need to:

Chi Song's avatar
Chi Song committed
7
8
9
1. Define an Advisor inheriting from the MsgDispatcherBase class
1. Implement the methods with prefix `handle_` except `handle_request`
1. Configure your customized Advisor in experiment yaml config file
QuanluZhang's avatar
QuanluZhang committed
10

Chi Song's avatar
Chi Song committed
11
Here is an example:
QuanluZhang's avatar
QuanluZhang committed
12
13

**1) Define an Advisor inheriting from the MsgDispatcherBase class**
Chi Song's avatar
Chi Song committed
14

QuanluZhang's avatar
QuanluZhang committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
```python
from nni.msg_dispatcher_base import MsgDispatcherBase

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

**2) Implement the methods with prefix `handle_` except `handle_request`**

Please refer to the implementation of Hyperband ([src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py](../src/sdk/pynni/nni/hyperband_advisor/hyperband_advisor.py)) for how to implement the methods.

**3) Configure your customized Advisor in experiment yaml config file**

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.

```yaml
advisor:
  codeDir: /home/abc/myadvisor
  classFileName: my_customized_advisor.py
  className: CustomizedAdvisor
  # Any parameter need to pass to your advisor class __init__ constructor
  # can be specified in this optional classArgs field, for example 
  classArgs:
    arg1: value1
```