Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.9.2^2
zouap 3 years ago
parent
commit
0fb745427b
2 changed files with 52 additions and 22 deletions
  1. +16
    -0
      models/ai_model_manage.go
  2. +36
    -22
      routers/repo/ai_model_manage.go

+ 16
- 0
models/ai_model_manage.go View File

@@ -286,6 +286,22 @@ func ModifyModelDescription(id string, description string) error {
return nil return nil
} }


func ModifyModelStatus(id string, modelSize int64, status int, modelPath string) error {
var sess *xorm.Session
sess = x.ID(id)
defer sess.Close()
re, err := sess.Cols("size", "status", "path").Update(&AiModelManage{
Size: modelSize,
Status: status,
Path: modelPath,
})
if err != nil {
return err
}
log.Info("success to update ModelStatus from db.re=" + fmt.Sprint((re)))
return nil
}

func ModifyModelNewProperty(id string, new int, versioncount int) error { func ModifyModelNewProperty(id string, new int, versioncount int) error {
var sess *xorm.Session var sess *xorm.Session
sess = x.ID(id) sess = x.ID(id)


+ 36
- 22
routers/repo/ai_model_manage.go View File

@@ -27,6 +27,9 @@ const (
MODEL_LATEST = 1 MODEL_LATEST = 1
MODEL_NOT_LATEST = 0 MODEL_NOT_LATEST = 0
MODEL_MAX_SIZE = 1024 * 1024 * 1024 MODEL_MAX_SIZE = 1024 * 1024 * 1024
STATUS_COPY_MODEL = 1
STATUS_FINISHED = 0
STATUS_ERROR = 2
) )


func saveModelByParameters(jobId string, versionName string, name string, version string, label string, description string, engine int, ctx *context.Context) error { func saveModelByParameters(jobId string, versionName string, name string, version string, label string, description string, engine int, ctx *context.Context) error {
@@ -62,13 +65,9 @@ func saveModelByParameters(jobId string, versionName string, name string, versio
modelSelectedFile := ctx.Query("modelSelectedFile") modelSelectedFile := ctx.Query("modelSelectedFile")
//download model zip //train type //download model zip //train type
if aiTask.ComputeResource == models.NPUResource { if aiTask.ComputeResource == models.NPUResource {
modelPath, modelSize, err = downloadModelFromCloudBrainTwo(id, aiTask.JobName, "", aiTask.TrainUrl, modelSelectedFile)
if err != nil {
log.Info("download model from CloudBrainTwo faild." + err.Error())
return err
}
cloudType = models.TypeCloudBrainTwo cloudType = models.TypeCloudBrainTwo
} else if aiTask.ComputeResource == models.GPUResource { } else if aiTask.ComputeResource == models.GPUResource {
cloudType = models.TypeCloudBrainOne
var ResourceSpecs *models.ResourceSpecs var ResourceSpecs *models.ResourceSpecs
json.Unmarshal([]byte(setting.ResourceSpecs), &ResourceSpecs) json.Unmarshal([]byte(setting.ResourceSpecs), &ResourceSpecs)
for _, tmp := range ResourceSpecs.ResourceSpec { for _, tmp := range ResourceSpecs.ResourceSpec {
@@ -77,24 +76,8 @@ func saveModelByParameters(jobId string, versionName string, name string, versio
aiTask.FlavorName = flaverName aiTask.FlavorName = flaverName
} }
} }
modelPath, modelSize, err = downloadModelFromCloudBrainOne(id, aiTask.JobName, "", aiTask.TrainUrl, modelSelectedFile)
if err != nil {
log.Info("download model from CloudBrainOne faild." + err.Error())
return err
}
cloudType = models.TypeCloudBrainOne
} }
// else if cloudType == models.TypeC2Net {
// if aiTask.ComputeResource == models.NPUResource {
// modelPath, modelSize, err = downloadModelFromCloudBrainTwo(id, aiTask.JobName, "", aiTask.TrainUrl, modelSelectedFile)
// if err != nil {
// log.Info("download model from CloudBrainTwo faild." + err.Error())
// return err
// }
// } else if aiTask.ComputeResource == models.GPUResource {

// }
// }

accuracy := make(map[string]string) accuracy := make(map[string]string)
accuracy["F1"] = "" accuracy["F1"] = ""
accuracy["Recall"] = "" accuracy["Recall"] = ""
@@ -123,6 +106,7 @@ func saveModelByParameters(jobId string, versionName string, name string, versio
Engine: int64(engine), Engine: int64(engine),
TrainTaskInfo: string(aiTaskJson), TrainTaskInfo: string(aiTaskJson),
Accuracy: string(accuracyJson), Accuracy: string(accuracyJson),
Status: STATUS_COPY_MODEL,
} }


err = models.SaveModelToDb(model) err = models.SaveModelToDb(model)
@@ -146,11 +130,41 @@ func saveModelByParameters(jobId string, versionName string, name string, versio


models.UpdateRepositoryUnits(ctx.Repo.Repository, units, deleteUnitTypes) models.UpdateRepositoryUnits(ctx.Repo.Repository, units, deleteUnitTypes)


go asyncToCopyModel(aiTask, id, modelSelectedFile)

log.Info("save model end.") log.Info("save model end.")
notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, id, name, models.ActionCreateNewModelTask) notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, id, name, models.ActionCreateNewModelTask)
return nil return nil
} }


func asyncToCopyModel(aiTask *models.Cloudbrain, id string, modelSelectedFile string) {
if aiTask.ComputeResource == models.NPUResource {
modelPath, modelSize, err := downloadModelFromCloudBrainTwo(id, aiTask.JobName, "", aiTask.TrainUrl, modelSelectedFile)
if err != nil {
updateStatus(id, 0, STATUS_ERROR, modelPath)
log.Info("download model from CloudBrainTwo faild." + err.Error())
} else {
updateStatus(id, modelSize, STATUS_FINISHED, modelPath)
}
} else if aiTask.ComputeResource == models.GPUResource {

modelPath, modelSize, err := downloadModelFromCloudBrainOne(id, aiTask.JobName, "", aiTask.TrainUrl, modelSelectedFile)
if err != nil {
updateStatus(id, 0, STATUS_ERROR, modelPath)
log.Info("download model from CloudBrainOne faild." + err.Error())
} else {
updateStatus(id, modelSize, STATUS_FINISHED, modelPath)
}
}
}

func updateStatus(id string, modelSize int64, status int, modelPath string) {
err := models.ModifyModelStatus(id, modelSize, STATUS_FINISHED, modelPath)
if err != nil {
log.Info("update status error." + err.Error())
}
}

func SaveNewNameModel(ctx *context.Context) { func SaveNewNameModel(ctx *context.Context) {
if !ctx.Repo.CanWrite(models.UnitTypeModelManage) { if !ctx.Repo.CanWrite(models.UnitTypeModelManage) {
ctx.Error(403, ctx.Tr("repo.model_noright")) ctx.Error(403, ctx.Tr("repo.model_noright"))


Loading…
Cancel
Save