diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 5bf066413..c3707c9e2 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -19,8 +19,8 @@ type JobType string type ModelArtsJobStatus string const ( - NPUResource = "NPU" - GPUResource = "CPU/GPU" + NPUResource = "NPU" + GPUResource = "CPU/GPU" JobWaiting CloudbrainStatus = "WAITING" JobStopped CloudbrainStatus = "STOPPED" @@ -210,7 +210,7 @@ type CloudbrainsOptions struct { JobType string VersionName string IsLatestVersion string - JobTypeNot bool + JobTypeNot bool } type TaskPod struct { @@ -975,7 +975,9 @@ func QueryModelTrainJobList(repoId int64) ([]*CloudbrainInfo, int, error) { cond = cond.And( builder.Eq{"Status": "COMPLETED"}, ) - + cond = cond.And( + builder.Eq{"job_type": "TRAIN"}, + ) cloudbrains := make([]*CloudbrainInfo, 0) if err := sess.Select("job_id,job_name").Table(&Cloudbrain{}).Where(cond).OrderBy("created_unix DESC"). Find(&cloudbrains); err != nil { diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 272957887..1dceb5c4a 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -844,6 +844,7 @@ modelarts.current_version=Current version modelarts.parent_version=Parent Version modelarts.run_version=Run Version modelarts.train_job.compute_node=Compute Node +modelarts.create_model = Create Model modelarts.train_job.basic_info=Basic Info diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index efa730002..2e7f4d73c 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -849,6 +849,7 @@ modelarts.modify=修改 modelarts.current_version=当前版本 modelarts.parent_version=父版本 modelarts.run_version=运行版本 +modelarts.create_model=创建模型 diff --git a/routers/repo/ai_model_manage.go b/routers/repo/ai_model_manage.go index 669bdf9fa..845dbbc6b 100644 --- a/routers/repo/ai_model_manage.go +++ b/routers/repo/ai_model_manage.go @@ -99,6 +99,18 @@ func saveModelByParameters(jobId string, versionName string, name string, versio //udpate status and version count models.ModifyModelNewProperty(lastNewModelId, MODEL_NOT_LATEST, 0) } + var units []models.RepoUnit + var deleteUnitTypes []models.UnitType + units = append(units, models.RepoUnit{ + RepoID: ctx.Repo.Repository.ID, + Type: models.UnitTypeModelManage, + Config: &models.ModelManageConfig{ + EnableModelManage: true, + }, + }) + deleteUnitTypes = append(deleteUnitTypes, models.UnitTypeModelManage) + + models.UpdateRepositoryUnits(ctx.Repo.Repository, units, deleteUnitTypes) log.Info("save model end.") @@ -130,10 +142,13 @@ func SaveModel(ctx *context.Context) { version := ctx.Query("Version") label := ctx.Query("Label") description := ctx.Query("Description") + trainTaskCreate := ctx.QueryBool("trainTaskCreate") - if !ctx.Repo.CanWrite(models.UnitTypeModelManage) { - ctx.ServerError("No right.", errors.New(ctx.Tr("repo.model_noright"))) - return + if !trainTaskCreate { + if !ctx.Repo.CanWrite(models.UnitTypeModelManage) { + ctx.ServerError("No right.", errors.New(ctx.Tr("repo.model_noright"))) + return + } } if JobId == "" || VersionName == "" { @@ -474,6 +489,23 @@ func ShowOneVersionOtherModel(ctx *context.Context) { func ShowModelTemplate(ctx *context.Context) { ctx.Data["isModelManage"] = true + repoId := ctx.Repo.Repository.ID + Type := -1 + _, count, _ := models.QueryModel(&models.AiModelQueryOptions{ + ListOptions: models.ListOptions{ + Page: 1, + PageSize: 2, + }, + RepoID: repoId, + Type: Type, + New: MODEL_LATEST, + }) + ctx.Data["MODEL_COUNT"] = count + + _, trainCount, _ := models.QueryModelTrainJobList(repoId) + log.Info("query train count=" + fmt.Sprint(trainCount)) + + ctx.Data["TRAIN_COUNT"] = trainCount ctx.HTML(200, tplModelManageIndex) } @@ -586,3 +618,67 @@ func ModifyModelInfo(ctx *context.Context) { } } + +func QueryModelListForPredict(ctx *context.Context) { + repoId := ctx.Repo.Repository.ID + modelResult, count, err := models.QueryModel(&models.AiModelQueryOptions{ + ListOptions: models.ListOptions{ + Page: -1, + PageSize: -1, + }, + RepoID: repoId, + Type: -1, + New: -1, + }) + if err != nil { + ctx.ServerError("Cloudbrain", err) + return + } + log.Info("query return count=" + fmt.Sprint(count)) + + nameList := make([]string, 0) + + nameMap := make(map[string][]*models.AiModelManage) + for _, model := range modelResult { + if _, value := nameMap[model.Name]; !value { + models := make([]*models.AiModelManage, 0) + models = append(models, model) + nameMap[model.Name] = models + nameList = append(nameList, model.Name) + } else { + nameMap[model.Name] = append(nameMap[model.Name], model) + } + } + + mapInterface := make(map[string]interface{}) + mapInterface["nameList"] = nameList + mapInterface["nameMap"] = nameMap + ctx.JSON(http.StatusOK, mapInterface) +} + +func QueryModelFileForPredict(ctx *context.Context) { + id := ctx.Query("ID") + model, err := models.QueryModelById(id) + if err != nil { + log.Error("no such model!", err.Error()) + ctx.ServerError("no such model:", err) + return + } + prefix := model.Path[len(setting.Bucket)+1:] + fileinfos, err := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, prefix) + ctx.JSON(http.StatusOK, fileinfos) +} + +func QueryOneLevelModelFile(ctx *context.Context) { + id := ctx.Query("ID") + parentDir := ctx.Query("parentDir") + model, err := models.QueryModelById(id) + if err != nil { + log.Error("no such model!", err.Error()) + ctx.ServerError("no such model:", err) + return + } + prefix := model.Path[len(setting.Bucket)+1:] + fileinfos, err := storage.GetOneLevelAllObjectUnderDir(setting.Bucket, prefix, parentDir) + ctx.JSON(http.StatusOK, fileinfos) +} diff --git a/routers/routes/routes.go b/routers/routes/routes.go index 481b0eacb..439c17a92 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -982,7 +982,7 @@ func RegisterRoutes(m *macaron.Macaron) { }, context.RepoRef()) m.Group("/modelmanage", func() { m.Post("/create_model", reqRepoModelManageWriter, repo.SaveModel) - m.Post("/create_new_model", reqRepoModelManageWriter, repo.SaveNewNameModel) + m.Post("/create_new_model", repo.SaveNewNameModel) m.Delete("/delete_model", repo.DeleteModel) m.Put("/modify_model", repo.ModifyModelInfo) m.Get("/show_model", reqRepoModelManageReader, repo.ShowModelTemplate) @@ -992,6 +992,9 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/show_model_child_api", repo.ShowOneVersionOtherModel) m.Get("/query_train_job", reqRepoCloudBrainReader, repo.QueryTrainJobList) m.Get("/query_train_job_version", reqRepoCloudBrainReader, repo.QueryTrainJobVersionList) + m.Get("/query_model_for_predict", reqRepoCloudBrainReader, repo.QueryModelListForPredict) + m.Get("/query_modelfile_for_predict", reqRepoCloudBrainReader, repo.QueryModelFileForPredict) + m.Get("/query_onelevel_modelfile", reqRepoCloudBrainReader, repo.QueryOneLevelModelFile) m.Group("/:ID", func() { m.Get("", repo.ShowSingleModel) m.Get("/downloadsingle", repo.DownloadSingleModelFile) diff --git a/templates/repo/debugjob/index.tmpl b/templates/repo/debugjob/index.tmpl index bc8663eab..a50c35eda 100755 --- a/templates/repo/debugjob/index.tmpl +++ b/templates/repo/debugjob/index.tmpl @@ -331,7 +331,7 @@ {{end}} {{else}} - {{if eq .Status "RUNNING"}} + {{if eq .Status "RUNNING" "WAITING" "CREATING" "STARTING"}} {{$.i18n.Tr "repo.debug"}} diff --git a/templates/repo/modelarts/trainjob/show.tmpl b/templates/repo/modelarts/trainjob/show.tmpl index 956853d94..0be93fc8f 100755 --- a/templates/repo/modelarts/trainjob/show.tmpl +++ b/templates/repo/modelarts/trainjob/show.tmpl @@ -161,6 +161,15 @@ td, th { padding-top: 0.5rem ; } +
+
+
+
+
+
+
+
+
{{template "repo/header" .}}
@@ -186,6 +195,12 @@ td, th {
+ {{$.CsrfTokenHtml}} + {{if .CanModify}} + {{$.i18n.Tr "repo.modelarts.create_model"}} + {{else}} + {{$.i18n.Tr "repo.modelarts.create_model"}} + {{end}} {{$.CsrfTokenHtml}} {{if .CanModify}} {{$.i18n.Tr "repo.modelarts.modify"}} @@ -446,6 +461,62 @@ td, th {
+ +
+
{{template "base/footer" .}} @@ -479,7 +550,61 @@ td, th { } let timeid = window.setInterval(loadJobStatus, 30000); $(document).ready(loadJobStatus); - + function showcreate(obj){ + $('.ui.modal.second') + .modal({ + centered: false, + onShow:function(){ + $('input[name="Version"]').addClass('model_disabled') + // $('input[name="JobId"]').text(obj.JobName) + $('#JobName').val(obj.JobName).addClass('model_disabled') + $('input[name="JobId"]').val(obj.JobID) + $('input[name="VersionName"]').val(obj.VersionName).addClass('model_disabled') + $('.ui.dimmer').css({"background-color":"rgb(136, 136, 136,0.7)"}) + createModelName() + + + }, + onHide:function(){ + document.getElementById("formId").reset(); + $('.ui.dimmer').css({"background-color":""}) + $('.ui.error.message').text() + $('.ui.error.message').css('display','none') + + } + }) + .modal('show') + } + function createModel(){ + let url_href = `/${userName}/${repoPath}/modelmanage/create_new_model` + let data = $("#formId").serialize() + $("#mask").css({"display":"block","z-index":"9999"}) + $.ajax({ + url:url_href, + type:'POST', + data:data, + success:function(res){ + location.href=`/${userName}/${repoPath}/modelmanage/show_model` + $('.ui.modal.second').modal('hide') + }, + error: function(xhr){ + // 隐藏 loading + // 只有请求不正常(状态码不为200)才会执行 + $('.ui.error.message').text(xhr.responseText) + $('.ui.error.message').css('display','block') + }, + complete:function(xhr){ + $("#mask").css({"display":"none","z-index":"1"}) + } + }) + + } + function createModelName(){ + let repoName = location.pathname.split('/')[2] + let modelName = repoName + '_model_' + Math.random().toString(36).substr(2, 4) + $('#name').val(modelName) + $('#version').val("0.0.1") + } function renderSize(value){ if(null==value||value==''){ return "0 Bytes"; diff --git a/templates/repo/modelmanage/index.tmpl b/templates/repo/modelmanage/index.tmpl index 5cd7bbcdb..5dd54a6d3 100644 --- a/templates/repo/modelmanage/index.tmpl +++ b/templates/repo/modelmanage/index.tmpl @@ -17,16 +17,30 @@
{{template "repo/header" .}} -
+
{{template "base/alert" .}} - + {{end}}
@@ -89,7 +104,6 @@
-
@@ -103,7 +117,6 @@
-
diff --git a/templates/repo/modelmanage/showinfo.tmpl b/templates/repo/modelmanage/showinfo.tmpl index a6b35500a..e3cbee271 100644 --- a/templates/repo/modelmanage/showinfo.tmpl +++ b/templates/repo/modelmanage/showinfo.tmpl @@ -78,100 +78,121 @@
-
- 基本信息 - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{$.i18n.Tr "repo.model.manage.model_name"}}
{{$.i18n.Tr "repo.model.manage.version"}}
{{$.i18n.Tr "repo.migrate_items_labels"}} -
+ +
+
+ 基本信息 + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{{$.i18n.Tr "repo.model.manage.model_name"}}
{{$.i18n.Tr "repo.model.manage.version"}}
{{$.i18n.Tr "repo.migrate_items_labels"}} +
+ +
- - - -
{{$.i18n.Tr "repo.modelarts.model_size"}}
{{$.i18n.Tr "repo.modelarts.createtime"}}
{{$.i18n.Tr "repo.model.manage.description"}} -
- - -
-
{{$.i18n.Tr "repo.modelarts.code_version"}}
{{$.i18n.Tr "repo.modelarts.train_job.start_file"}}
{{$.i18n.Tr "repo.modelarts.train_job.train_dataset"}}
{{$.i18n.Tr "repo.modelarts.train_job.run_parameter"}}
{{$.i18n.Tr "repo.modelarts.train_job.AI_driver"}}
{{$.i18n.Tr "repo.modelarts.train_job.standard"}}
{{$.i18n.Tr "repo.modelarts.train_job.compute_node"}}
+ +
{{$.i18n.Tr "repo.modelarts.model_size"}}
{{$.i18n.Tr "repo.modelarts.createtime"}}
{{$.i18n.Tr "repo.model.manage.description"}} +
+ + +
+
{{$.i18n.Tr "repo.modelarts.code_version"}}
{{$.i18n.Tr "repo.modelarts.train_job.start_file"}}
{{$.i18n.Tr "repo.modelarts.train_job.train_dataset"}}
{{$.i18n.Tr "repo.modelarts.train_job.run_parameter"}}
{{$.i18n.Tr "repo.modelarts.train_job.AI_driver"}}
{{$.i18n.Tr "repo.modelarts.train_job.standard"}}
{{$.i18n.Tr "repo.modelarts.train_job.compute_node"}}
+
+
+ {{$.i18n.Tr "repo.model.manage.model_accuracy"}} + + + + + + + + + + + + + + + + + + + +
{{$.i18n.Tr "repo.model.manage.Accuracy"}}
F1
{{$.i18n.Tr "repo.model.manage.Precision"}}
{{$.i18n.Tr "repo.model.manage.Recall"}}
+
+
-
- {{$.i18n.Tr "repo.model.manage.model_accuracy"}} - - - - - - - - - - - - - - - - - - - -
{{$.i18n.Tr "repo.model.manage.Accuracy"}}
F1
{{$.i18n.Tr "repo.model.manage.Precision"}}
{{$.i18n.Tr "repo.model.manage.Recall"}}
+
+ + + +
+ +
-
+
@@ -179,6 +200,9 @@ \ No newline at end of file