"...targets/git@developer.sourcefind.cn:gaoqiong/migraphx.git" did not exist on "4fda0214679f65a944517f251f49679d4fc565cd"
CustomizeAssessor.md 1.91 KB
Newer Older
Yan Ni's avatar
Yan Ni committed
1
2
# Customize Assessor

Chi Song's avatar
Chi Song committed
3
NNI supports to build an assessor by yourself for tuning demand.
Yan Ni's avatar
Yan Ni committed
4

Chi Song's avatar
Chi Song committed
5
If you want to implement a customized Assessor, there are three things to do:
Yan Ni's avatar
Yan Ni committed
6

Chi Song's avatar
Chi Song committed
7
8
9
1. Inherit the base Assessor class
1. Implement assess_trial function
1. Configure your customized Assessor in experiment YAML config file
Yan Ni's avatar
Yan Ni committed
10

Chi Song's avatar
Chi Song committed
11
**1. Inherit the base Assessor class**
Yan Ni's avatar
Yan Ni committed
12
13
14
15
16
17
18
19
20
21

```python
from nni.assessor import Assessor

class CustomizedAssessor(Assessor):
    def __init__(self, ...):
        ...
```

**2. Implement assess trial function**
Chi Song's avatar
Chi Song committed
22

Yan Ni's avatar
Yan Ni committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
```python
from nni.assessor import Assessor, AssessResult

class CustomizedAssessor(Assessor):
    def __init__(self, ...):
        ...

    def assess_trial(self, trial_history):
        """
        Determines whether a trial should be killed. Must override.
        trial_history: a list of intermediate result objects.
        Returns AssessResult.Good or AssessResult.Bad.
        """
        # you code implement here.
        ...
```

40
**3. Configure your customized Assessor in experiment YAML config file**
Yan Ni's avatar
Yan Ni committed
41
42
43

NNI needs to locate your customized Assessor class and instantiate the class, so you need to specify the location of the customized Assessor class and pass literal values as parameters to the \_\_init__ constructor.

Yan Ni's avatar
Yan Ni committed
44
```yaml
Yan Ni's avatar
Yan Ni committed
45
46
47
48
49
assessor:
  codeDir: /home/abc/myassessor
  classFileName: my_customized_assessor.py
  className: CustomizedAssessor
  # Any parameter need to pass to your Assessor class __init__ constructor
50
  # can be specified in this optional classArgs field, for example
Yan Ni's avatar
Yan Ni committed
51
52
53
54
55
56
57
  classArgs:
    arg1: value1
```

Please noted in **2**. The object `trial_history` are exact the object that Trial send to Assessor by using SDK `report_intermediate_result` function.

More detail example you could see:
Yan Ni's avatar
Yan Ni committed
58
59
> * [medianstop-assessor](https://github.com/Microsoft/nni/tree/master/src/sdk/pynni/nni/medianstop_assessor)
> * [curvefitting-assessor](https://github.com/Microsoft/nni/tree/master/src/sdk/pynni/nni/curvefitting_assessor)