trainingService.ts 4.23 KB
Newer Older
Deshui Yu's avatar
Deshui Yu committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
 * Copyright (c) Microsoft Corporation
 * All rights reserved.
 *
 * MIT License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

'use strict';

/**
 * define TrialJobStatus
 */
QuanluZhang's avatar
QuanluZhang committed
25
type TrialJobStatus = 'UNKNOWN' | 'WAITING' | 'RUNNING' | 'SUCCEEDED' | 'FAILED' | 'USER_CANCELED' | 'SYS_CANCELED' | 'EARLY_STOPPED';
Deshui Yu's avatar
Deshui Yu committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
type JobType = 'TRIAL' | 'HOST';

interface TrainingServiceMetadata {
    readonly key: string;
    readonly value: string;
}

/**
 * define JobApplicationForm
 */
interface JobApplicationForm {
    readonly jobType: JobType;
}

chicm-ms's avatar
chicm-ms committed
40
41
42
43
44
interface HyperParameters {
    readonly value: string;
    readonly index: number;
}

Deshui Yu's avatar
Deshui Yu committed
45
46
47
48
/**
 * define TrialJobApplicationForm
 */
interface TrialJobApplicationForm extends JobApplicationForm {
chicm-ms's avatar
chicm-ms committed
49
    readonly hyperParameters: HyperParameters;
Deshui Yu's avatar
Deshui Yu committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
}

/**
 * define HostJobApplicationForm
 */
interface HostJobApplicationForm extends JobApplicationForm {
    readonly host: string;
    readonly cmd: string;
}

/**
 * define TrialJobDetail
 */
interface TrialJobDetail {
    readonly id: string;
    readonly status: TrialJobStatus;
66
67
68
    readonly submitTime: number;
    readonly startTime?: number;
    readonly endTime?: number;
Deshui Yu's avatar
Deshui Yu committed
69
70
71
72
    readonly tags?: string[];
    readonly url?: string;
    readonly workingDirectory: string;
    readonly form: JobApplicationForm;
73
    readonly sequenceId: number;
74
    isEarlyStopped?: boolean;
Deshui Yu's avatar
Deshui Yu committed
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
}

interface HostJobDetail {
    readonly id: string;
    readonly status: string;
}

/**
 * define TrialJobMetric
 */
interface TrialJobMetric {
    readonly id: string;
    readonly data: string;
}

/**
 * define TrainingServiceError
 */
class TrainingServiceError extends Error {
    private errCode: number;

    constructor(errorCode: number, errorMessage: string) {
        super(errorMessage);
        this.errCode = errorCode;
    }

    get errorCode(): number {
        return this.errCode;
    }
}

/**
 * define TrainingService
 */
abstract class TrainingService {
    public abstract listTrialJobs(): Promise<TrialJobDetail[]>;
    public abstract getTrialJob(trialJobId: string): Promise<TrialJobDetail>;
    public abstract addTrialJobMetricListener(listener: (metric: TrialJobMetric) => void): void;
    public abstract removeTrialJobMetricListener(listener: (metric: TrialJobMetric) => void): void;
    public abstract submitTrialJob(form: JobApplicationForm): Promise<TrialJobDetail>;
115
116
    public abstract updateTrialJob(trialJobId: string, form: JobApplicationForm): Promise<TrialJobDetail>;
    public abstract get isMultiPhaseJobSupported(): boolean;
QuanluZhang's avatar
QuanluZhang committed
117
    public abstract cancelTrialJob(trialJobId: string, isEarlyStopped?: boolean): Promise<void>;
Deshui Yu's avatar
Deshui Yu committed
118
119
120
121
122
123
    public abstract setClusterMetadata(key: string, value: string): Promise<void>;
    public abstract getClusterMetadata(key: string): Promise<string>;
    public abstract cleanUp(): Promise<void>;
    public abstract run(): Promise<void>;
}

124
125
126
127
128
129
130
131
132
133
/**
 * the ip of nni manager
 */
class NNIManagerIpConfig {
    public readonly nniManagerIp: string;
    constructor(nniManagerIp: string){
        this.nniManagerIp = nniManagerIp;
    }
}

Deshui Yu's avatar
Deshui Yu committed
134
135
export {
    TrainingService, TrainingServiceError, TrialJobStatus, TrialJobApplicationForm,
chicm-ms's avatar
chicm-ms committed
136
    TrainingServiceMetadata, TrialJobDetail, TrialJobMetric, HyperParameters,
137
    HostJobApplicationForm, JobApplicationForm, JobType, NNIManagerIpConfig
Deshui Yu's avatar
Deshui Yu committed
138
};
139
140