| @@ -637,30 +637,23 @@ func AiSafetyCreateForPost(ctx *context.Context) { | |||||
| ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tpname, nil) | ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tpname, nil) | ||||
| return | return | ||||
| } | } | ||||
| errstr := "" | |||||
| if taskType == models.TypeCloudBrainTwo { | if taskType == models.TypeCloudBrainTwo { | ||||
| ctx.Data["datasetType"] = models.TypeCloudBrainTwo | ctx.Data["datasetType"] = models.TypeCloudBrainTwo | ||||
| errstr = createForNPU(ctx, jobName) | |||||
| if errstr != "" { | |||||
| modelSafetyNewDataPrepare(ctx) | |||||
| ctx.RenderWithErr(errstr, tplCloudBrainModelSafetyNewNpu, nil) | |||||
| return | |||||
| } | |||||
| err = createForNPU(ctx, jobName) | |||||
| } else if taskType == models.TypeCloudBrainOne { | } else if taskType == models.TypeCloudBrainOne { | ||||
| ctx.Data["datasetType"] = models.TypeCloudBrainOne | ctx.Data["datasetType"] = models.TypeCloudBrainOne | ||||
| errstr = createForGPU(ctx, jobName) | |||||
| if errstr != "" { | |||||
| modelSafetyNewDataPrepare(ctx) | |||||
| ctx.RenderWithErr(errstr, tplCloudBrainModelSafetyNewGpu, nil) | |||||
| return | |||||
| } | |||||
| err = createForGPU(ctx, jobName) | |||||
| } | |||||
| if err != nil { | |||||
| modelSafetyNewDataPrepare(ctx) | |||||
| ctx.RenderWithErr(err.Error(), tpname, nil) | |||||
| } else { | |||||
| log.Info("to redirect...") | |||||
| ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain/benchmark") | |||||
| } | } | ||||
| log.Info("to redirect...") | |||||
| ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain/benchmark") | |||||
| } | } | ||||
| func createForNPU(ctx *context.Context, jobName string) string { | |||||
| func createForNPU(ctx *context.Context, jobName string) error { | |||||
| VersionOutputPath := modelarts.GetOutputPathByCount(modelarts.TotalVersionCount) | VersionOutputPath := modelarts.GetOutputPathByCount(modelarts.TotalVersionCount) | ||||
| BootFile := ctx.Query("boot_file") | BootFile := ctx.Query("boot_file") | ||||
| displayJobName := ctx.Query("display_job_name") | displayJobName := ctx.Query("display_job_name") | ||||
| @@ -703,11 +696,11 @@ func createForNPU(ctx *context.Context, jobName string) string { | |||||
| if err != nil || spec == nil { | if err != nil || spec == nil { | ||||
| //ctx.RenderWithErr("Resource specification not available", tplCloudBrainModelSafetyNewNpu, nil) | //ctx.RenderWithErr("Resource specification not available", tplCloudBrainModelSafetyNewNpu, nil) | ||||
| return "Resource specification not available" | |||||
| return errors.New("Resource specification not available") | |||||
| } | } | ||||
| if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice) { | if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice) { | ||||
| log.Error("point balance is not enough,userId=%d specId=%d ", ctx.User.ID, spec.ID) | log.Error("point balance is not enough,userId=%d specId=%d ", ctx.User.ID, spec.ID) | ||||
| return ctx.Tr("points.insufficient_points_balance") | |||||
| return errors.New(ctx.Tr("points.insufficient_points_balance")) | |||||
| } | } | ||||
| //todo: del the codeLocalPath | //todo: del the codeLocalPath | ||||
| @@ -721,23 +714,23 @@ func createForNPU(ctx *context.Context, jobName string) string { | |||||
| if err := downloadCode(repo, codeLocalPath, cloudbrain.DefaultBranchName); err != nil { | if err := downloadCode(repo, codeLocalPath, cloudbrain.DefaultBranchName); err != nil { | ||||
| log.Error("Create task failed, server timed out: %s (%v)", repo.FullName(), err) | log.Error("Create task failed, server timed out: %s (%v)", repo.FullName(), err) | ||||
| return ctx.Tr("cloudbrain.load_code_failed") | |||||
| return errors.New(ctx.Tr("cloudbrain.load_code_failed")) | |||||
| } | } | ||||
| //todo: upload code (send to file_server todo this work?) | //todo: upload code (send to file_server todo this work?) | ||||
| if err := obsMkdir(setting.CodePathPrefix + jobName + modelarts.ResultPath + VersionOutputPath + "/"); err != nil { | if err := obsMkdir(setting.CodePathPrefix + jobName + modelarts.ResultPath + VersionOutputPath + "/"); err != nil { | ||||
| log.Error("Failed to obsMkdir_result: %s (%v)", repo.FullName(), err) | log.Error("Failed to obsMkdir_result: %s (%v)", repo.FullName(), err) | ||||
| return "Failed to obsMkdir_result" | |||||
| return errors.New("Failed to obsMkdir_result") | |||||
| } | } | ||||
| if err := obsMkdir(setting.CodePathPrefix + jobName + modelarts.LogPath + VersionOutputPath + "/"); err != nil { | if err := obsMkdir(setting.CodePathPrefix + jobName + modelarts.LogPath + VersionOutputPath + "/"); err != nil { | ||||
| log.Error("Failed to obsMkdir_log: %s (%v)", repo.FullName(), err) | log.Error("Failed to obsMkdir_log: %s (%v)", repo.FullName(), err) | ||||
| return "Failed to obsMkdir_log" | |||||
| return errors.New("Failed to obsMkdir_log") | |||||
| } | } | ||||
| if err := uploadCodeToObs(codeLocalPath, jobName, ""); err != nil { | if err := uploadCodeToObs(codeLocalPath, jobName, ""); err != nil { | ||||
| log.Error("Failed to uploadCodeToObs: %s (%v)", repo.FullName(), err) | log.Error("Failed to uploadCodeToObs: %s (%v)", repo.FullName(), err) | ||||
| return ctx.Tr("cloudbrain.load_code_failed") | |||||
| return errors.New(ctx.Tr("cloudbrain.load_code_failed")) | |||||
| } | } | ||||
| var parameters models.Parameters | var parameters models.Parameters | ||||
| @@ -752,13 +745,13 @@ func createForNPU(ctx *context.Context, jobName string) string { | |||||
| uuid := srcDataset + ";" + combatDataset | uuid := srcDataset + ";" + combatDataset | ||||
| datasUrlList, dataUrl, datasetNames, isMultiDataset, err := getDatasUrlListByUUIDS(uuid) | datasUrlList, dataUrl, datasetNames, isMultiDataset, err := getDatasUrlListByUUIDS(uuid) | ||||
| if err != nil { | if err != nil { | ||||
| return err.Error() | |||||
| return err | |||||
| } | } | ||||
| dataPath := dataUrl | dataPath := dataUrl | ||||
| jsondatas, err := json.Marshal(datasUrlList) | jsondatas, err := json.Marshal(datasUrlList) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("Failed to Marshal: %v", err) | log.Error("Failed to Marshal: %v", err) | ||||
| return "json error:" + err.Error() | |||||
| return err | |||||
| } | } | ||||
| if isMultiDataset { | if isMultiDataset { | ||||
| param = append(param, models.Parameter{ | param = append(param, models.Parameter{ | ||||
| @@ -772,7 +765,7 @@ func createForNPU(ctx *context.Context, jobName string) string { | |||||
| err := json.Unmarshal([]byte(Params), ¶meters) | err := json.Unmarshal([]byte(Params), ¶meters) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("Failed to Unmarshal params: %s (%v)", Params, err) | log.Error("Failed to Unmarshal params: %s (%v)", Params, err) | ||||
| return "运行参数错误" | |||||
| return errors.New("运行参数错误") | |||||
| } | } | ||||
| for _, parameter := range parameters.Parameter { | for _, parameter := range parameters.Parameter { | ||||
| @@ -830,12 +823,12 @@ func createForNPU(ctx *context.Context, jobName string) string { | |||||
| err = modelarts.GenerateInferenceJob(ctx, req) | err = modelarts.GenerateInferenceJob(ctx, req) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("GenerateTrainJob failed:%v", err.Error()) | log.Error("GenerateTrainJob failed:%v", err.Error()) | ||||
| return err.Error() | |||||
| return err | |||||
| } | } | ||||
| return "" | |||||
| return nil | |||||
| } | } | ||||
| func createForGPU(ctx *context.Context, jobName string) string { | |||||
| func createForGPU(ctx *context.Context, jobName string) error { | |||||
| BootFile := ctx.Query("boot_file") | BootFile := ctx.Query("boot_file") | ||||
| displayJobName := ctx.Query("display_job_name") | displayJobName := ctx.Query("display_job_name") | ||||
| description := ctx.Query("description") | description := ctx.Query("description") | ||||
| @@ -858,7 +851,7 @@ func createForGPU(ctx *context.Context, jobName string) string { | |||||
| Cluster: models.OpenICluster, | Cluster: models.OpenICluster, | ||||
| AiCenterCode: models.AICenterOfCloudBrainOne}) | AiCenterCode: models.AICenterOfCloudBrainOne}) | ||||
| if err != nil || spec == nil { | if err != nil || spec == nil { | ||||
| return "Resource specification not available" | |||||
| return errors.New("Resource specification not available") | |||||
| } | } | ||||
| repo := ctx.Repo.Repository | repo := ctx.Repo.Repository | ||||
| @@ -867,13 +860,13 @@ func createForGPU(ctx *context.Context, jobName string) string { | |||||
| if err := downloadCode(repo, codePath, cloudbrain.DefaultBranchName); err != nil { | if err := downloadCode(repo, codePath, cloudbrain.DefaultBranchName); err != nil { | ||||
| log.Error("downloadCode failed, %v", err, ctx.Data["MsgID"]) | log.Error("downloadCode failed, %v", err, ctx.Data["MsgID"]) | ||||
| return "system error" | |||||
| return errors.New("system error") | |||||
| } | } | ||||
| err = uploadCodeToMinio(codePath+"/", jobName, cloudbrain.CodeMountPath+"/") | err = uploadCodeToMinio(codePath+"/", jobName, cloudbrain.CodeMountPath+"/") | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("uploadCodeToMinio failed, %v", err, ctx.Data["MsgID"]) | log.Error("uploadCodeToMinio failed, %v", err, ctx.Data["MsgID"]) | ||||
| return "system error" | |||||
| return errors.New("system error") | |||||
| } | } | ||||
| uuid := srcDataset + ";" + combatDataset | uuid := srcDataset + ";" + combatDataset | ||||
| @@ -881,12 +874,12 @@ func createForGPU(ctx *context.Context, jobName string) string { | |||||
| log.Info("uuid=" + uuid) | log.Info("uuid=" + uuid) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("GetDatasetInfo failed: %v", err, ctx.Data["MsgID"]) | log.Error("GetDatasetInfo failed: %v", err, ctx.Data["MsgID"]) | ||||
| return ctx.Tr("cloudbrain.error.dataset_select") | |||||
| return errors.New(ctx.Tr("cloudbrain.error.dataset_select")) | |||||
| } | } | ||||
| command, err := getGpuModelSafetyCommand(BootFile, Params, CkptName, displayJobName) | command, err := getGpuModelSafetyCommand(BootFile, Params, CkptName, displayJobName) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("Get Command failed: %v", err, ctx.Data["MsgID"]) | log.Error("Get Command failed: %v", err, ctx.Data["MsgID"]) | ||||
| return ctx.Tr("cloudbrain.error.dataset_select") | |||||
| return errors.New(ctx.Tr("cloudbrain.error.dataset_select")) | |||||
| } | } | ||||
| log.Info("Command=" + command) | log.Info("Command=" + command) | ||||
| @@ -920,9 +913,9 @@ func createForGPU(ctx *context.Context, jobName string) string { | |||||
| err = cloudbrain.GenerateTask(req) | err = cloudbrain.GenerateTask(req) | ||||
| if err != nil { | if err != nil { | ||||
| return err.Error() | |||||
| return err | |||||
| } | } | ||||
| return "" | |||||
| return nil | |||||
| } | } | ||||
| func getGpuModelSafetyCommand(BootFile string, params string, CkptName string, DisplayJobName string) (string, error) { | func getGpuModelSafetyCommand(BootFile string, params string, CkptName string, DisplayJobName string) (string, error) { | ||||