-
Notifications
You must be signed in to change notification settings - Fork 377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Warm up Orchestrator build cache from previous Composer session #6550
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
dce21dc
Update orch package
taicchoumsft ae82b46
Merge branch 'main' into tachou/orchColdBootOptimization
taicchoumsft 56de6b9
initial implementation
taicchoumsft 015aec4
Merge branch 'main' into tachou/orchColdBootOptimization
taicchoumsft 1eaa774
Tighten up code and exception handling
taicchoumsft 58b96b3
Unit tests
taicchoumsft bffbbc9
Fix linter errors
taicchoumsft eb69fab
Merge branch 'main' into tachou/orchColdBootOptimization
taicchoumsft 0173319
Don't rethrow error for cache - safe to continue on
taicchoumsft 85959bc
Merge branch 'main' into tachou/orchColdBootOptimization
taicchoumsft 203694f
Merge branch 'main' into tachou/orchColdBootOptimization
taicchoumsft f7388a8
Merge branch 'main' into tachou/orchColdBootOptimization
taicchoumsft a72f752
Fix build error of worker script when testing
taicchoumsft 5bc8fdf
Merge branch 'tachou/orchColdBootOptimization' of https://github.com/…
taicchoumsft 63de49d
Merge branch 'main' into tachou/orchColdBootOptimization
taicchoumsft 0c00e30
Merge branch 'main' into tachou/orchColdBootOptimization
boydc2014 a18fb55
Merge branch 'main' into tachou/orchColdBootOptimization
boydc2014 5d454f6
Merge branch 'main' into tachou/orchColdBootOptimization
taicchoumsft 23395b1
Merge branch 'main' into tachou/orchColdBootOptimization
boydc2014 78c2946
Merge branch 'main' into tachou/orchColdBootOptimization
boydc2014 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
Composer/packages/server/src/models/bot/__tests__/orchestratorWorker.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,161 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
import { LabelResolver, Utility, Orchestrator } from '@microsoft/bf-orchestrator'; | ||
import { pathExists, readdir, readJson } from 'fs-extra'; | ||
|
||
import { cache, warmUpCache } from '../process/orchestratorWorker'; | ||
|
||
jest.mock('@microsoft/bf-orchestrator'); | ||
jest.mock('fs-extra', () => ({ | ||
pathExists: jest.fn(async (path) => path === './generatedFolder' || path.endsWith('orchestrator.settings.json')), | ||
readdir: jest.fn(async (path) => { | ||
if (path === './generatedFolder') { | ||
return ['test.en.lu', 'test.en.blu', 'test.zh-cn.blu', 'settings.json', '/path']; | ||
} | ||
return []; | ||
}), | ||
readJson: jest.fn(async (file) => { | ||
return { | ||
orchestrator: { | ||
models: { | ||
en: './model/en.onnx', | ||
multilang: './model/multilang.onnx', | ||
}, | ||
snapshots: { | ||
testZhCn: './generated/test.zh-cn.blu', | ||
}, | ||
}, | ||
}; | ||
}), | ||
readFile: jest.fn(async (file) => { | ||
return Buffer.from('test blu file'); | ||
}), | ||
})); | ||
|
||
describe('Orchestrator Warmup Cache', () => { | ||
beforeAll(async () => { | ||
Utility.toPrintDebuggingLogToConsole = false; //disable Orchestrator logging | ||
}); | ||
|
||
beforeEach(async () => { | ||
(Orchestrator.getLabelResolversAsync as jest.Mock).mockImplementation( | ||
async (intentModelPath: string, _: string, snapshots: Map<string, Uint8Array>) => { | ||
return new Map<string, LabelResolver>(); | ||
} | ||
); | ||
|
||
(readdir as jest.Mock).mockClear(); | ||
(pathExists as jest.Mock).mockClear(); | ||
(Orchestrator.getLabelResolversAsync as jest.Mock).mockClear(); | ||
|
||
cache.clear(); | ||
}); | ||
|
||
it('exits on invalid generatedFolderPath', async () => { | ||
expect(await warmUpCache('badpath', 'abc')).toBeFalsy(); | ||
}); | ||
|
||
it('exits if cache for project has contents', async () => { | ||
const data: [string, LabelResolver] = ['test.en.lu', {} as LabelResolver]; | ||
cache.set('abc', new Map([data])); | ||
expect(cache.get('abc').size).toBe(1); | ||
|
||
expect(await warmUpCache('./generatedFolder', 'abc')).toBeFalsy(); | ||
}); | ||
|
||
it('exits if no blu files in generated folder', async () => { | ||
expect(cache.get('abc').size).toBe(0); | ||
|
||
expect(await warmUpCache('./emptyGeneratedFolder', 'abc')).toBeFalsy(); | ||
expect(Orchestrator.getLabelResolversAsync).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it('exits if Orchestrator settings is invalid', async () => { | ||
(Orchestrator.getLabelResolversAsync as jest.Mock).mockImplementation( | ||
async (intentModelPath: string, _: string, snapshots: Map<string, Uint8Array>) => { | ||
return new Map<string, LabelResolver>(); | ||
} | ||
); | ||
(readJson as jest.Mock).mockImplementationOnce(async (file) => 'corrupted settings'); | ||
|
||
await warmUpCache('./generatedFolder', 'abc'); | ||
expect(pathExists).toHaveBeenCalledTimes(2); | ||
expect(readJson).toHaveBeenCalled(); | ||
|
||
expect(Orchestrator.getLabelResolversAsync).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it('exits if Orchestrator settings cannot be read', async () => { | ||
(readJson as jest.Mock).mockImplementationOnce(async (file) => undefined); | ||
|
||
expect(await warmUpCache('./generatedFolder', 'abc')).toBeFalsy(); | ||
expect(pathExists).toHaveBeenCalledTimes(2); | ||
expect(readJson).toHaveBeenCalled(); | ||
|
||
expect(Orchestrator.getLabelResolversAsync).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it('sends correct data shape to Orchestrator library for en + multilang', async () => { | ||
expect(cache.get('abc').size).toBe(0); | ||
expect(await readdir('./generatedFolder')).toContain('test.en.blu'); | ||
|
||
await warmUpCache('./generatedFolder', 'abc'); | ||
|
||
expect(Orchestrator.getLabelResolversAsync).toHaveBeenCalledTimes(2); | ||
expect(Orchestrator.getLabelResolversAsync).toHaveBeenNthCalledWith( | ||
1, | ||
'./model/en.onnx', | ||
'', | ||
new Map([['test.en.lu', new Uint8Array(Buffer.from('test blu file'))]]), | ||
false | ||
); | ||
expect(Orchestrator.getLabelResolversAsync).toHaveBeenNthCalledWith( | ||
2, | ||
'./model/multilang.onnx', | ||
'', | ||
new Map([['test.zh-cn.lu', new Uint8Array(Buffer.from('test blu file'))]]), | ||
false | ||
); | ||
}); | ||
|
||
it('sends correct data shape to Orchestrator library for en only', async () => { | ||
expect(cache.get('abc').size).toBe(0); | ||
|
||
(readdir as jest.Mock).mockImplementationOnce(async (path: string) => ['test.en.blu', 'test.en-us.blu']); | ||
|
||
await warmUpCache('./generatedFolder', 'abc'); | ||
|
||
expect(Orchestrator.getLabelResolversAsync).toHaveBeenCalledTimes(1); | ||
expect(Orchestrator.getLabelResolversAsync).toHaveBeenNthCalledWith( | ||
1, | ||
'./model/en.onnx', | ||
'', | ||
new Map([ | ||
['test.en-us.lu', new Uint8Array(Buffer.from('test blu file'))], | ||
['test.en.lu', new Uint8Array(Buffer.from('test blu file'))], | ||
]), | ||
false | ||
); | ||
}); | ||
|
||
it('sends correct data shape to Orchestrator library for multilang only', async () => { | ||
expect(cache.get('abc').size).toBe(0); | ||
|
||
(readdir as jest.Mock).mockImplementationOnce(async (path: string) => ['test.zh-cn.blu', 'test.ja-jp.blu']); | ||
|
||
await warmUpCache('./generatedFolder', 'abc'); | ||
|
||
expect(Orchestrator.getLabelResolversAsync).toHaveBeenCalledTimes(1); | ||
expect(Orchestrator.getLabelResolversAsync).toHaveBeenNthCalledWith( | ||
1, | ||
'./model/multilang.onnx', | ||
'', | ||
new Map([ | ||
['test.zh-cn.lu', new Uint8Array(Buffer.from('test blu file'))], | ||
['test.ja-jp.lu', new Uint8Array(Buffer.from('test blu file'))], | ||
]), | ||
false | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this matches the lu object id "f.replace('.blu', '.lu')" pass in the buildAsync method, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, these are also the ids we get back from the results object from
buildAsync
,