Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.10.1^2
zouap 3 years ago
parent
commit
434c23b380
1 changed files with 36 additions and 54 deletions
  1. +36
    -54
      routers/repo/aisafety.go

+ 36
- 54
routers/repo/aisafety.go View File

@@ -637,19 +637,30 @@ func AiSafetyCreateForPost(ctx *context.Context) {
ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tpname, nil)
return
}
errstr := ""
if taskType == models.TypeCloudBrainTwo {
ctx.Data["datasetType"] = models.TypeCloudBrainTwo
createForNPU(ctx, jobName)
errstr = createForNPU(ctx, jobName)
if errstr != "" {
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr(errstr, tplCloudBrainModelSafetyNewNpu, nil)
return
}
} else if taskType == models.TypeCloudBrainOne {
ctx.Data["datasetType"] = models.TypeCloudBrainOne
createForGPU(ctx, jobName)
errstr = createForGPU(ctx, jobName)
if errstr != "" {
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr(errstr, tplCloudBrainModelSafetyNewGpu, nil)
return
}
}

log.Info("to redirect...")
ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain/benchmark")
}

func createForNPU(ctx *context.Context, jobName string) {
func createForNPU(ctx *context.Context, jobName string) string {
VersionOutputPath := modelarts.GetOutputPathByCount(modelarts.TotalVersionCount)
BootFile := ctx.Query("boot_file")
displayJobName := ctx.Query("display_job_name")
@@ -690,15 +701,13 @@ func createForNPU(ctx *context.Context, jobName string) {
Cluster: models.OpenICluster,
AiCenterCode: models.AICenterOfCloudBrainTwo})
if err != nil || spec == nil {
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr("Resource specification not available", tplCloudBrainModelSafetyNewNpu, nil)
return
//ctx.RenderWithErr("Resource specification not available", tplCloudBrainModelSafetyNewNpu, nil)
return "Resource specification not available"
}
if !account.IsPointBalanceEnough(ctx.User.ID, spec.UnitPrice) {
log.Error("point balance is not enough,userId=%d specId=%d ", ctx.User.ID, spec.ID)
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr(ctx.Tr("points.insufficient_points_balance"), tplCloudBrainModelSafetyNewNpu, nil)
return
return ctx.Tr("points.insufficient_points_balance")
}

//todo: del the codeLocalPath
@@ -712,31 +721,23 @@ func createForNPU(ctx *context.Context, jobName string) {

if err := downloadCode(repo, codeLocalPath, cloudbrain.DefaultBranchName); err != nil {
log.Error("Create task failed, server timed out: %s (%v)", repo.FullName(), err)
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplCloudBrainModelSafetyNewNpu, nil)
return
return ctx.Tr("cloudbrain.load_code_failed")
}

//todo: upload code (send to file_server todo this work?)
if err := obsMkdir(setting.CodePathPrefix + jobName + modelarts.ResultPath + VersionOutputPath + "/"); err != nil {
log.Error("Failed to obsMkdir_result: %s (%v)", repo.FullName(), err)
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr("Failed to obsMkdir_result", tplCloudBrainModelSafetyNewNpu, nil)
return
return "Failed to obsMkdir_result"
}

if err := obsMkdir(setting.CodePathPrefix + jobName + modelarts.LogPath + VersionOutputPath + "/"); err != nil {
log.Error("Failed to obsMkdir_log: %s (%v)", repo.FullName(), err)
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr("Failed to obsMkdir_log", tplCloudBrainModelSafetyNewNpu, nil)
return
return "Failed to obsMkdir_log"
}

if err := uploadCodeToObs(codeLocalPath, jobName, ""); err != nil {
log.Error("Failed to uploadCodeToObs: %s (%v)", repo.FullName(), err)
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplCloudBrainModelSafetyNewNpu, nil)
return
return ctx.Tr("cloudbrain.load_code_failed")
}

var parameters models.Parameters
@@ -751,17 +752,13 @@ func createForNPU(ctx *context.Context, jobName string) {
uuid := srcDataset + ";" + combatDataset
datasUrlList, dataUrl, datasetNames, isMultiDataset, err := getDatasUrlListByUUIDS(uuid)
if err != nil {
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr(err.Error(), tplCloudBrainModelSafetyNewNpu, nil)
return
return err.Error()
}
dataPath := dataUrl
jsondatas, err := json.Marshal(datasUrlList)
if err != nil {
log.Error("Failed to Marshal: %v", err)
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr("json error:"+err.Error(), tplCloudBrainModelSafetyNewNpu, nil)
return
return "json error:" + err.Error()
}
if isMultiDataset {
param = append(param, models.Parameter{
@@ -775,9 +772,7 @@ func createForNPU(ctx *context.Context, jobName string) {
err := json.Unmarshal([]byte(Params), &parameters)
if err != nil {
log.Error("Failed to Unmarshal params: %s (%v)", Params, err)
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr("运行参数错误", tplCloudBrainModelSafetyNewNpu, nil)
return
return "运行参数错误"
}

for _, parameter := range parameters.Parameter {
@@ -835,13 +830,12 @@ func createForNPU(ctx *context.Context, jobName string) {
err = modelarts.GenerateInferenceJob(ctx, req)
if err != nil {
log.Error("GenerateTrainJob failed:%v", err.Error())
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr(err.Error(), tplCloudBrainModelSafetyNewNpu, nil)
return
return err.Error()
}
return ""
}

func createForGPU(ctx *context.Context, jobName string) {
func createForGPU(ctx *context.Context, jobName string) string {
BootFile := ctx.Query("boot_file")
displayJobName := ctx.Query("display_job_name")
description := ctx.Query("description")
@@ -864,9 +858,7 @@ func createForGPU(ctx *context.Context, jobName string) {
Cluster: models.OpenICluster,
AiCenterCode: models.AICenterOfCloudBrainOne})
if err != nil || spec == nil {
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr("Resource specification not available", tplCloudBrainModelSafetyNewGpu, nil)
return
return "Resource specification not available"
}

repo := ctx.Repo.Repository
@@ -875,17 +867,13 @@ func createForGPU(ctx *context.Context, jobName string) {

if err := downloadCode(repo, codePath, cloudbrain.DefaultBranchName); err != nil {
log.Error("downloadCode failed, %v", err, ctx.Data["MsgID"])
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr("system error", tplCloudBrainModelSafetyNewGpu, nil)
return
return "system error"
}

err = uploadCodeToMinio(codePath+"/", jobName, cloudbrain.CodeMountPath+"/")
if err != nil {
log.Error("uploadCodeToMinio failed, %v", err, ctx.Data["MsgID"])
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr("system error", tplCloudBrainModelSafetyNewGpu, nil)
return
return "system error"
}

uuid := srcDataset + ";" + combatDataset
@@ -893,16 +881,12 @@ func createForGPU(ctx *context.Context, jobName string) {
log.Info("uuid=" + uuid)
if err != nil {
log.Error("GetDatasetInfo failed: %v", err, ctx.Data["MsgID"])
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr(ctx.Tr("cloudbrain.error.dataset_select"), tplCloudBrainBenchmarkNew, nil)
return
return ctx.Tr("cloudbrain.error.dataset_select")
}
command, err := getGpuModelSafetyCommand(BootFile, Params, CkptName, displayJobName)
if err != nil {
log.Error("Get Command failed: %v", err, ctx.Data["MsgID"])
modelSafetyNewDataPrepare(ctx)
//ctx.RenderWithErr(ctx.Tr("cloudbrain.error.dataset_select"), tplCloudBrainBenchmarkNew, nil) TODO
return
return ctx.Tr("cloudbrain.error.dataset_select")
}
log.Info("Command=" + command)

@@ -936,11 +920,9 @@ func createForGPU(ctx *context.Context, jobName string) {

err = cloudbrain.GenerateTask(req)
if err != nil {
modelSafetyNewDataPrepare(ctx)
ctx.RenderWithErr(err.Error(), tplCloudBrainBenchmarkNew, nil)
return
return err.Error()
}
//ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain/modelsafety_test")
return ""
}

func getGpuModelSafetyCommand(BootFile string, params string, CkptName string, DisplayJobName string) (string, error) {


Loading…
Cancel
Save