-
Notifications
You must be signed in to change notification settings - Fork 41
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
Separate config and observation on model execute signature #377
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,9 @@ tags: null | |
initialize: | ||
models: | ||
- name: sci | ||
kind: builtin | ||
path: '' | ||
kind: plugin | ||
path: '@grnsft/if-models' | ||
model: SciModel | ||
graph: | ||
children: | ||
child: | ||
|
@@ -30,7 +31,5 @@ graph: | |
operational-carbon: 5 | ||
embodied-carbon: 0.02 | ||
requests: 100 | ||
functional-unit-duration: 1 | ||
functional-unit-time: minutes | ||
functional-unit: requests | ||
carbon: 0.0013944444444444442 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
sci: 0.0008366666666666665 |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,6 +306,123 @@ describe('lib/supercomputer: ', () => { | |
); | ||
}); | ||
|
||
it('passes output from earlier executed model to the later ones as an input', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO having all the test related entities and logic inside of the test itself increases readability and maintainability. |
||
const testImpl: any = { | ||
name: 'test-impl', | ||
graph: { | ||
children: { | ||
child: { | ||
pipeline: ['model-one', 'model-two'], | ||
inputs: [{testProp: 5}], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const mockModelOneExecutor = jest.fn(() => [ | ||
{testProp: 5, 'model-one-output': true}, | ||
]); | ||
const mockModelTwoExecutor = jest.fn(); | ||
|
||
const modelsHandbook = { | ||
getInitializedModel: jest.fn(modelName => { | ||
if (modelName === 'model-one') return {execute: mockModelOneExecutor}; | ||
if (modelName === 'model-two') return {execute: mockModelTwoExecutor}; | ||
return; | ||
}), | ||
}; | ||
|
||
const supercomputer = new Supercomputer( | ||
testImpl, | ||
modelsHandbook as unknown as ModelsUniverse | ||
); | ||
await supercomputer.compute(); | ||
|
||
expect(modelsHandbook.getInitializedModel).toHaveBeenNthCalledWith( | ||
1, | ||
'model-one', | ||
{} | ||
); | ||
|
||
expect(modelsHandbook.getInitializedModel).toHaveBeenNthCalledWith( | ||
2, | ||
'model-two', | ||
{} | ||
); | ||
|
||
expect(mockModelOneExecutor).toHaveBeenNthCalledWith( | ||
1, | ||
[{testProp: 5}], | ||
{} | ||
); | ||
|
||
expect(mockModelTwoExecutor).toHaveBeenNthCalledWith( | ||
1, | ||
[{testProp: 5, 'model-one-output': true}], | ||
{} | ||
); | ||
}); | ||
|
||
it('runs model execute method with two arguments: inputs and properly merged config', async () => { | ||
const testImpl: any = { | ||
name: 'test-impl', | ||
graph: { | ||
children: { | ||
child: { | ||
pipeline: ['model-one'], | ||
config: { | ||
'model-one': { | ||
'config-prop-one': true, | ||
'config-prop-two': 'test', | ||
}, | ||
}, | ||
children: { | ||
child: { | ||
config: { | ||
'model-one': { | ||
'config-prop-one': false, | ||
'config-prop-three': 1, | ||
}, | ||
}, | ||
inputs: [{testProp: 5}], | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const mockModelOneExecutor = jest.fn(); | ||
|
||
const modelsHandbook = { | ||
getInitializedModel: jest.fn(() => ({ | ||
execute: mockModelOneExecutor, | ||
})), | ||
}; | ||
|
||
const supercomputer = new Supercomputer( | ||
testImpl, | ||
modelsHandbook as unknown as ModelsUniverse | ||
); | ||
await supercomputer.compute(); | ||
|
||
expect(modelsHandbook.getInitializedModel).toHaveBeenNthCalledWith( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additionally, we will check that the model is initialized with a proper config. |
||
1, | ||
'model-one', | ||
{ | ||
'config-prop-one': false, | ||
'config-prop-two': 'test', | ||
'config-prop-three': 1, | ||
} | ||
); | ||
|
||
expect(mockModelOneExecutor).toHaveBeenNthCalledWith(1, [{testProp: 5}], { | ||
'config-prop-one': false, | ||
'config-prop-two': 'test', | ||
'config-prop-three': 1, | ||
}); | ||
}); | ||
|
||
it('throws `structure malformed` error if nested children component misses `inputs`.', async () => { | ||
const jsonObj = JSON.stringify(impl); | ||
const implCopy = JSON.parse(jsonObj); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ import {CONFIG, STRINGS} from '../config'; | |
|
||
import { | ||
ClassContainerParams, | ||
GraphOptions, | ||
ImplInitializeModel, | ||
InitalizedModels, | ||
} from '../types/models-universe'; | ||
|
@@ -100,7 +99,7 @@ export class ModelsUniverse { | |
* Initializes and registers model. | ||
*/ | ||
public async writeDown(modelToInitalize: ImplInitializeModel) { | ||
const {model, path, config, name} = modelToInitalize; | ||
const {model, path, config: initConfig, name} = modelToInitalize; | ||
|
||
if (!model) { | ||
throw new ModelCredentialError(MISSING_CLASSNAME); | ||
|
@@ -112,10 +111,10 @@ export class ModelsUniverse { | |
|
||
const Model = await this.handModel(model, path); | ||
|
||
const callback = async (graphOptions: GraphOptions) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was just not relevant to the data comes here... |
||
const callback = async (nodeConfig: Record<string, any>) => { | ||
const params = { | ||
...config, | ||
...graphOptions, | ||
...initConfig, | ||
...nodeConfig, | ||
}; | ||
|
||
const initalizedModel = await new Model().configure(params); | ||
|
This file was deleted.
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.
Here is exactly an idea of the change, to remove config props pollution on outputs.