Ejemplo n.º 1
0
def operate_model(model_operation):
    request_config = request.json or request.form.to_dict()
    job_id = generate_job_id()
    if model_operation not in [ModelOperation.STORE, ModelOperation.RESTORE, ModelOperation.EXPORT, ModelOperation.IMPORT]:
        raise Exception('Can not support this operating now: {}'.format(model_operation))
    required_arguments = ["model_id", "model_version", "role", "party_id"]
    check_config(request_config, required_arguments=required_arguments)
    request_config["model_id"] = gen_party_model_id(model_id=request_config["model_id"], role=request_config["role"], party_id=request_config["party_id"])
    if model_operation in [ModelOperation.EXPORT, ModelOperation.IMPORT]:
        if model_operation == ModelOperation.IMPORT:
            file = request.files.get('file')
            file_path = os.path.join(TEMP_DIRECTORY, file.filename)
            try:
                os.makedirs(os.path.dirname(file_path), exist_ok=True)
                file.save(file_path)
            except Exception as e:
                shutil.rmtree(file_path)
                raise e
            request_config['file'] = file_path
            model = pipelined_model.PipelinedModel(model_id=request_config["model_id"], model_version=request_config["model_version"])
            model.unpack_model(file_path)
            return get_json_result()
        else:
            model = pipelined_model.PipelinedModel(model_id=request_config["model_id"], model_version=request_config["model_version"])
            archive_file_path = model.packaging_model()
            return send_file(archive_file_path, attachment_filename=os.path.basename(archive_file_path), as_attachment=True)
    else:
        data = {}
        job_dsl, job_runtime_conf = gen_model_operation_job_config(request_config, model_operation)
        job_id, job_dsl_path, job_runtime_conf_path, logs_directory, model_info, board_url = JobController.submit_job(
            {'job_dsl': job_dsl, 'job_runtime_conf': job_runtime_conf}, job_id=job_id)
        data.update({'job_dsl_path': job_dsl_path, 'job_runtime_conf_path': job_runtime_conf_path,
                     'board_url': board_url, 'logs_directory': logs_directory})
        return get_json_result(job_id=job_id, data=data)
Ejemplo n.º 2
0
 def __init__(self,
              job_id: str,
              role: str,
              party_id: int,
              model_id: str = None,
              model_version: str = None,
              component_name: str = None,
              component_module_name: str = None,
              task_id: str = None):
     self.job_id = job_id
     self.role = role
     self.party_id = party_id
     self.component_name = component_name if component_name else 'pipeline'
     self.module_name = component_module_name if component_module_name else 'Pipeline'
     self.task_id = task_id if task_id else job_utils.generate_task_id(
         job_id=self.job_id, component_name=self.component_name)
     self.table_namespace = '_'.join([
         'fate_flow', 'tracking', 'data', self.job_id, self.role,
         str(self.party_id), self.component_name
     ])
     self.job_table_namespace = '_'.join([
         'fate_flow', 'tracking', 'data', self.job_id, self.role,
         str(self.party_id)
     ])
     self.model_id = model_id
     self.party_model_id = model_utils.gen_party_model_id(model_id=model_id,
                                                          role=role,
                                                          party_id=party_id)
     self.model_version = model_version
     self.pipelined_model = None
     if self.party_model_id and self.model_version:
         self.pipelined_model = pipelined_model.PipelinedModel(
             model_id=self.party_model_id, model_version=self.model_version)
Ejemplo n.º 3
0
def download_model(request_data):
    model = pipelined_model.PipelinedModel(
        model_id=request_data.get("namespace"),
        model_version=request_data.get("name"))
    model_data = model.collect_models(in_bytes=True)
    return model_data