|
|
|
@@ -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 |
|
|
|
} |
|
|
|
|
|
|
|
|