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 ; } +
| {{$.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.model.manage.Accuracy"}} | ++ |
| F1 | ++ |
| {{$.i18n.Tr "repo.model.manage.Precision"}} | ++ |
| {{$.i18n.Tr "repo.model.manage.Recall"}} | ++ |
| {{$.i18n.Tr "repo.model.manage.Accuracy"}} | -- |
| F1 | -- |
| {{$.i18n.Tr "repo.model.manage.Precision"}} | -- |
| {{$.i18n.Tr "repo.model.manage.Recall"}} | -- |