|
|
|
@@ -27,6 +27,9 @@ const ( |
|
|
|
MODEL_LATEST = 1 |
|
|
|
MODEL_NOT_LATEST = 0 |
|
|
|
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 { |
|
|
|
@@ -62,13 +65,9 @@ func saveModelByParameters(jobId string, versionName string, name string, versio |
|
|
|
modelSelectedFile := ctx.Query("modelSelectedFile") |
|
|
|
//download model zip //train type |
|
|
|
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 |
|
|
|
} else if aiTask.ComputeResource == models.GPUResource { |
|
|
|
cloudType = models.TypeCloudBrainOne |
|
|
|
var ResourceSpecs *models.ResourceSpecs |
|
|
|
json.Unmarshal([]byte(setting.ResourceSpecs), &ResourceSpecs) |
|
|
|
for _, tmp := range ResourceSpecs.ResourceSpec { |
|
|
|
@@ -77,24 +76,8 @@ func saveModelByParameters(jobId string, versionName string, name string, versio |
|
|
|
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["F1"] = "" |
|
|
|
accuracy["Recall"] = "" |
|
|
|
@@ -123,6 +106,7 @@ func saveModelByParameters(jobId string, versionName string, name string, versio |
|
|
|
Engine: int64(engine), |
|
|
|
TrainTaskInfo: string(aiTaskJson), |
|
|
|
Accuracy: string(accuracyJson), |
|
|
|
Status: STATUS_COPY_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) |
|
|
|
|
|
|
|
go asyncToCopyModel(aiTask, id, modelSelectedFile) |
|
|
|
|
|
|
|
log.Info("save model end.") |
|
|
|
notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, id, name, models.ActionCreateNewModelTask) |
|
|
|
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) { |
|
|
|
if !ctx.Repo.CanWrite(models.UnitTypeModelManage) { |
|
|
|
ctx.Error(403, ctx.Tr("repo.model_noright")) |
|
|
|
|