EnableAssessor.md 2.95 KB
Newer Older
Deshui Yu's avatar
Deshui Yu committed
1
2
3
4
5
**Enable Assessor in your expeirment**
===
Assessor module is for assessing running trials. One common use case is early stopping, which terminates unpromising trial jobs based on their intermediate results.

## Using NNI built-in Assessor
6
Here we use the same example `examples/trials/mnist-annotation`. We use `Medianstop` assessor for this experiment. The yml configure file is shown below:
Deshui Yu's avatar
Deshui Yu committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
```
authorName: your_name
experimentName: auto_mnist
# how many trials could be concurrently running
trialConcurrency: 2
# maximum experiment running duration
maxExecDuration: 3h
# empty means never stop
maxTrialNum: 100
# choice: local, remote  
trainingServicePlatform: local
# choice: true, false  
useAnnotation: true
tuner:
21
22
23
  builtinTunerName: TPE
  classArgs:
    optimize_mode: maximize
Deshui Yu's avatar
Deshui Yu committed
24
assessor:
25
26
27
  builtinAssessorName: Medianstop
  classArgs:
    optimize_mode: maximize
Deshui Yu's avatar
Deshui Yu committed
28
trial:
29
30
31
  command: python mnist.py
  codeDir: /usr/share/nni/examples/trials/mnist-annotation
  gpuNum: 0
Deshui Yu's avatar
Deshui Yu committed
32
```
33
For our built-in assessors, you need to fill two fields: `builtinAssessorName` which chooses NNI provided assessors (refer to [here]() for built-in assessors), `optimize_mode` which includes maximize and minimize (you want to maximize or minimize your trial result).
Deshui Yu's avatar
Deshui Yu committed
34
35

## Using user customized Assessor
36
You can also write your own assessor following the guidance [here](). For example, you wrote an assessor for `examples/trials/mnist-annotation`. You should prepare the yml configure below:
Deshui Yu's avatar
Deshui Yu committed
37
38
39
40
41
42
43
44
45
46
47
48
49
50
```
authorName: your_name
experimentName: auto_mnist
# how many trials could be concurrently running
trialConcurrency: 2
# maximum experiment running duration
maxExecDuration: 3h
# empty means never stop
maxTrialNum: 100
# choice: local, remote  
trainingServicePlatform: local
# choice: true, false  
useAnnotation: true
tuner:
51
52
53
54
  # Possible values: TPE, Random, Anneal, Evolution
  builtinTunerName: TPE
  classArgs:
    optimize_mode: maximize
Deshui Yu's avatar
Deshui Yu committed
55
assessor:
56
57
58
59
60
61
62
63
64
65
66
  # Your assessor code directory
  codeDir: 
  # Name of the file which contains your assessor class
  classFileName: 
  # Your assessor class name, must be a subclass of nni.Assessor
  className: 
  # Parameter names and literal values you want to pass to
  # the __init__ constructor of your assessor class
  classArgs:
    arg1: value1
  gpuNum: 0
Deshui Yu's avatar
Deshui Yu committed
67
trial:
68
69
70
  command: python mnist.py
  codeDir: /usr/share/nni/examples/trials/mnist-annotation
  gpuNum: 0
Deshui Yu's avatar
Deshui Yu committed
71
```
72
You need to fill: `codeDir`, `classFileName`, `className`, and pass parameters to \_\_init__ constructor through `classArgs` field if the \_\_init__ constructor of your assessor class has required parameters.
QuanluZhang's avatar
QuanluZhang committed
73
74
75
76
77
78
79

**Note that** if you want to access a file (e.g., ```data.txt```) in the directory of your own assessor, you cannot use ```open('data.txt', 'r')```. Instead, you should use the following:
```
_pwd = os.path.dirname(__file__)
_fd = open(os.path.join(_pwd, 'data.txt'), 'r')
```
This is because your assessor is not executed in the directory of your assessor (i.e., ```pwd``` is not the directory of your own assessor).