你确认删除该任务么?此任务一旦删除不可恢复。
-diff --git a/modules/modelarts/modelarts.go b/modules/modelarts/modelarts.go index a64c317a8..273d59012 100755 --- a/modules/modelarts/modelarts.go +++ b/modules/modelarts/modelarts.go @@ -48,8 +48,12 @@ const ( PerPage = 10 IsLatestVersion = "1" NotLatestVersion = "0" - ComputeResource = "NPU" - VersionCount = 1 + // ComputeResource = "NPU" + NPUResource = "NPU" + GPUResource = "CPU/GPU" + AllResource = "all" + DebugType = -1 + VersionCount = 1 SortByCreateTime = "create_time" ConfigTypeCustom = "custom" @@ -273,7 +277,7 @@ func GenerateTrainJob(ctx *context.Context, req *GenerateTrainJobReq) (err error DatasetName: attach.Name, CommitID: req.CommitID, IsLatestVersion: req.IsLatestVersion, - ComputeResource: ComputeResource, + ComputeResource: NPUResource, EngineID: req.EngineID, TrainUrl: req.TrainUrl, BranchName: req.BranchName, @@ -356,7 +360,7 @@ func GenerateTrainJobVersion(ctx *context.Context, req *GenerateTrainJobReq, job CommitID: req.CommitID, IsLatestVersion: req.IsLatestVersion, PreVersionName: req.PreVersionName, - ComputeResource: ComputeResource, + ComputeResource: NPUResource, EngineID: req.EngineID, TrainUrl: req.TrainUrl, BranchName: req.BranchName, diff --git a/routers/api/v1/repo/modelarts.go b/routers/api/v1/repo/modelarts.go index b4d5fc010..a18da3fe5 100755 --- a/routers/api/v1/repo/modelarts.go +++ b/routers/api/v1/repo/modelarts.go @@ -240,26 +240,28 @@ func DelTrainJobVersion(ctx *context.APIContext) { ctx.ServerError("get VersionListCount faild", err) return } - - // 判断当前删掉的任务是否是最新版本,若是,将排序后的TotalVersionCount置为删掉的最新版本的TotalVersionCount,若不是,按时间排序后的版本列表的第一个版本设置为最新版本,TotalVersionCount不变 - if task.IsLatestVersion == modelarts.IsLatestVersion { - err = models.SetVersionCountAndLatestVersion(jobID, VersionTaskList[0].Cloudbrain.VersionName, VersionListCount, modelarts.IsLatestVersion, task.TotalVersionCount) - if err != nil { - ctx.ServerError("UpdateJobVersionCount failed", err) - return - } - } else { - err = models.SetVersionCountAndLatestVersion(jobID, VersionTaskList[0].VersionName, VersionListCount, modelarts.IsLatestVersion, VersionTaskList[0].Cloudbrain.TotalVersionCount) - if err != nil { - ctx.ServerError("UpdateJobVersionCount failed", err) - return + if VersionListCount > 0 { + // 判断当前删掉的任务是否是最新版本,若是,将排序后的TotalVersionCount置为删掉的最新版本的TotalVersionCount,若不是,按时间排序后的版本列表的第一个版本设置为最新版本,TotalVersionCount不变 + if task.IsLatestVersion == modelarts.IsLatestVersion { + err = models.SetVersionCountAndLatestVersion(jobID, VersionTaskList[0].Cloudbrain.VersionName, VersionListCount, modelarts.IsLatestVersion, task.TotalVersionCount) + if err != nil { + ctx.ServerError("UpdateJobVersionCount failed", err) + return + } + } else { + err = models.SetVersionCountAndLatestVersion(jobID, VersionTaskList[0].VersionName, VersionListCount, modelarts.IsLatestVersion, VersionTaskList[0].Cloudbrain.TotalVersionCount) + if err != nil { + ctx.ServerError("UpdateJobVersionCount failed", err) + return + } } } ctx.JSON(http.StatusOK, map[string]interface{}{ - "JobID": jobID, - "VersionName": versionName, - "StatusOK": 0, + "JobID": jobID, + "VersionName": versionName, + "StatusOK": 0, + "VersionListCount": VersionListCount, }) } diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 256bc9e6d..3f5fce013 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -49,42 +49,6 @@ func MustEnableCloudbrain(ctx *context.Context) { return } } -func CloudBrainIndex(ctx *context.Context) { - MustEnableCloudbrain(ctx) - repo := ctx.Repo.Repository - page := ctx.QueryInt("page") - if page <= 0 { - page = 1 - } - - ciTasks, count, err := models.Cloudbrains(&models.CloudbrainsOptions{ - ListOptions: models.ListOptions{ - Page: page, - PageSize: setting.UI.IssuePagingNum, - }, - RepoID: repo.ID, - Type: models.TypeCloudBrainOne, - }) - if err != nil { - ctx.ServerError("Cloudbrain", err) - return - } - - for i, task := range ciTasks { - ciTasks[i].CanDebug = cloudbrain.CanCreateOrDebugJob(ctx) - ciTasks[i].CanDel = cloudbrain.CanDeleteJob(ctx, &task.Cloudbrain) - - } - - pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5) - pager.SetDefaultParams(ctx) - ctx.Data["Page"] = pager - - ctx.Data["PageIsCloudBrain"] = true - ctx.Data["Tasks"] = ciTasks - ctx.Data["CanCreate"] = cloudbrain.CanCreateOrDebugJob(ctx) - ctx.HTML(200, tplCloudBrainIndex) -} func cutString(str string, lens int) string { if len(str) < lens { @@ -242,11 +206,11 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { } repo := ctx.Repo.Repository downloadCode(repo, codePath) - uploadCodeToMinio(codePath + "/", jobName, "/code/") + uploadCodeToMinio(codePath+"/", jobName, "/code/") modelPath := setting.JobPath + jobName + cloudbrain.ModelMountPath + "/" mkModelPath(modelPath) - uploadCodeToMinio(modelPath, jobName, cloudbrain.ModelMountPath + "/") + uploadCodeToMinio(modelPath, jobName, cloudbrain.ModelMountPath+"/") benchmarkPath := setting.JobPath + jobName + cloudbrain.BenchMarkMountPath if setting.IsBenchmarkEnabled && jobType == string(models.JobTypeBenchmark) { @@ -257,30 +221,30 @@ func CloudBrainCreate(ctx *context.Context, form auth.CreateCloudBrainForm) { } } downloadRateCode(repo, jobName, setting.BenchmarkOwner, setting.BrainScoreName, benchmarkPath, form.BenchmarkCategory, gpuType) - uploadCodeToMinio(benchmarkPath + "/", jobName, cloudbrain.BenchMarkMountPath + "/") + uploadCodeToMinio(benchmarkPath+"/", jobName, cloudbrain.BenchMarkMountPath+"/") } snn4imagenetPath := setting.JobPath + jobName + cloudbrain.Snn4imagenetMountPath if setting.IsSnn4imagenetEnabled && jobType == string(models.JobTypeSnn4imagenet) { downloadRateCode(repo, jobName, setting.Snn4imagenetOwner, setting.Snn4imagenetName, snn4imagenetPath, "", "") - uploadCodeToMinio(snn4imagenetPath + "/", jobName, cloudbrain.Snn4imagenetMountPath + "/") + uploadCodeToMinio(snn4imagenetPath+"/", jobName, cloudbrain.Snn4imagenetMountPath+"/") } brainScorePath := setting.JobPath + jobName + cloudbrain.BrainScoreMountPath if setting.IsBrainScoreEnabled && jobType == string(models.JobTypeBrainScore) { downloadRateCode(repo, jobName, setting.BrainScoreOwner, setting.BrainScoreName, brainScorePath, "", "") - uploadCodeToMinio(brainScorePath + "/", jobName, cloudbrain.BrainScoreMountPath + "/") + uploadCodeToMinio(brainScorePath+"/", jobName, cloudbrain.BrainScoreMountPath+"/") } - err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, getMinioPath(jobName, cloudbrain.ModelMountPath + "/"), - getMinioPath(jobName, cloudbrain.BenchMarkMountPath + "/"), getMinioPath(jobName, cloudbrain.Snn4imagenetMountPath + "/"), - getMinioPath(jobName, cloudbrain.BrainScoreMountPath + "/"), jobType, gpuQueue, resourceSpecId) + err = cloudbrain.GenerateTask(ctx, jobName, image, command, uuid, codePath, getMinioPath(jobName, cloudbrain.ModelMountPath+"/"), + getMinioPath(jobName, cloudbrain.BenchMarkMountPath+"/"), getMinioPath(jobName, cloudbrain.Snn4imagenetMountPath+"/"), + getMinioPath(jobName, cloudbrain.BrainScoreMountPath+"/"), jobType, gpuQueue, resourceSpecId) if err != nil { cloudBrainNewDataPrepare(ctx) ctx.RenderWithErr(err.Error(), tplCloudBrainNew, &form) return } - ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") + ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob") } func CloudBrainShow(ctx *context.Context) { @@ -412,8 +376,7 @@ func CloudBrainStop(ctx *context.Context) { ctx.ServerError("UpdateJob failed", err) return } - - ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") + ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob") } func StopJobsByUserID(userID int64) { @@ -515,8 +478,7 @@ func CloudBrainDel(ctx *context.Context) { ctx.ServerError("DeleteJob failed", err) return } - - ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/cloudbrain") + ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob") } func CloudBrainShowModels(ctx *context.Context) { @@ -598,7 +560,7 @@ func getImages(ctx *context.Context, imageType string) { func GetModelDirs(jobName string, parentDir string) (string, error) { var req string - modelActualPath := getMinioPath(jobName, cloudbrain.ModelMountPath + "/") + modelActualPath := getMinioPath(jobName, cloudbrain.ModelMountPath+"/") if parentDir == "" { req = "baseDir=" + modelActualPath } else { @@ -794,7 +756,6 @@ func mkModelPath(modelPath string) error { return nil } - func SyncCloudbrainStatus() { cloudBrains, err := models.GetCloudBrainUnStoppedJob() if err != nil { diff --git a/routers/repo/modelarts.go b/routers/repo/modelarts.go index 3994ba542..1d8323000 100755 --- a/routers/repo/modelarts.go +++ b/routers/repo/modelarts.go @@ -28,6 +28,8 @@ import ( ) const ( + tplDebugJobIndex base.TplName = "repo/debugjob/index" + tplModelArtsNotebookIndex base.TplName = "repo/modelarts/notebook/index" tplModelArtsNotebookNew base.TplName = "repo/modelarts/notebook/new" tplModelArtsNotebookShow base.TplName = "repo/modelarts/notebook/show" @@ -38,21 +40,23 @@ const ( tplModelArtsTrainJobVersionNew base.TplName = "repo/modelarts/trainjob/version_new" ) -// MustEnableDataset check if repository enable internal cb -func MustEnableModelArts(ctx *context.Context) { - if !ctx.Repo.CanRead(models.UnitTypeCloudBrain) { - ctx.NotFound("MustEnableCloudbrain", nil) - return - } -} - -func NotebookIndex(ctx *context.Context) { - MustEnableModelArts(ctx) +func DebugJobIndex(ctx *context.Context) { + debugListType := ctx.Query("debugListType") + MustEnableCloudbrain(ctx) repo := ctx.Repo.Repository page := ctx.QueryInt("page") if page <= 0 { page = 1 } + debugType := modelarts.DebugType + jobType := string(models.JobTypeDebug) + if debugListType == modelarts.GPUResource { + debugType = models.TypeCloudBrainOne + jobType = "" + } + if debugListType == modelarts.NPUResource { + debugType = models.TypeCloudBrainTwo + } ciTasks, count, err := models.Cloudbrains(&models.CloudbrainsOptions{ ListOptions: models.ListOptions{ @@ -60,28 +64,43 @@ func NotebookIndex(ctx *context.Context) { PageSize: setting.UI.IssuePagingNum, }, RepoID: repo.ID, - Type: models.TypeCloudBrainTwo, - JobType: string(models.JobTypeDebug), + Type: debugType, + JobType: jobType, }) if err != nil { - ctx.ServerError("Cloudbrain", err) + ctx.ServerError("Get debugjob faild:", err) return } for i, task := range ciTasks { + if task.Cloudbrain.Type == models.TypeCloudBrainOne { + ciTasks[i].CanDebug = cloudbrain.CanCreateOrDebugJob(ctx) + ciTasks[i].CanDel = cloudbrain.CanDeleteJob(ctx, &task.Cloudbrain) + ciTasks[i].Cloudbrain.ComputeResource = modelarts.GPUResource + } + if task.Cloudbrain.Type == models.TypeCloudBrainTwo { + ciTasks[i].CanDebug = cloudbrain.CanCreateOrDebugJob(ctx) + ciTasks[i].CanDel = cloudbrain.CanDeleteJob(ctx, &task.Cloudbrain) + ciTasks[i].Cloudbrain.ComputeResource = modelarts.NPUResource + } - ciTasks[i].CanDebug = cloudbrain.CanCreateOrDebugJob(ctx) - ciTasks[i].CanDel = cloudbrain.CanDeleteJob(ctx, &task.Cloudbrain) } pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5) pager.SetDefaultParams(ctx) ctx.Data["Page"] = pager - ctx.Data["PageIsCloudBrain"] = true ctx.Data["Tasks"] = ciTasks ctx.Data["CanCreate"] = cloudbrain.CanCreateOrDebugJob(ctx) - ctx.HTML(200, tplModelArtsNotebookIndex) + ctx.HTML(200, tplDebugJobIndex) +} + +// MustEnableDataset check if repository enable internal cb +func MustEnableModelArts(ctx *context.Context) { + if !ctx.Repo.CanRead(models.UnitTypeCloudBrain) { + ctx.NotFound("MustEnableCloudbrain", nil) + return + } } func NotebookNew(ctx *context.Context) { @@ -136,8 +155,7 @@ func NotebookCreate(ctx *context.Context, form auth.CreateModelArtsNotebookForm) ctx.RenderWithErr(err.Error(), tplModelArtsNotebookNew, &form) return } - - ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/notebook") + ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob") } func NotebookShow(ctx *context.Context) { @@ -244,8 +262,7 @@ func NotebookStop(ctx *context.Context) { ctx.ServerError("UpdateJob failed", err) return } - - ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/notebook") + ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob") } func NotebookDel(ctx *context.Context) { @@ -275,7 +292,7 @@ func NotebookDel(ctx *context.Context) { return } - ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/notebook") + ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/debugjob") } func TrainJobIndex(ctx *context.Context) { diff --git a/routers/routes/routes.go b/routers/routes/routes.go index a18fe422c..30e486b98 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -960,7 +960,6 @@ func RegisterRoutes(m *macaron.Macaron) { }, context.RepoRef()) m.Group("/cloudbrain", func() { - m.Get("", reqRepoCloudBrainReader, repo.CloudBrainIndex) m.Group("/:jobid", func() { m.Get("", reqRepoCloudBrainReader, repo.CloudBrainShow) m.Get("/debug", reqRepoCloudBrainWriter, repo.CloudBrainDebug) @@ -992,9 +991,12 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/downloadall", repo.DownloadMultiModelFile) }, context.RepoRef()) + m.Group("/debugjob", func() { + m.Get("", reqRepoCloudBrainReader, repo.DebugJobIndex) + }, context.RepoRef()) + m.Group("/modelarts", func() { m.Group("/notebook", func() { - m.Get("", reqRepoCloudBrainReader, repo.NotebookIndex) m.Group("/:jobid", func() { m.Get("", reqRepoCloudBrainReader, repo.NotebookShow) m.Get("/debug", reqRepoCloudBrainWriter, repo.NotebookDebug) diff --git a/templates/repo/cloudbrain/index.tmpl b/templates/repo/cloudbrain/index.tmpl deleted file mode 100755 index b23021c55..000000000 --- a/templates/repo/cloudbrain/index.tmpl +++ /dev/null @@ -1,641 +0,0 @@ - -{{template "base/head" .}} - - - - -
你确认删除该任务么?此任务一旦删除不可恢复。
-