你确认删除该任务么?此任务一旦删除不可恢复。
+diff --git a/models/ai_model_manage.go b/models/ai_model_manage.go index 1048e9fec..c0837a521 100644 --- a/models/ai_model_manage.go +++ b/models/ai_model_manage.go @@ -51,6 +51,7 @@ type AiModelConvert struct { DestFormat int `xorm:"NOT NULL DEFAULT 0"` NetOutputFormat int `xorm:"NULL"` UserId int64 `xorm:"NOT NULL"` + CloudBrainTaskId string `xorm:"NULL"` RunTime int64 `xorm:"NULL"` TrainJobDuration string InputShape string `xorm:"varchar(2000)"` @@ -77,6 +78,20 @@ type AiModelQueryOptions struct { Status int } +func UpdateModelConvertCBTI(id string, CloudBrainTaskId string) error { + var sess *xorm.Session + sess = x.ID(id) + defer sess.Close() + re, err := sess.Cols("cloud_brain_task_id").Update(&AiModelConvert{ + CloudBrainTaskId: CloudBrainTaskId, + }) + if err != nil { + return err + } + log.Info("success to update cloud_brain_task_id from db.re=" + fmt.Sprint((re))) + return nil +} + func SaveModelConvert(modelConvert *AiModelConvert) error { sess := x.NewSession() defer sess.Close() diff --git a/routers/repo/ai_model_convert.go b/routers/repo/ai_model_convert.go index 432fd1c35..9210803c7 100644 --- a/routers/repo/ai_model_convert.go +++ b/routers/repo/ai_model_convert.go @@ -49,12 +49,20 @@ func SaveModelConvert(ctx *context.Context) { DestFormat := ctx.QueryInt("DestFormat") NetOutputFormat := ctx.QueryInt("NetOutputFormat") + task, err := models.QueryModelById(modelId) + if err != nil { + log.Error("no such model!", err.Error()) + ctx.ServerError("no such model:", err) + return + } + uuid := uuid.NewV4() id := uuid.String() modelConvert := &models.AiModelConvert{ ID: id, Name: name, Description: desc, + Status: "Waiting", SrcEngine: SrcEngine, RepoId: ctx.Repo.Repository.ID, ModelId: modelId, @@ -66,30 +74,31 @@ func SaveModelConvert(ctx *context.Context) { UserId: ctx.User.ID, } models.SaveModelConvert(modelConvert) + createTrainJob(modelConvert, ctx, task.Path) ctx.JSON(200, map[string]string{ "result_code": "0", }) } -func createTrainJob(modelConvertId string, modelId string, SrcEngine int, ctx *context.Context, modelPath string) error { +func createTrainJob(modelConvert *models.AiModelConvert, ctx *context.Context, modelRelativePath string) error { repo, _ := models.GetRepositoryByID(ctx.Repo.Repository.RepoID) - if SrcEngine == PYTORCH_ENGINE { - codePath := setting.JobPath + modelConvertId + CodeMountPath + if modelConvert.SrcEngine == PYTORCH_ENGINE { + codePath := setting.JobPath + modelConvert.ID + CodeMountPath downloadCode(repo, codePath, DefaultBranchName) - uploadCodeToMinio(codePath+"/", modelConvertId, CodeMountPath+"/") + uploadCodeToMinio(codePath+"/", modelConvert.ID, CodeMountPath+"/") - modelPath := setting.JobPath + modelConvertId + ModelMountPath + "/" + modelPath := setting.JobPath + modelConvert.ID + ModelMountPath + "/" mkModelPath(modelPath) - uploadCodeToMinio(modelPath, modelConvertId, ModelMountPath+"/") - command := getModelConvertCommand(modelConvertId) - dataActualPath := setting.Attachment.Minio.RealPath + modelPath + uploadCodeToMinio(modelPath, modelConvert.ID, ModelMountPath+"/") + command := getModelConvertCommand(modelConvert.ID, modelConvert.ModelPath) + dataActualPath := setting.Attachment.Minio.RealPath + modelRelativePath if TrainResourceSpecs == nil { json.Unmarshal([]byte(setting.TrainResourceSpecs), &TrainResourceSpecs) } resourceSpec := TrainResourceSpecs.ResourceSpec[1] - jobResult, err := cloudbrain.CreateJob(modelConvertId, models.CreateJobParams{ - JobName: modelConvertId, + jobResult, err := cloudbrain.CreateJob(modelConvert.ID, models.CreateJobParams{ + JobName: modelConvert.ID, RetryCount: 1, GpuType: GpuQueue, Image: GPU_PYTORCH_IMAGE, @@ -138,21 +147,22 @@ func createTrainJob(modelConvertId string, modelId string, SrcEngine int, ctx *c return err } if jobResult.Code != Success { - log.Error("CreateJob(%s) failed:%s", modelConvertId, jobResult.Msg, ctx.Data["MsgID"]) + log.Error("CreateJob(%s) failed:%s", modelConvert.ID, jobResult.Msg, ctx.Data["MsgID"]) return errors.New(jobResult.Msg) } var jobID = jobResult.Payload["jobId"].(string) log.Info("jobId=" + jobID) + models.UpdateModelConvertCBTI(modelConvert.ID, jobID) } return nil } -func getModelConvertCommand(name string) string { +func getModelConvertCommand(name string, modelFile string) string { var command string bootFile := "convert_pytorch.py" - command += "python /code/" + bootFile + " > " + ModelMountPath + "/" + name + "-" + LogFile + command += "python /code/" + bootFile + " --model " + modelFile + " > " + ModelMountPath + "/" + name + "-" + LogFile return command } diff --git a/templates/repo/modelmanage/convertshowinfo.tmpl b/templates/repo/modelmanage/convertshowinfo.tmpl new file mode 100644 index 000000000..24f6ce9da --- /dev/null +++ b/templates/repo/modelmanage/convertshowinfo.tmpl @@ -0,0 +1,652 @@ +{{template "base/head" .}} + +
| + {{$.i18n.Tr "repo.cloudbrain_task"}} + | +
+
+ {{.Name}}
+
+ |
+
| + {{$.i18n.Tr "repo.modelarts.status"}} + | + +
+
+ {{.Status}}
+
+ |
+
| + {{$.i18n.Tr "repo.modelarts.train_job.start_time"}} + | + +
+
+ {{TimeSinceUnix1 .CreatedUnix}}
+
+ |
+
| + {{$.i18n.Tr "repo.modelarts.train_job.dura_time"}} + | + +
+
+ {{$.TrainJobDuration}}
+
+ |
+
| + {{$.i18n.Tr "repo.modelarts.train_job.start_file"}} + | + +
+
+ {{.BootFile}}
+
+ |
+
| + {{$.i18n.Tr "repo.modelarts.train_job.description"}} + | + +
+
+ {{.Description}}
+
+ |
+
你确认删除该任务么?此任务一旦删除不可恢复。
+