Beispiel #1
0
def hub_model(request, model_path, device, compiler):
    """Constructs a model object for pytests to use.
    Any pytest function that consumes a 'modeldef' arg will invoke this
    automatically, and reuse it for each test that takes that combination
    of arguments within the module.

    If reusing the module between tests isn't safe, change 'scope' parameter.
    """
    hubconf_file = 'hubconf.py'
    with workdir(model_path):
        hub_module = torch.hub.import_module(hubconf_file, hubconf_file)
        Model = getattr(hub_module, 'Model', None)
        if not Model:
            raise RuntimeError(
                'Missing class Model in {}/hubconf.py'.format(model_path))
        use_jit = compiler == 'jit'
        return Model(device=device, jit=use_jit)
Beispiel #2
0
def run_models():
    for model_class, model_path in list_models():
        with workdir(model_path):
            run_model(model_class, model_path)