README.md 1.77 KB
Newer Older
Scarlett Li's avatar
Scarlett Li committed
1
# Define your own Assessor
Deshui Yu's avatar
Deshui Yu committed
2
3
4

*Assessor receive intermediate result from Trial and decide whether the Trial should be killed. Once the Trial experiment meets the early stop conditions, the assessor will kill the Trial.*

5
So, if users want to implement a customized Assessor, they only need to:
Deshui Yu's avatar
Deshui Yu committed
6
7


8
**1) Inherit an assessor of a base Assessor class**
Deshui Yu's avatar
Deshui Yu committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
```python
from nni.assessor import Assessor

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

**2) Implement assess trial function**
```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.
        ...
```
34
**3) Write a script to run Assessor**
Deshui Yu's avatar
Deshui Yu committed
35
36
37
```python
import argparse

Chi Song's avatar
Chi Song committed
38
import CustomizedAssessor
Deshui Yu's avatar
Deshui Yu committed
39
40
41
42
43
44
45
46
47
48
49
50
51

def main():
    parser = argparse.ArgumentParser(description='parse command line parameters.')
    # parse your assessor arg here.
    ...
    FLAGS, unparsed = parser.parse_known_args()

    tuner = CustomizedAssessor(...)
    tuner.run()

main()
```

Chi Song's avatar
Chi Song committed
52
Please noted in 2). The object `trial_history` are exact the object that Trial send to Assessor by using SDK `report_intermediate_result` function.
Deshui Yu's avatar
Deshui Yu committed
53

Chi Song's avatar
Chi Song committed
54
Also, user could override the `run` function in Assessor to control the process logic.
Deshui Yu's avatar
Deshui Yu committed
55
56
57

More detail example you could see:
> * [Base-Assessor](https://msrasrg.visualstudio.com/NeuralNetworkIntelligenceOpenSource/_git/Default?_a=contents&path=%2Fsrc%2Fsdk%2Fpynni%2Fnni%2Fassessor.py&version=GBadd_readme)