Ejemplo n.º 1
0
def get_fake_model():
    model_xml = 'model1.xml'
    model_bin = 'model1.bin'
    mapping_config = 'mapping_config.json'
    exec_net = None
    net = None
    plugin = None
    batch_size = None
    input_key = 'input'
    inputs = {input_key: Layer('FP32', [1, 1, 1], 'NCHW')}
    outputs = {'output': Layer('FP32', [1, 1, 1], 'NCHW')}
    engine = IrEngine(model_bin=model_bin,
                      model_xml=model_xml,
                      mapping_config=mapping_config,
                      exec_net=exec_net,
                      inputs=inputs,
                      outputs=outputs,
                      net=net,
                      plugin=plugin,
                      batch_size=batch_size)
    new_engines = {1: engine, 2: engine, 3: engine}
    new_model = LocalModel(model_name="test",
                           model_directory='fake_path/model/',
                           available_versions=[1, 2, 3],
                           engines=new_engines,
                           batch_size=batch_size)
    return new_model
Ejemplo n.º 2
0
def get_fake_model():
    model_xml = 'model1.xml'
    model_bin = 'model1.bin'
    mapping_config = 'mapping_config.json'
    exec_net = None
    net = None
    plugin = None
    batch_size = None
    input_key = DEFAULT_INPUT_KEY
    output_key = DEFAULT_OUTPUT_KEY
    inputs = {input_key: Layer('FP32', [1, 1, 1], 'NCHW')}
    outputs = {output_key: Layer('FP32', [1, 1, 1], 'NCHW')}
    engine = IrEngine(model_bin=model_bin,
                      model_xml=model_xml,
                      mapping_config=mapping_config,
                      exec_net=exec_net,
                      inputs=inputs,
                      outputs=outputs,
                      net=net,
                      plugin=plugin,
                      batch_size=batch_size)
    new_engines = {1: engine, 2: engine, 3: engine}
    available_versions = [1, 2, 3]
    model_name = "test"
    versions_statuses = {}
    for version in available_versions:
        versions_statuses[version] = ModelVersionStatus(model_name, version)
    new_model = LocalModel(model_name=model_name,
                           model_directory='fake_path/model/',
                           available_versions=[1, 2, 3],
                           engines=new_engines,
                           batch_size=batch_size,
                           version_policy_filter=lambda versions: versions[:],
                           versions_statuses=versions_statuses)
    return new_model
Ejemplo n.º 3
0
def test_get_engines_for_model_with_ir_raises(mocker):
    engines_mocker = mocker.patch('ie_serving.models.ir_engine.IrEngine.'
                                  'build')
    engines_mocker.side_effect = ['modelv2', 'modelv4', Exception("test")]
    available_versions = [{'xml_file': 'modelv2.xml',
                           'bin_file': 'modelv2.bin',
                           'mapping_config': 'mapping_config.json',
                           'version_number': 2, 'batch_size_param': None,
                           'shape_param': None, 'num_ireq': 1,
                           'target_device': 'CPU', 'plugin_config': None},
                          {'xml_file': 'modelv4.xml',
                           'bin_file': 'modelv4.bin',
                           'mapping_config': 'mapping_config.json',
                           'version_number': 3, 'batch_size_param': None,
                           'shape_param': None, 'num_ireq': 1,
                           'target_device': 'CPU', 'plugin_config': None},
                          {'xml_file': 'modelv4.xml',
                           'bin_file': 'modelv4.bin',
                           'mapping_config': 'mapping_config.json',
                           'version_number': 4, 'batch_size_param': None,
                           'shape_param': None, 'num_ireq': 1,
                           'target_device': 'CPU', 'plugin_config': None}]
    versions_statuses = {}
    for version in available_versions:
        version_number = version['version_number']
        versions_statuses[version_number] = ModelVersionStatus(
            "test", version_number)
    output = LocalModel.get_engines_for_model(
        model_name='test',
        versions_attributes=available_versions,
        versions_statuses=versions_statuses,
        update_locks={})
    assert 2 == len(output)
    assert 'modelv2' == output[2]
    assert 'modelv4' == output[3]
Ejemplo n.º 4
0
def test_model_init(engines):
    available_versions = [1, 2, 3]
    model_name = "test"
    versions_statuses = {}
    for version in available_versions:
        versions_statuses[version] = ModelVersionStatus(model_name, version)

    for version_status in versions_statuses.values():
        assert version_status.state == ModelVersionState.START

    new_model = LocalModel(model_name=model_name, model_directory='fake_path',
                           available_versions=available_versions,
                           engines=engines,
                           batch_size_param=None,
                           shape_param=None,
                           version_policy_filter=lambda versions: versions[:],
                           versions_statuses=versions_statuses,
                           update_locks={},
                           num_ireq=1, target_device='CPU',
                           plugin_config=None)

    not_available_versions = list(set(available_versions) ^
                                  set(engines.keys()))
    for loaded_version in engines.keys():
        assert new_model.versions_statuses[loaded_version].state == \
            ModelVersionState.AVAILABLE
    for not_available_version in not_available_versions:
        assert new_model.versions_statuses[not_available_version].state != \
            ModelVersionState.AVAILABLE

    assert new_model.default_version == 3
    assert new_model.model_name == 'test'
    assert new_model.model_directory == 'fake_path'
    assert new_model.engines == engines
def test_get_engines_for_model_with_ir_raises(mocker):
    engines_mocker = mocker.patch('ie_serving.models.ir_engine.IrEngine.'
                                  'build')
    engines_mocker.side_effect = ['modelv2', 'modelv4', Exception("test")]
    available_versions = [{
        'xml_file': 'modelv2.xml',
        'bin_file': 'modelv2.bin',
        'mapping_config': 'mapping_config.json',
        'version_number': 2
    }, {
        'xml_file': 'modelv4.xml',
        'bin_file': 'modelv4.bin',
        'mapping_config': 'mapping_config.json',
        'version_number': 3
    }, {
        'xml_file': 'modelv4.xml',
        'bin_file': 'modelv4.bin',
        'mapping_config': 'mapping_config.json',
        'version_number': 4
    }]
    output = LocalModel.get_engines_for_model(
        versions_attributes=available_versions)
    assert 2 == len(output)
    assert 'modelv2' == output[2]
    assert 'modelv4' == output[3]
Ejemplo n.º 6
0
def get_fake_model():
    mapping_config = 'mapping_config.json'
    exec_net = None
    net = MockedNet(
        inputs={DEFAULT_INPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')},
        outputs={DEFAULT_OUTPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')})
    plugin = None
    batching_info = BatchingInfo(None)
    shape_info = ShapeInfo(None, net.inputs)
    new_engines = {}
    available_versions = [1, 2, 3]
    for version in available_versions:
        engine = IrEngine(model_name='test',
                          model_version=version,
                          mapping_config=mapping_config,
                          exec_net=exec_net,
                          net=net,
                          plugin=plugin,
                          batching_info=batching_info,
                          shape_info=shape_info)
        new_engines.update({version: engine})
    model_name = "test"
    versions_statuses = {}
    batch_size_param, shape_param = None, None
    for version in available_versions:
        versions_statuses[version] = ModelVersionStatus(model_name, version)
    new_model = LocalModel(model_name=model_name,
                           model_directory='fake_path/model/',
                           available_versions=available_versions,
                           engines=new_engines,
                           batch_size_param=batch_size_param,
                           shape_param=shape_param,
                           version_policy_filter=lambda versions: versions[:],
                           versions_statuses=versions_statuses)
    return new_model
Ejemplo n.º 7
0
def test_get_versions_files(mocker, mocker_values, expected_output):
    glob_mocker = mocker.patch('glob.glob')
    glob_mocker.side_effect = mocker_values

    xml_f, bin_f, mapping = LocalModel.get_version_files('/data/model/3/')
    assert expected_output[0] == xml_f
    assert expected_output[1] == bin_f
    assert expected_output[2] is mapping
Ejemplo n.º 8
0
 def build(model_name: str, model_directory: str):
     parsed_path = urlparse(model_directory)
     if parsed_path.scheme == '':
         return LocalModel.build(model_name, model_directory)
     elif parsed_path.scheme == 'gs':
         return GSModel.build(model_name, model_directory)
     elif parsed_path.scheme == 's3':
         return S3Model.build(model_name, model_directory)
def test_get_versions_files(mocker):
    glob_mocker = mocker.patch('glob.glob')
    glob_mocker.side_effect = [['/data/model/3/model.bin'],
                               ['/data/model/3/model.xml'], []]

    xml, bin, mapping = LocalModel.get_version_files('/data/model/3/')
    assert xml == '/data/model/3/model.xml' and \
        bin == '/data/model/3/model.bin' and \
        mapping is None
def test_model_init():
    new_model = LocalModel(model_name="test",
                           model_directory='fake_path',
                           available_versions=[1, 2, 3],
                           engines={})
    assert new_model.default_version == 3
    assert new_model.model_name == 'test'
    assert new_model.model_directory == 'fake_path'
    assert new_model.engines == {}
Ejemplo n.º 11
0
def test_model_init():
    new_model = LocalModel(model_name="test",
                           model_directory='fake_path',
                           available_versions=[1, 2, 3],
                           engines={},
                           batch_size=None,
                           version_policy_filter=lambda versions: versions[:])
    assert new_model.default_version == 3
    assert new_model.model_name == 'test'
    assert new_model.model_directory == 'fake_path'
    assert new_model.engines == {}
Ejemplo n.º 12
0
def test_get_engines_for_model(mocker, is_error):
    engines_mocker = mocker.patch('ie_serving.models.ir_engine.IrEngine.'
                                  'build')

    engines_mocker.side_effect = ['modelv2', 'modelv4']
    available_versions = [{
        'xml_file': 'modelv2.xml',
        'bin_file': 'modelv2.bin',
        'mapping_config': 'mapping_config.json',
        'version_number': 2,
        'batch_size_param': None,
        'shape_param': None,
        'num_ireq': 1,
        'target_device': 'CPU',
        'plugin_config': None
    }, {
        'xml_file': 'modelv4.xml',
        'bin_file': 'modelv4.bin',
        'mapping_config': 'mapping_config.json',
        'version_number': 4,
        'batch_size_param': None,
        'shape_param': None,
        'num_ireq': 1,
        'target_device': 'CPU',
        'plugin_config': None
    }]
    versions_statuses = {}
    for version in available_versions:
        version_number = version['version_number']
        versions_statuses[version_number] = ModelVersionStatus(
            "test", version_number)
    if is_error:
        get_engine_for_version_mocker = mocker.patch(
            'ie_serving.models.local_model.LocalModel.get_engine_for_version')
        get_engine_for_version_mocker.side_effect = Exception()

    output = LocalModel.get_engines_for_model(
        model_name='test',
        versions_attributes=available_versions,
        versions_statuses=versions_statuses)

    for version_status in versions_statuses.values():
        assert version_status.state == ModelVersionState.LOADING
        if is_error:
            assert version_status.status['error_code'] == ErrorCode.UNKNOWN
            assert get_engine_for_version_mocker.called
        else:
            assert version_status.status['error_code'] == ErrorCode.OK
    if is_error:
        assert 0 == len(output)
    else:
        assert 2 == len(output)
        assert 'modelv2' == output[2]
        assert 'modelv4' == output[4]
Ejemplo n.º 13
0
 def build(model_name: str, model_directory: str,
           model_version_policy: dict, batch_size, shape):
     parsed_path = urlparse(model_directory)
     if parsed_path.scheme == '':
         return LocalModel.build(model_name, model_directory, batch_size,
                                 shape, model_version_policy)
     elif parsed_path.scheme == 'gs':
         return GSModel.build(model_name, model_directory, batch_size,
                              shape, model_version_policy)
     elif parsed_path.scheme == 's3':
         return S3Model.build(model_name, model_directory, batch_size,
                              shape, model_version_policy)
Ejemplo n.º 14
0
 def build(model_name: str, model_directory: str,
           model_version_policy: dict, batch_size, shape, num_ireq: int,
           target_device, plugin_config):
     parsed_path = urlparse(model_directory)
     if parsed_path.scheme == '':
         return LocalModel.build(model_name, model_directory, batch_size,
                                 shape, model_version_policy, num_ireq,
                                 target_device, plugin_config)
     elif parsed_path.scheme == 'gs':
         return GSModel.build(model_name, model_directory, batch_size,
                              shape, model_version_policy, num_ireq,
                              target_device, plugin_config)
     elif parsed_path.scheme == 's3':
         return S3Model.build(model_name, model_directory, batch_size,
                              shape, model_version_policy, num_ireq,
                              target_device, plugin_config)
Ejemplo n.º 15
0
def get_fake_model():
    model_xml = 'model1.xml'
    model_bin = 'model1.bin'
    mapping_config = 'mapping_config.json'
    exec_net = None
    input_key = 'input'
    inputs = {input_key: [1, 1]}
    outputs = ['test_output']
    engine = IrEngine(model_bin=model_bin, model_xml=model_xml,
                      mapping_config=mapping_config, exec_net=exec_net,
                      inputs=inputs, outputs=outputs)
    new_engines = {1: engine, 2: engine, 3: engine}
    new_model = LocalModel(model_name="test",
                           model_directory='fake_path/model/',
                           available_versions=[1, 2, 3], engines=new_engines)
    return new_model
Ejemplo n.º 16
0
def get_fake_model():
    mapping_config = 'mapping_config.json'
    exec_net = MockedExecNet()
    net = MockedNet(
        inputs={DEFAULT_INPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')},
        outputs={DEFAULT_OUTPUT_KEY: MockedIOInfo('FP32', [1, 1, 1], 'NCHW')})
    core = None
    batching_info = BatchingInfo(None)
    shape_info = ShapeInfo(None, net.inputs)
    new_engines = {}
    available_versions = [1, 2, 3]
    requests_queue = queue.Queue()
    free_ireq_index_queue = queue.Queue(maxsize=1)
    free_ireq_index_queue.put(0)
    for version in available_versions:
        engine = IrEngine(model_name='test',
                          model_version=version,
                          mapping_config=mapping_config,
                          exec_net=exec_net,
                          net=net,
                          core=core,
                          batching_info=batching_info,
                          shape_info=shape_info,
                          target_device="CPU",
                          free_ireq_index_queue=free_ireq_index_queue,
                          plugin_config=None,
                          num_ireq=1,
                          requests_queue=requests_queue)
        new_engines.update({version: engine})
    model_name = "test"
    versions_statuses = {}
    batch_size_param, shape_param = None, None
    for version in available_versions:
        versions_statuses[version] = ModelVersionStatus(model_name, version)
    new_model = LocalModel(model_name=model_name,
                           model_directory='fake_path/model/',
                           available_versions=available_versions,
                           engines=new_engines,
                           batch_size_param=batch_size_param,
                           shape_param=shape_param,
                           version_policy_filter=lambda versions: versions[:],
                           versions_statuses=versions_statuses,
                           update_locks={},
                           plugin_config=None,
                           target_device="CPU",
                           num_ireq=1)
    return new_model
Ejemplo n.º 17
0
def test_get_engines_for_model(mocker):
    engines_mocker = mocker.patch('ie_serving.models.ir_engine.IrEngine.'
                                  'build')
    engines_mocker.side_effect = ['modelv2', 'modelv4']
    available_versions = [{
        'xml_file': 'modelv2.xml',
        'bin_file': 'modelv2.bin',
        'mapping_config': 'mapping_config.json',
        'version_number': 2,
        'batch_size': None
    }, {
        'xml_file': 'modelv4.xml',
        'bin_file': 'modelv4.bin',
        'mapping_config': 'mapping_config.json',
        'version_number': 4,
        'batch_size': None
    }]
    output = LocalModel.get_engines_for_model(
        versions_attributes=available_versions)
    assert 2 == len(output)
    assert 'modelv2' == output[2]
    assert 'modelv4' == output[4]