From 7f4531c4e386cbc339e6842566639673ef4dc101 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 29 Sep 2022 16:46:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A8=A1=E6=9D=BF=E5=90=8D=E7=A7=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/aisafety.go | 83 ++++++++++++++++++++++++++++---------- routers/repo/cloudbrain.go | 3 +- routers/routes/routes.go | 3 +- 3 files changed, 65 insertions(+), 24 deletions(-) diff --git a/routers/repo/aisafety.go b/routers/repo/aisafety.go index ab4065916..0ee54f535 100644 --- a/routers/repo/aisafety.go +++ b/routers/repo/aisafety.go @@ -28,7 +28,8 @@ import ( ) const ( - tplModelSafetyTestCreate = "repo/modelsafety/new" + tplModelSafetyTestCreateGpu = "repo/modelsafety/newgpu" + tplModelSafetyTestCreateNpu = "repo/modelsafety/newnpu" ) func CloudBrainAiSafetyCreateTest(ctx *context.Context) { @@ -309,13 +310,46 @@ func DelAiSafetyTask(ctx *context.Context) { } -func AiSafetyCreateForGet(ctx *context.Context) { +func AiSafetyCreateForGetGPU(ctx *context.Context) { ctx.Data["PageIsCloudBrain"] = true + ctx.Data["IsCreate"] = true ctx.Data["BaseDataSetName"] = setting.ModelSafetyTest.BaseDataSetName ctx.Data["BaseDataSetUUID"] = setting.ModelSafetyTest.BaseDataSetUUID ctx.Data["CombatDataSetName"] = setting.ModelSafetyTest.CombatDataSetName ctx.Data["CombatDataSetUUID"] = setting.ModelSafetyTest.CombatDataSetUUID - ctx.HTML(200, tplModelSafetyTestCreate) + prepareCloudbrainOneSpecs(ctx) + ctx.HTML(200, tplModelSafetyTestCreateGpu) +} + +func AiSafetyCreateForGetNPU(ctx *context.Context) { + ctx.Data["PageIsCloudBrain"] = true + ctx.Data["IsCreate"] = true + ctx.Data["BaseDataSetName"] = setting.ModelSafetyTest.BaseDataSetName + ctx.Data["BaseDataSetUUID"] = setting.ModelSafetyTest.BaseDataSetUUID + ctx.Data["CombatDataSetName"] = setting.ModelSafetyTest.CombatDataSetName + ctx.Data["CombatDataSetUUID"] = setting.ModelSafetyTest.CombatDataSetUUID + + var resourcePools modelarts.ResourcePool + if err := json.Unmarshal([]byte(setting.ResourcePools), &resourcePools); err != nil { + ctx.ServerError("json.Unmarshal failed:", err) + } + ctx.Data["resource_pools"] = resourcePools.Info + + var engines modelarts.Engine + if err := json.Unmarshal([]byte(setting.Engines), &engines); err != nil { + ctx.ServerError("json.Unmarshal failed:", err) + } + ctx.Data["engines"] = engines.Info + + var versionInfos modelarts.VersionInfo + if err := json.Unmarshal([]byte(setting.EngineVersions), &versionInfos); err != nil { + ctx.ServerError("json.Unmarshal failed:", err) + } + ctx.Data["engine_versions"] = versionInfos.Version + + prepareCloudbrainTwoInferenceSpecs(ctx) + + ctx.HTML(200, tplModelSafetyTestCreateNpu) } func AiSafetyCreateForPost(ctx *context.Context) { @@ -329,26 +363,31 @@ func AiSafetyCreateForPost(ctx *context.Context) { repo := ctx.Repo.Repository + tpname := tplCloudBrainModelSafetyNewNpu + if taskType == models.TypeCloudBrainOne { + tpname = tplCloudBrainModelSafetyNewGpu + } + tasks, err := models.GetCloudbrainsByDisplayJobName(repo.ID, string(models.JobTypeModelSafety), displayJobName) if err == nil { if len(tasks) != 0 { log.Error("the job name did already exist", ctx.Data["MsgID"]) modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr("the job name did already exist", tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr("the job name did already exist", tpname, nil) return } } else { if !models.IsErrJobNotExist(err) { log.Error("system error, %v", err, ctx.Data["MsgID"]) modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr("system error", tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr("system error", tpname, nil) return } } if !jobNamePattern.MatchString(jobName) { modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_jobname_err"), tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_jobname_err"), tpname, nil) return } @@ -356,13 +395,13 @@ func AiSafetyCreateForPost(ctx *context.Context) { if err != nil { log.Error("GetCloudbrainCountByUserID failed:%v", err, ctx.Data["MsgID"]) modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr("system error", tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr("system error", tpname, nil) return } else { if count >= 1 { log.Error("the user already has running or waiting task", ctx.Data["MsgID"]) modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr(ctx.Tr("repo.cloudbrain.morethanonejob"), tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr(ctx.Tr("repo.cloudbrain.morethanonejob"), tpname, nil) return } } @@ -371,7 +410,7 @@ func AiSafetyCreateForPost(ctx *context.Context) { if err != nil || !bootFileExist { log.Error("Get bootfile error:", err) modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tplModelArtsInferenceJobNew, nil) + ctx.RenderWithErr(ctx.Tr("repo.cloudbrain_bootfile_err"), tpname, nil) return } @@ -424,13 +463,13 @@ func createForNPU(ctx *context.Context, jobName string) { AiCenterCode: models.AICenterOfCloudBrainTwo}) if err != nil || spec == nil { modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr("Resource specification not available", tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr("Resource specification not available", tplCloudBrainModelSafetyNewNpu, nil) return } 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"), tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr(ctx.Tr("points.insufficient_points_balance"), tplCloudBrainModelSafetyNewNpu, nil) return } @@ -446,7 +485,7 @@ 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"), tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplCloudBrainModelSafetyNewNpu, nil) return } @@ -454,21 +493,21 @@ func createForNPU(ctx *context.Context, jobName string) { 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", tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr("Failed to obsMkdir_result", tplCloudBrainModelSafetyNewNpu, nil) return } 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", tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr("Failed to obsMkdir_log", tplCloudBrainModelSafetyNewNpu, nil) return } 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"), tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr(ctx.Tr("cloudbrain.load_code_failed"), tplCloudBrainModelSafetyNewNpu, nil) return } @@ -485,7 +524,7 @@ func createForNPU(ctx *context.Context, jobName string) { datasUrlList, dataUrl, datasetNames, isMultiDataset, err := getDatasUrlListByUUIDS(uuid) if err != nil { modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr(err.Error(), tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr(err.Error(), tplCloudBrainModelSafetyNewNpu, nil) return } dataPath := dataUrl @@ -493,7 +532,7 @@ func createForNPU(ctx *context.Context, jobName string) { if err != nil { log.Error("Failed to Marshal: %v", err) modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr("json error:"+err.Error(), tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr("json error:"+err.Error(), tplCloudBrainModelSafetyNewNpu, nil) return } if isMultiDataset { @@ -509,7 +548,7 @@ func createForNPU(ctx *context.Context, jobName string) { if err != nil { log.Error("Failed to Unmarshal params: %s (%v)", Params, err) modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr("运行参数错误", tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr("运行参数错误", tplCloudBrainModelSafetyNewNpu, nil) return } @@ -569,7 +608,7 @@ func createForNPU(ctx *context.Context, jobName string) { if err != nil { log.Error("GenerateTrainJob failed:%v", err.Error()) modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr(err.Error(), tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr(err.Error(), tplCloudBrainModelSafetyNewNpu, nil) return } } @@ -595,7 +634,7 @@ func createForGPU(ctx *context.Context, jobName string) { AiCenterCode: models.AICenterOfCloudBrainOne}) if err != nil || spec == nil { modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr("Resource specification not available", tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr("Resource specification not available", tplCloudBrainModelSafetyNewGpu, nil) return } @@ -606,7 +645,7 @@ 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", tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr("system error", tplCloudBrainModelSafetyNewGpu, nil) return } @@ -614,7 +653,7 @@ func createForGPU(ctx *context.Context, jobName string) { if err != nil { log.Error("uploadCodeToMinio failed, %v", err, ctx.Data["MsgID"]) modelSafetyNewDataPrepare(ctx) - ctx.RenderWithErr("system error", tplCloudBrainModelSafetyNew, nil) + ctx.RenderWithErr("system error", tplCloudBrainModelSafetyNewGpu, nil) return } diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index f24d33cd0..1f6732174 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -51,7 +51,8 @@ const ( tplCloudBrainBenchmarkNew base.TplName = "repo/cloudbrain/benchmark/new" tplCloudBrainBenchmarkShow base.TplName = "repo/cloudbrain/benchmark/show" - tplCloudBrainModelSafetyNew base.TplName = "repo/cloudbrain/modelsafety/new" + tplCloudBrainModelSafetyNewGpu base.TplName = "repo/cloudbrain/modelsafety/newgpu" + tplCloudBrainModelSafetyNewNpu base.TplName = "repo/cloudbrain/modelsafety/newnpu" tplCloudBrainImageSubmit base.TplName = "repo/cloudbrain/image/submit" tplCloudBrainImageEdit base.TplName = "repo/cloudbrain/image/edit" diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 09f6a1b1c..e249fafbe 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -1233,7 +1233,8 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.StopAiSafetyTask) m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.DelAiSafetyTask) }) - m.Get("/create", reqWechatBind, reqRepoCloudBrainWriter, repo.AiSafetyCreateForGet) + m.Get("/create_gpu", reqWechatBind, reqRepoCloudBrainWriter, repo.AiSafetyCreateForGetGPU) + m.Get("/create_npu", reqWechatBind, reqRepoCloudBrainWriter, repo.AiSafetyCreateForGetNPU) m.Post("/create", reqWechatBind, reqRepoCloudBrainWriter, repo.AiSafetyCreateForPost) }, context.RepoRef())