def create(name, registry_image, registry_tag, data_set_id, entry_point, git_owner, git_repository, git_branch, git_commit, cpu, memory, gpu, partition, memo, zip, local_data_set, parent_ids, options, registry_id, git_id): """Submit new inference""" api = rest.InferenceApi(configuration.get_api_client()) container_image = rest.ComponentsContainerImageInputModel( image=registry_image, registry_id=registry_id, tag=registry_tag) git_model = rest.ComponentsGitCommitInputModel(branch=git_branch, commit_id=git_commit, git_id=git_id, owner=git_owner, repository=git_repository) option_dict = {key: value for key, value in options} if options else None model = rest.TrainingApiModelsCreateInputModel( container_image=container_image, cpu=cpu, data_set_id=data_set_id, entry_point=entry_point, git_model=git_model, gpu=gpu, memo=memo, memory=memory, name=name, options=option_dict, parent_ids=list(parent_ids), partition=partition, zip=zip, local_data_set=local_data_set) result = api.create_inference(model=model) print('created', result.id)
def list_inference(count, id, name, started_at, data_set, memo, status, entry_point): """List inference filtered by conditions""" api = rest.InferenceApi(configuration.get_api_client()) per_page = 1000 command_args = { 'id': id, 'name': name, 'started_at': started_at, 'data_set': data_set, 'memo': memo, 'status': status, 'entry_point': entry_point, } args = {key: value for key, value in command_args.items() if value is not None} if count <= per_page: result = api.list_inference(per_page=count, **args) else: total_pages = (count - 1) // per_page + 1 result = [] for page in range(1, total_pages + 1): page_result = api.list_inference(page=page, **args) result.extend(page_result) if len(page_result) < per_page: break pprint.pp_table(['id', 'name', 'started_at', 'dataset', 'memo', 'value', 'status'], [[x.id, x.name, x.created_at, x.data_set.name, x.memo, x.output_value, x.status] for x in result[:count]])
def update(id, name, memo, favorite): """Update inference""" api = rest.InferenceApi(configuration.get_api_client()) model = rest.TrainingApiModelsEditInputModel(name=name, memo=memo, favorite=favorite) result = api.update_inference(id, model=model) print('updated', result.id)
def download_files(id, file_id, destination): """Download files of inference""" api = rest.InferenceApi(configuration.get_api_client()) result = api.list_inference_files(id, with_url=True) pool_manager = api.api_client.rest_client.pool_manager for x in result: if not file_id or x.file_id in file_id: object_storage.download_file(pool_manager, x.url, destination, x.file_name)
def upload_file(id, file_path): """Upload a file to inference""" api = rest.InferenceApi(configuration.get_api_client()) attached_info = object_storage.upload_file( api.api_client, file_path, 'InferenceHistoryAttachedFiles') model = rest.ComponentsAddFileInputModel( file_name=attached_info.file_name, stored_path=attached_info.stored_path) api.add_inference_file(id, model=model)
def download_container_files(id, destination, source): """Download files in a container""" api = rest.InferenceApi(configuration.get_api_client()) pool_manager = api.api_client.rest_client.pool_manager def download_entries(path): result = api.list_inference_container_files(id, path=path, with_url=True) for x in result.files: if os.path.isabs(path): _, tail = os.path.splitdrive(path) object_storage.download_file(pool_manager, x.url, destination + tail, x.file_name) else: object_storage.download_file(pool_manager, x.url, os.path.join(destination, path), x.file_name) for x in result.dirs: download_entries(os.path.join(path, x.dir_name)) source = source if source is not None else '/' download_entries(source)
def complete(id): """Complete inference""" api = rest.InferenceApi(configuration.get_api_client()) result = api.complete_inference(id) print('completed', result.id)
def halt(id): """Halt inference""" api = rest.InferenceApi(configuration.get_api_client()) result = api.halt_inference(id) print('halted', result.id)
def get(id): """Get details of inference""" api = rest.InferenceApi(configuration.get_api_client()) result = api.get_inference(id) pprint.pp_dict(util.to_dict(result))
def delete_file(id, file_id): """Delete a file of inference""" api = rest.InferenceApi(configuration.get_api_client()) api.delete_inference_file(id, file_id) print('deleted', file_id)
def list_files(id): """List files of inference""" api = rest.InferenceApi(configuration.get_api_client()) result = api.list_inference_files(id) pprint.pp_table(['file_id', 'file_name'], [[x.file_id, x.file_name] for x in result])
def delete(id): """Delete inference""" api = rest.InferenceApi(configuration.get_api_client()) api.delete_inference(id) print('deleted', id)