def delete(id: str): if not exists_by_id(id): raise HTTPException( status_code=404, detail=f'Model ID {id} does not exist. You may change the ID', ) delete_model(id)
def update(id: str, schema: ModelUpdateSchema): if not exists_by_id(id): raise HTTPException( status_code=404, detail=f'Model ID {id} does not exist. You may change the ID', ) return update_model(id, schema)
def profile(model_id: str, device: str='cuda', batch_size: int=1): if not exists_by_id(model_id): raise HTTPException( status_code=404, detail=f'Model ID {model_id} does not exist. You may change the ID', ) profile_result = profile_model(model_id, device, batch_size) return profile_result
def convert( id: str = typer.Option(None, '-i', '--id', help='ID of model.'), yaml_file: Optional[Path] = typer.Option( None, '-f', '--yaml-file', exists=True, file_okay=True, help='Path to configuration YAML file. You should either set the `yaml_file` field or fields ' '(`FILE_OR_DIR`, `--name`, `--framework`, `--engine`, `--version`, `--task`, `--dataset`,' '`--metric`, `--input`, `--output`).' ), register: bool = typer.Option(False, '-r', '--register', is_flag=True, help='register the converted models to modelhub, default false') ): model = None if id is None and yaml_file is None: raise ValueError('WARNING: Please assign a way to find the target model! details refer to --help') if id is not None and yaml_file is not None: raise ValueError('WARNING: Do not use -id and -path at the same time!') elif id is not None and yaml_file is None: if ModelDB.exists_by_id(id): model = ModelDB.get_by_id(id) else: typer.echo(f"model id: {id} does not exist in modelhub") elif id is None and yaml_file is not None: # get MLModel from yaml file with open(yaml_file) as f: model_config = yaml.safe_load(f) model_yaml = MLModelFromYaml.parse_obj(model_config) model_in_saved_path = model_yaml.saved_path if model_in_saved_path != model_yaml.weight: copy2(model_yaml.weight, model_in_saved_path) if model_yaml.engine == Engine.TFS: weight_dir = model_yaml.weight make_archive(weight_dir.with_suffix('.zip'), 'zip', weight_dir) model_data = model_yaml.dict(exclude_none=True, exclude={'convert', 'profile'}) model = MLModel.parse_obj(model_data) # auto execute all possible convert and return a list of save paths of every converted model generated_dir_list = generate_model_family(model) typer.echo(f"Converted models are save in: {generated_dir_list}") if register: model_data = model.dict(exclude={'weight', 'id', 'model_status', 'engine'}) for model_dir in generated_dir_list: parse_result = parse_path_plain(model_dir) engine = parse_result['engine'] model_cvt = MLModel(**model_data, weight=model_dir, engine=engine, model_status=[ModelStatus.CONVERTED]) ModelDB.save(model_cvt) typer.echo(f"converted {engine} are successfully registered in Modelhub")