|
|
@@ -528,6 +528,15 @@ func TrainJobIndex(ctx *context.Context) { |
|
|
|
} |
|
|
|
|
|
|
|
func TrainJobNew(ctx *context.Context) { |
|
|
|
err := trainJobNewDataPrepare(ctx) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("get new train-job info failed", err) |
|
|
|
return |
|
|
|
} |
|
|
|
ctx.HTML(200, tplModelArtsTrainJobNew) |
|
|
|
} |
|
|
|
|
|
|
|
func trainJobNewDataPrepare(ctx *context.Context) error { |
|
|
|
ctx.Data["PageIsCloudBrain"] = true |
|
|
|
|
|
|
|
//can, err := canUserCreateTrainJob(ctx.User.ID) |
|
|
@@ -549,35 +558,35 @@ func TrainJobNew(ctx *context.Context) { |
|
|
|
attachs, err := models.GetModelArtsUserAttachments(ctx.User.ID) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("GetAllUserAttachments failed:", err) |
|
|
|
return |
|
|
|
return err |
|
|
|
} |
|
|
|
ctx.Data["attachments"] = attachs |
|
|
|
|
|
|
|
var resourcePools modelarts.ResourcePool |
|
|
|
if err = json.Unmarshal([]byte(setting.ResourcePools), &resourcePools); err != nil { |
|
|
|
ctx.ServerError("json.Unmarshal failed:", err) |
|
|
|
return |
|
|
|
return err |
|
|
|
} |
|
|
|
ctx.Data["resource_pools"] = resourcePools.Info |
|
|
|
|
|
|
|
var engines modelarts.Engine |
|
|
|
if err = json.Unmarshal([]byte(setting.Engines), &engines); err != nil { |
|
|
|
ctx.ServerError("json.Unmarshal failed:", err) |
|
|
|
return |
|
|
|
return err |
|
|
|
} |
|
|
|
ctx.Data["engines"] = engines.Info |
|
|
|
|
|
|
|
var versionInfos modelarts.VersionInfo |
|
|
|
if err = json.Unmarshal([]byte(setting.EngineVersions), &versionInfos); err != nil { |
|
|
|
ctx.ServerError("json.Unmarshal failed:", err) |
|
|
|
return |
|
|
|
return err |
|
|
|
} |
|
|
|
ctx.Data["engine_versions"] = versionInfos.Version |
|
|
|
|
|
|
|
var flavorInfos modelarts.Flavor |
|
|
|
if err = json.Unmarshal([]byte(setting.TrainJobFLAVORINFOS), &flavorInfos); err != nil { |
|
|
|
ctx.ServerError("json.Unmarshal failed:", err) |
|
|
|
return |
|
|
|
return err |
|
|
|
} |
|
|
|
ctx.Data["flavor_infos"] = flavorInfos.Info |
|
|
|
|
|
|
@@ -587,12 +596,12 @@ func TrainJobNew(ctx *context.Context) { |
|
|
|
configList, err := getConfigList(modelarts.PerPage, 1, modelarts.SortByCreateTime, "desc", "", modelarts.ConfigTypeCustom) |
|
|
|
if err != nil { |
|
|
|
ctx.ServerError("getConfigList failed:", err) |
|
|
|
return |
|
|
|
return err |
|
|
|
} |
|
|
|
|
|
|
|
ctx.Data["config_list"] = configList.ParaConfigs |
|
|
|
|
|
|
|
ctx.HTML(200, tplModelArtsTrainJobNew) |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) { |
|
|
@@ -629,12 +638,14 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) |
|
|
|
//param check |
|
|
|
if err := paramCheckCreateTrainJob(form); err != nil { |
|
|
|
log.Error("paramCheckCreateTrainJob failed:(%v)", err) |
|
|
|
trainJobNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if err := git.Clone(repo.RepoPath(), codeLocalPath, git.CloneRepoOptions{}); err != nil { |
|
|
|
log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err) |
|
|
|
trainJobNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("Failed to clone repository", tplModelArtsTrainJobNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
@@ -642,18 +653,21 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) |
|
|
|
//todo: upload code (send to file_server todo this work?) |
|
|
|
if err := obsMkdir(setting.CodePathPrefix + jobName + modelarts.OutputPath); err != nil { |
|
|
|
log.Error("Failed to obsMkdir_output: %s (%v)", repo.FullName(), err) |
|
|
|
trainJobNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("Failed to obsMkdir_output", tplModelArtsTrainJobNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if err := obsMkdir(setting.CodePathPrefix + jobName + modelarts.LogPath); err != nil { |
|
|
|
log.Error("Failed to obsMkdir_log: %s (%v)", repo.FullName(), err) |
|
|
|
trainJobNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("Failed to obsMkdir_log", tplModelArtsTrainJobNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if err := uploadCodeToObs(codeLocalPath, jobName, ""); err != nil { |
|
|
|
log.Error("Failed to uploadCodeToObs: %s (%v)", repo.FullName(), err) |
|
|
|
trainJobNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("Failed to uploadCodeToObs", tplModelArtsTrainJobNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
@@ -673,6 +687,7 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) |
|
|
|
err := json.Unmarshal([]byte(params), ¶meters) |
|
|
|
if err != nil { |
|
|
|
log.Error("Failed to Unmarshal params: %s (%v)", params, err) |
|
|
|
trainJobNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("运行参数错误", tplModelArtsTrainJobNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
@@ -691,6 +706,7 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) |
|
|
|
if isSaveParam == "on" { |
|
|
|
if form.ParameterTemplateName == "" { |
|
|
|
log.Error("ParameterTemplateName is empty") |
|
|
|
trainJobNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("保存作业参数时,作业参数名称不能为空", tplModelArtsTrainJobNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
@@ -714,6 +730,7 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
log.Error("Failed to CreateTrainJobConfig: %v", err) |
|
|
|
trainJobNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr("保存作业参数失败:"+err.Error(), tplModelArtsTrainJobNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
@@ -738,6 +755,7 @@ func TrainJobCreate(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) |
|
|
|
err := modelarts.GenerateTrainJob(ctx, req) |
|
|
|
if err != nil { |
|
|
|
log.Error("GenerateTrainJob failed:%v", err.Error()) |
|
|
|
trainJobNewDataPrepare(ctx) |
|
|
|
ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|