forked from microsoft/nni
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadlTrainingService.test.ts
138 lines (127 loc) · 4.48 KB
/
adlTrainingService.test.ts
1
2
3
4
5
6
7
8
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
'use strict';
import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as fs from 'fs';
import * as tmp from 'tmp';
import * as component from '../../common/component';
import { TrialJobApplicationForm, TrialJobDetail, TrainingService } from '../../common/trainingService';
import { cleanupUnitTest, prepareUnitTest } from '../../common/utils';
import { TrialConfigMetadataKey } from '../common/trialConfigMetadataKey';
import { AdlTrainingService } from '../kubernetes/adl/adlTrainingService';
const localCodeDir: string = tmp.dirSync().name
describe('Unit Test for AdlTrainingService', () => {
let skip: boolean = false;
try {
const testKubeflowConfig = fs.readFileSync('/home/vsts/.kube/config', 'utf8');
} catch (err) {
console.log('Please have kubernetes cluster to enable its training service unit test.');
skip = true;
}
let testAdlTrialConfig: any = JSON.stringify({
"command": "python3 /root/apps/nni_linear_regression/main.py",
"codeDir": ".",
"gpuNum": 0,
"image": "test.image:latest",
"imagePullSecrets": [
{
"name": "stagingsecrets"
}
],
"nfs": {
"server": "172.20.188.236",
"path": "/exports",
"containerMountPath": "/nfs"
},
"memorySize": "1Gi",
"cpuNum": 1
});
let testAdlTrialConfig2: any = JSON.stringify({
"command": "python3 /root/apps/nni_linear_regression/main.py",
"codeDir": ".",
"gpuNum": 0,
"image": "test.image:latest",
"imagePullSecrets": [
{
"name": "stagingsecrets"
}
],
"adaptive": true,
"checkpoint": {
"storageClass": "aws-efs",
"storageSize": "1Gi"
},
"nfs": {
"server": "172.20.188.236",
"path": "/exports",
"containerMountPath": "/nfs"
}
});
let testNniManagerIp: any = JSON.stringify({
"nniManagerIp": "0.0.0.0"
});
let adlTrainingService: AdlTrainingService;
console.log(tmp.dirSync().name);
before(() => {
chai.should();
chai.use(chaiAsPromised);
prepareUnitTest();
});
after(() => {
cleanupUnitTest();
});
beforeEach(() => {
if (skip) {
return;
}
adlTrainingService = component.get(AdlTrainingService);
adlTrainingService.run()
});
afterEach(() => {
if (skip) {
return;
}
adlTrainingService.cleanUp();
});
it('Set and get cluster metadata', async () => {
if (skip) {
return;
}
await adlTrainingService.setClusterMetadata(TrialConfigMetadataKey.TRIAL_CONFIG, testAdlTrialConfig2);
await adlTrainingService.setClusterMetadata(TrialConfigMetadataKey.NNI_MANAGER_IP, testNniManagerIp);
let data:string = await adlTrainingService.getClusterMetadata(TrialConfigMetadataKey.TRIAL_CONFIG);
chai.expect(data).to.be.equals(testAdlTrialConfig2);
});
it('Submit job', async () => {
if (skip) {
return;
}
// job without given checkpoint, with resource config
await adlTrainingService.setClusterMetadata(TrialConfigMetadataKey.TRIAL_CONFIG, testAdlTrialConfig);
let form: TrialJobApplicationForm = {
sequenceId: 0,
hyperParameters: {
value: 'mock hyperparameters',
index: 0
}
};
let jobDetail: TrialJobDetail = await adlTrainingService.submitTrialJob(form);
chai.expect(jobDetail.status).to.be.equals('WAITING');
await adlTrainingService.cancelTrialJob(jobDetail.id);
chai.expect(jobDetail.status).to.be.equals('USER_CANCELED');
// job with given checkpoint
await adlTrainingService.setClusterMetadata(TrialConfigMetadataKey.TRIAL_CONFIG, testAdlTrialConfig2);
form = {
sequenceId: 0,
hyperParameters: {
value: 'mock hyperparameters',
index: 0
}
};
jobDetail = await adlTrainingService.submitTrialJob(form);
chai.expect(jobDetail.status).to.be.equals('WAITING');
await adlTrainingService.cancelTrialJob(jobDetail.id);
chai.expect(jobDetail.status).to.be.equals('USER_CANCELED');
}).timeout(3000000);
});