Browse Source

实现删除接口。

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

+ 86
- 45
routers/repo/aisafety.go View File

@@ -21,6 +21,7 @@ import (
"code.gitea.io/gitea/modules/modelarts"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/cloudbrain/resource"
"code.gitea.io/gitea/services/reward/point/account"
@@ -88,6 +89,65 @@ func GetAiSafetyTask(ctx *context.Context) {
}

func StopAiSafetyTask(ctx *context.Context) {
var ID = ctx.Params(":jobid")
task, err := models.GetCloudbrainByJobIDWithDeleted(ID)
result := make(map[string]interface{})
result["code"] = -1
if err != nil {
log.Error("GetCloudbrainByJobID failed:" + err.Error())
result["msg"] = "No such task."
ctx.JSON(200, result)
return
}
if isTaskNotFinished(task.Status) {
if task.Type == models.TypeCloudBrainTwo {
//queryTaskStatusFromCloudbrainTwo(job)
} else if task.Type == models.TypeCloudBrainOne {
if task.Status == string(models.JobStopped) || task.Status == string(models.JobFailed) || task.Status == string(models.JobSucceeded) {
log.Error("the job(%s) has been stopped", task.JobName, ctx.Data["msgID"])
result["msg"] = "cloudbrain.Already_stopped"
ctx.JSON(200, result)
return
}
err := cloudbrain.StopJob(task.JobID)
if err != nil {
log.Error("StopJob(%s) failed:%v", task.JobName, err, ctx.Data["msgID"])
result["msg"] = "cloudbrain.Stopped_failed"
ctx.JSON(200, result)
return
}
task.Status = string(models.JobStopped)
if task.EndTime == 0 {
task.EndTime = timeutil.TimeStampNow()
}
task.ComputeAndSetDuration()
err = models.UpdateJob(task)
if err != nil {
log.Error("UpdateJob(%s) failed:%v", task.JobName, err, ctx.Data["msgID"])
result["msg"] = "cloudbrain.Stopped_success_update_status_fail"
ctx.JSON(200, result)
return
}
}
} else {
if task.Status == string(models.ModelSafetyTesting) {
//修改为Failed
task.Status = string(models.JobStopped)
if task.EndTime == 0 {
task.EndTime = timeutil.TimeStampNow()
}
task.ComputeAndSetDuration()
err = models.UpdateJob(task)
if err != nil {
log.Error("UpdateJob(%s) failed:%v", task.JobName, err, ctx.Data["msgID"])
result["msg"] = "cloudbrain.Stopped_success_update_status_fail"
ctx.JSON(200, result)
return
}
} else {
log.Info("The job is finished. status=" + task.Status)
}
}

}

@@ -108,6 +168,9 @@ func DelAiSafetyTask(ctx *context.Context) {
ctx.JSON(200, result)
return
}
if task.Type == models.TypeCloudBrainOne {
DeleteCloudbrainJobStorage(task.JobName, models.TypeCloudBrainOne)
}
err = models.DeleteJob(task)
if err != nil {
result["msg"] = err.Error()
@@ -511,24 +574,24 @@ func AiSafetyCreateForPost(ctx *context.Context) {

func createForNPU(ctx *context.Context, jobName string) {
VersionOutputPath := modelarts.GetOutputPathByCount(modelarts.TotalVersionCount)
BootFile := ctx.Query("BootFile")
displayJobName := ctx.Query("DisplayJobName")
description := ctx.Query("Description")
engineID := ctx.QueryInt("EngineID")
poolID := ctx.Query("PoolID")
//image := strings.TrimSpace(ctx.Query("Image"))
srcDataset := ctx.Query("srcDataset") //uuid
combatDataset := ctx.Query("combatDataset") //uuid
BootFile := ctx.Query("boot_file")
displayJobName := ctx.Query("display_job_name")
description := ctx.Query("description")

srcDataset := ctx.Query("src_dataset") //uuid
combatDataset := ctx.Query("combat_dataset") //uuid
evaluationIndex := ctx.Query("evaluationIndex")
Params := ctx.Query("RunParaList")
specId := ctx.QueryInt64("SpecId")
Params := ctx.Query("run_para_list")
specId := ctx.QueryInt64("spec_id")

engineID := ctx.QueryInt("EngineID")
poolID := ctx.Query("PoolID")
repo := ctx.Repo.Repository

trainUrl := ctx.Query("TrainUrl")
trainUrl := ctx.Query("train_url")
modelName := ctx.Query("ModelName")
modelVersion := ctx.Query("ModelVersion")
ckptName := ctx.Query("CkptName")
ckptName := ctx.Query("ckpt_name")
ckptUrl := "/" + trainUrl + ckptName
log.Info("ckpt url:" + ckptUrl)

@@ -828,43 +891,21 @@ func getGpuModelSafetyCommand(BootFile string, params string, CkptName string, D

func modelSafetyNewDataPrepare(ctx *context.Context) error {
ctx.Data["PageIsCloudBrain"] = true
t := time.Now()
var displayJobName = jobNamePrefixValid(cutString(ctx.User.Name, 5)) + t.Format("2006010215") + strconv.Itoa(int(t.Unix()))[5:]
ctx.Data["display_job_name"] = displayJobName

ctx.Data["command"] = cloudbrain.GetCloudbrainDebugCommand()
ctx.Data["code_path"] = cloudbrain.CodeMountPath
ctx.Data["dataset_path"] = cloudbrain.DataSetMountPath
ctx.Data["model_path"] = cloudbrain.ModelMountPath
ctx.Data["benchmark_path"] = cloudbrain.BenchMarkMountPath
ctx.Data["is_benchmark_enabled"] = setting.IsBenchmarkEnabled

if categories == nil {
json.Unmarshal([]byte(setting.BenchmarkCategory), &categories)
}
ctx.Data["benchmark_categories"] = categories.Category

ctx.Data["benchmark_types"] = GetBenchmarkTypes(ctx).BenchmarkType
queuesDetail, _ := cloudbrain.GetQueuesDetail()
if queuesDetail != nil {
ctx.Data["QueuesDetail"] = queuesDetail
}
ctx.Data["boot_file"] = ctx.Query("boot_file")
ctx.Data["display_job_name"] = ctx.Query("display_job_name")
ctx.Data["description"] = ctx.Query("description")
ctx.Data["image"] = strings.TrimSpace(ctx.Query("image"))
ctx.Data["src_dataset"] = ctx.Query("src_dataset") //uuid
ctx.Data["combat_dataset"] = ctx.Query("combat_dataset") //uuid
ctx.Data["evaluationIndex"] = ctx.Query("evaluationIndex")
ctx.Data["run_para_list"] = ctx.Query("run_para_list")
ctx.Data["spec_id"] = ctx.QueryInt64("spec_id")
ctx.Data["train_url"] = ctx.Query("train_url")
ctx.Data["ckpt_name"] = ctx.Query("ckpt_name")

prepareCloudbrainOneSpecs(ctx)

ctx.Data["params"] = ""
ctx.Data["branchName"] = ctx.Repo.BranchName

ctx.Data["snn4imagenet_path"] = cloudbrain.Snn4imagenetMountPath
ctx.Data["is_snn4imagenet_enabled"] = setting.IsSnn4imagenetEnabled

ctx.Data["brainscore_path"] = cloudbrain.BrainScoreMountPath
ctx.Data["is_brainscore_enabled"] = setting.IsBrainScoreEnabled

ctx.Data["datasetType"] = models.TypeCloudBrainOne

ctx.Data["benchmarkMode"] = ctx.Query("benchmarkMode")

return nil
}



Loading…
Cancel
Save