Unverified Commit 382e2761 authored by Guoxin's avatar Guoxin Committed by GitHub
Browse files

Merge pull request #1353 from suiguoxin/get_id

issue #1331
parents a5fa2351 14d16cc3
...@@ -8,6 +8,8 @@ Trial ...@@ -8,6 +8,8 @@ Trial
.. autofunction:: nni.get_current_parameter .. autofunction:: nni.get_current_parameter
.. autofunction:: nni.report_intermediate_result .. autofunction:: nni.report_intermediate_result
.. autofunction:: nni.report_final_result .. autofunction:: nni.report_final_result
.. autofunction:: nni.get_experiment_id
.. autofunction:: nni.get_trial_id
.. autofunction:: nni.get_sequence_id .. autofunction:: nni.get_sequence_id
......
...@@ -26,7 +26,7 @@ import * as path from 'path'; ...@@ -26,7 +26,7 @@ import * as path from 'path';
import * as ts from 'tail-stream'; import * as ts from 'tail-stream';
import * as tkill from 'tree-kill'; import * as tkill from 'tree-kill';
import { NNIError, NNIErrorNames } from '../../common/errors'; import { NNIError, NNIErrorNames } from '../../common/errors';
import { getInitTrialSequenceId } from '../../common/experimentStartupInfo'; import { getExperimentId, getInitTrialSequenceId } from '../../common/experimentStartupInfo';
import { getLogger, Logger } from '../../common/log'; import { getLogger, Logger } from '../../common/log';
import { import {
HostJobApplicationForm, HyperParameters, JobApplicationForm, TrainingService, TrialJobApplicationForm, HostJobApplicationForm, HyperParameters, JobApplicationForm, TrainingService, TrialJobApplicationForm,
...@@ -126,6 +126,7 @@ class LocalTrainingService implements TrainingService { ...@@ -126,6 +126,7 @@ class LocalTrainingService implements TrainingService {
private stopping: boolean; private stopping: boolean;
private rootDir!: string; private rootDir!: string;
private trialSequenceId: number; private trialSequenceId: number;
private readonly experimentId! : string;
private gpuScheduler!: GPUScheduler; private gpuScheduler!: GPUScheduler;
private readonly occupiedGpuIndexNumMap: Map<number, number>; private readonly occupiedGpuIndexNumMap: Map<number, number>;
private designatedGpuIndices!: Set<number>; private designatedGpuIndices!: Set<number>;
...@@ -145,6 +146,7 @@ class LocalTrainingService implements TrainingService { ...@@ -145,6 +146,7 @@ class LocalTrainingService implements TrainingService {
this.stopping = false; this.stopping = false;
this.log = getLogger(); this.log = getLogger();
this.trialSequenceId = -1; this.trialSequenceId = -1;
this.experimentId = getExperimentId();
this.jobStreamMap = new Map<string, ts.Stream>(); this.jobStreamMap = new Map<string, ts.Stream>();
this.log.info('Construct local machine training service.'); this.log.info('Construct local machine training service.');
this.occupiedGpuIndexNumMap = new Map<number, number>(); this.occupiedGpuIndexNumMap = new Map<number, number>();
...@@ -400,6 +402,7 @@ class LocalTrainingService implements TrainingService { ...@@ -400,6 +402,7 @@ class LocalTrainingService implements TrainingService {
resource: { gpuIndices: number[] }): { key: string; value: string }[] { resource: { gpuIndices: number[] }): { key: string; value: string }[] {
const envVariables: { key: string; value: string }[] = [ const envVariables: { key: string; value: string }[] = [
{ key: 'NNI_PLATFORM', value: 'local' }, { key: 'NNI_PLATFORM', value: 'local' },
{ key: 'NNI_EXP_ID', value: this.experimentId },
{ key: 'NNI_SYS_DIR', value: trialJobDetail.workingDirectory }, { key: 'NNI_SYS_DIR', value: trialJobDetail.workingDirectory },
{ key: 'NNI_TRIAL_JOB_ID', value: trialJobDetail.id }, { key: 'NNI_TRIAL_JOB_ID', value: trialJobDetail.id },
{ key: 'NNI_OUTPUT_DIR', value: trialJobDetail.workingDirectory }, { key: 'NNI_OUTPUT_DIR', value: trialJobDetail.workingDirectory },
......
...@@ -24,6 +24,7 @@ from collections import namedtuple ...@@ -24,6 +24,7 @@ from collections import namedtuple
_trial_env_var_names = [ _trial_env_var_names = [
'NNI_PLATFORM', 'NNI_PLATFORM',
'NNI_EXP_ID',
'NNI_TRIAL_JOB_ID', 'NNI_TRIAL_JOB_ID',
'NNI_SYS_DIR', 'NNI_SYS_DIR',
'NNI_OUTPUT_DIR', 'NNI_OUTPUT_DIR',
......
...@@ -94,5 +94,11 @@ def send_metric(string): ...@@ -94,5 +94,11 @@ def send_metric(string):
else: else:
subprocess.run(['touch', _metric_file.name], check = True) subprocess.run(['touch', _metric_file.name], check = True)
def get_experiment_id():
return trial_env_vars.NNI_EXP_ID
def get_trial_id():
return trial_env_vars.NNI_TRIAL_JOB_ID
def get_sequence_id(): def get_sequence_id():
return trial_env_vars.NNI_TRIAL_SEQ_ID return trial_env_vars.NNI_TRIAL_SEQ_ID
...@@ -25,6 +25,12 @@ import json_tricks ...@@ -25,6 +25,12 @@ import json_tricks
def get_next_parameter(): def get_next_parameter():
pass pass
def get_experiment_id():
pass
def get_trial_id():
pass
def get_sequence_id(): def get_sequence_id():
pass pass
......
...@@ -32,6 +32,12 @@ _last_metric = None ...@@ -32,6 +32,12 @@ _last_metric = None
def get_next_parameter(): def get_next_parameter():
return _params return _params
def get_experiment_id():
return 'fakeidex'
def get_trial_id():
return 'fakeidtr'
def get_sequence_id(): def get_sequence_id():
return 0 return 0
......
...@@ -30,11 +30,15 @@ __all__ = [ ...@@ -30,11 +30,15 @@ __all__ = [
'get_current_parameter', 'get_current_parameter',
'report_intermediate_result', 'report_intermediate_result',
'report_final_result', 'report_final_result',
'get_experiment_id',
'get_trial_id',
'get_sequence_id' 'get_sequence_id'
] ]
_params = None _params = None
_experiment_id = platform.get_experiment_id()
_trial_id = platform.get_trial_id()
_sequence_id = platform.get_sequence_id() _sequence_id = platform.get_sequence_id()
...@@ -52,6 +56,12 @@ def get_current_parameter(tag): ...@@ -52,6 +56,12 @@ def get_current_parameter(tag):
return None return None
return _params['parameters'][tag] return _params['parameters'][tag]
def get_experiment_id():
return _experiment_id
def get_trial_id():
return _trial_id
def get_sequence_id(): def get_sequence_id():
return _sequence_id return _sequence_id
......
...@@ -38,6 +38,12 @@ class TrialTestCase(TestCase): ...@@ -38,6 +38,12 @@ class TrialTestCase(TestCase):
nni.get_next_parameter() nni.get_next_parameter()
self.assertEqual(nni.get_current_parameter('x'), 123) self.assertEqual(nni.get_current_parameter('x'), 123)
def test_get_experiment_id(self):
self.assertEqual(nni.get_experiment_id(), 'fakeidex')
def test_get_trial_id(self):
self.assertEqual(nni.get_trial_id(), 'fakeidtr')
def test_get_sequence_id(self): def test_get_sequence_id(self):
self.assertEqual(nni.get_sequence_id(), 0) self.assertEqual(nni.get_sequence_id(), 0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment