Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Fix aml message index #2648

Merged
merged 5 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/nni_manager/training_service/reusable/aml/amlConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ export class AMLTrialConfig extends TrialConfig {

export class AMLEnvironmentInformation extends EnvironmentInformation {
public amlClient?: AMLClient;
public currentMessageIndex: number = -1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class AMLRunnerConnection extends RunnerConnection {

export class AMLCommandChannel extends CommandChannel {
private stopping: boolean = false;
private currentMessageIndex: number = -1;
private sendQueues: [EnvironmentInformation, string][] = [];
private readonly NNI_METRICS_PATTERN: string = `NNISDK_MEb'(?<metrics>.*?)'`;

Expand Down Expand Up @@ -89,23 +88,26 @@ export class AMLCommandChannel extends CommandChannel {
const runnerConnections = [...this.runnerConnections.values()] as AMLRunnerConnection[];
for (const runnerConnection of runnerConnections) {
// to loop all commands
const amlClient = (runnerConnection.environment as AMLEnvironmentInformation).amlClient;
const amlEnvironmentInformation: AMLEnvironmentInformation = runnerConnection.environment as AMLEnvironmentInformation;
const amlClient = amlEnvironmentInformation.amlClient;
let currentMessageIndex = amlEnvironmentInformation.currentMessageIndex;
if (!amlClient) {
throw new Error('AML client not initialized!');
}
const command = await amlClient.receiveCommand();
if (command && Object.prototype.hasOwnProperty.call(command, "trial_runner")) {
const messages = command['trial_runner'];
if (messages) {
if (messages instanceof Object && this.currentMessageIndex < messages.length - 1) {
for (let index = this.currentMessageIndex + 1; index < messages.length; index ++) {
if (messages instanceof Object && currentMessageIndex < messages.length - 1) {
for (let index = currentMessageIndex + 1; index < messages.length; index ++) {
this.handleCommand(runnerConnection.environment, messages[index]);
}
this.currentMessageIndex = messages.length - 1;
} else if (this.currentMessageIndex === -1){
currentMessageIndex = messages.length - 1;
} else if (currentMessageIndex === -1){
this.handleCommand(runnerConnection.environment, messages);
this.currentMessageIndex += 1;
currentMessageIndex += 1;
}
amlEnvironmentInformation.currentMessageIndex = currentMessageIndex;
}
}
}
Expand Down