trainingService.ts 3.8 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

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

chicm-ms's avatar
chicm-ms committed
32
33
34
35
36
interface HyperParameters {
    readonly value: string;
    readonly index: number;
}

Deshui Yu's avatar
Deshui Yu committed
37
38
39
/**
 * define TrialJobApplicationForm
 */
40
41
interface TrialJobApplicationForm {
    readonly sequenceId: number;
chicm-ms's avatar
chicm-ms committed
42
    readonly hyperParameters: HyperParameters;
Deshui Yu's avatar
Deshui Yu committed
43
44
45
46
47
48
49
50
}

/**
 * define TrialJobDetail
 */
interface TrialJobDetail {
    readonly id: string;
    readonly status: TrialJobStatus;
51
52
53
    readonly submitTime: number;
    readonly startTime?: number;
    readonly endTime?: number;
Deshui Yu's avatar
Deshui Yu committed
54
55
56
    readonly tags?: string[];
    readonly url?: string;
    readonly workingDirectory: string;
57
    readonly form: TrialJobApplicationForm;
58
    isEarlyStopped?: boolean;
Deshui Yu's avatar
Deshui Yu committed
59
60
61
62
63
64
65
66
67
68
69
70
71
72
}

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

/**
 * define TrainingServiceError
 */
class TrainingServiceError extends Error {
73

Deshui Yu's avatar
Deshui Yu committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    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;
94
95
    public abstract submitTrialJob(form: TrialJobApplicationForm): Promise<TrialJobDetail>;
    public abstract updateTrialJob(trialJobId: string, form: TrialJobApplicationForm): Promise<TrialJobDetail>;
96
    public abstract get isMultiPhaseJobSupported(): boolean;
QuanluZhang's avatar
QuanluZhang committed
97
    public abstract cancelTrialJob(trialJobId: string, isEarlyStopped?: boolean): Promise<void>;
Deshui Yu's avatar
Deshui Yu committed
98
99
100
101
102
103
    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>;
}

104
105
106
107
108
109
110
111
112
113
/**
 * the ip of nni manager
 */
class NNIManagerIpConfig {
    public readonly nniManagerIp: string;
    constructor(nniManagerIp: string){
        this.nniManagerIp = nniManagerIp;
    }
}

Deshui Yu's avatar
Deshui Yu committed
114
115
export {
    TrainingService, TrainingServiceError, TrialJobStatus, TrialJobApplicationForm,
chicm-ms's avatar
chicm-ms committed
116
    TrainingServiceMetadata, TrialJobDetail, TrialJobMetric, HyperParameters,
117
    NNIManagerIpConfig
Deshui Yu's avatar
Deshui Yu committed
118
};