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, tags, zip, local_data_set, parent_ids, options, registry_id, git_id): """Submit new training""" api = rest.TrainingApi(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, tags=list(tags), zip=zip, local_data_set=local_data_set) result = api.create_training(model=model) print('created', result.id)
def list_training(count, id, name, started_at, data_set, memo, status, entry_point): """List training filtered by conditions""" api = rest.TrainingApi(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_training(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_training(page=page, **args) result.extend(page_result) if len(page_result) < per_page: break pprint.pp_table( ['id', 'name', 'started_at', 'dataset', 'memo', 'status'], [[x.id, x.name, x.created_at, x.data_set.name, x.memo, x.status] for x in result[:count]])
def download_files(id, destination): """Download files of training""" api = rest.TrainingApi(configuration.get_api_client()) result = api.list_training_files(id, with_url=True) pool_manager = api.api_client.rest_client.pool_manager for x in result: object_storage.download_file(pool_manager, x.url, destination, x.file_name)
def update(id, name, memo, favorite): """Update training""" api = rest.TrainingApi(configuration.get_api_client()) model = rest.TrainingApiModelsEditInputModel(name=name, memo=memo, favorite=favorite) result = api.update_training(id, model=model) print('updated', result.id)
def upload_file(id, file_path): """Upload a file to training""" api = rest.TrainingApi(configuration.get_api_client()) attached_info = object_storage.upload_file(api.api_client, file_path, 'TrainingHistoryAttachedFiles') model = rest.ComponentsAddFileInputModel( file_name=attached_info.file_name, stored_path=attached_info.stored_path) api.add_training_file(id, model=model)
def download_container_files(id, destination, source): """Download files in a container""" api = rest.TrainingApi(configuration.get_api_client()) pool_manager = api.api_client.rest_client.pool_manager def download_entries(path): result = api.list_training_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 get(id): """Get details of training""" api = rest.TrainingApi(configuration.get_api_client()) result = api.get_training(id) pprint.pp_dict(util.to_dict(result))
def tensorboard_halt(id): """Halt tensorboard""" api = rest.TrainingApi(configuration.get_api_client()) api.halt_tensorboard(id) print('halted', id)
def complete(id): """Complete training""" api = rest.TrainingApi(configuration.get_api_client()) result = api.complete_training(id) print('completed', result.id)
def halt(id): """Halt training""" api = rest.TrainingApi(configuration.get_api_client()) result = api.halt_training(id) print('halted', result.id)
def delete_file(id, file_id): """Delete a file of training""" api = rest.TrainingApi(configuration.get_api_client()) api.delete_training_file(id, file_id) print('deleted', file_id)
def list_files(id): """List files of training""" api = rest.TrainingApi(configuration.get_api_client()) result = api.list_training_files(id) pprint.pp_table(['file_id', 'file_name'], [[x.file_id, x.file_name] for x in result])
def delete(id): """Delete training""" api = rest.TrainingApi(configuration.get_api_client()) api.delete_training(id) print('deleted', id)