Browse Source

inference

fix-2419
lewis 3 years ago
parent
commit
e56a6c7d4f
4 changed files with 18 additions and 101 deletions
  1. +0
    -1
      modules/modelarts/modelarts.go
  2. +13
    -97
      routers/repo/modelarts.go
  3. +3
    -3
      routers/routes/routes.go
  4. +2
    -0
      templates/repo/modelarts/trainjob/show.tmpl

+ 0
- 1
modules/modelarts/modelarts.go View File

@@ -716,7 +716,6 @@ func GenerateInferenceJob(ctx *context.Context, req *GenerateInferenceJobReq) (e
return err return err
} }


//todo
task := &models.Cloudbrain{ task := &models.Cloudbrain{
Status: string(models.ModelArtsTrainJobWaiting), Status: string(models.ModelArtsTrainJobWaiting),
UserID: ctx.User.ID, UserID: ctx.User.ID,


+ 13
- 97
routers/repo/modelarts.go View File

@@ -810,18 +810,11 @@ func TrainJobNewVersion(ctx *context.Context) {


func trainJobNewVersionDataPrepare(ctx *context.Context) error { func trainJobNewVersionDataPrepare(ctx *context.Context) error {
ctx.Data["PageIsCloudBrain"] = true ctx.Data["PageIsCloudBrain"] = true
var jobID = ctx.Params(":jobid")
var versionName = ctx.Query("version_name")

// canNewJob, err := canUserCreateTrainJobVersion(ctx, jobID, versionName)
// if err != nil {
// ctx.ServerError("canNewJob can info failed", err)
// return err
// }
var id = ctx.Params(":id")


task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName)
task, err := models.GetCloudbrainByID(id)
if err != nil { if err != nil {
log.Error("GetCloudbrainByJobIDAndVersionName(%s) failed:%v", jobID, err.Error())
log.Error("GetCloudbrainByID(%s) failed:%v", id, err.Error())
return err return err
} }


@@ -901,13 +894,10 @@ func trainJobNewVersionDataPrepare(ctx *context.Context) error {


func versionErrorDataPrepare(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) error { func versionErrorDataPrepare(ctx *context.Context, form auth.CreateModelArtsTrainJobForm) error {
ctx.Data["PageIsCloudBrain"] = true ctx.Data["PageIsCloudBrain"] = true
var jobID = ctx.Params(":jobid")
// var versionName = ctx.Params(":version-name")
var versionName = ctx.Query("version_name")

task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName)
var id = ctx.Params(":id")
task, err := models.GetCloudbrainByID(id)
if err != nil { if err != nil {
log.Error("GetCloudbrainByJobIDAndVersionName(%s) failed:%v", jobID, err.Error())
log.Error("GetCloudbrainByID(%s) failed:%v", id, err.Error())
return err return err
} }


@@ -1716,60 +1706,6 @@ func TrainJobShow(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplModelArtsTrainJobShow) ctx.HTML(http.StatusOK, tplModelArtsTrainJobShow)
} }


func TrainJobGetLog(ctx *context.Context) {
ctx.Data["PageIsTrainJob"] = true

var jobID = ctx.Params(":jobid")
var logFileName = ctx.Query("file_name")
var baseLine = ctx.Query("base_line")
var order = ctx.Query("order")

if order != modelarts.OrderDesc && order != modelarts.OrderAsc {
log.Error("order(%s) check failed", order)
ctx.HTML(http.StatusBadRequest, tplModelArtsTrainJobShow)
return
}

task, err := models.GetCloudbrainByJobID(jobID)
if err != nil {
log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error())
ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil)
return
}

result, err := modelarts.GetTrainJobLog(jobID, strconv.FormatInt(task.VersionID, 10), baseLine, logFileName, order, modelarts.Lines)
if err != nil {
log.Error("GetTrainJobLog(%s) failed:%v", jobID, err.Error())
ctx.RenderWithErr(err.Error(), tplModelArtsTrainJobShow, nil)
return
}

ctx.Data["log"] = result
//ctx.HTML(http.StatusOK, tplModelArtsTrainJobShow)
}

func trainJobGetLog(jobID string) (*models.GetTrainJobLogFileNamesResult, *models.GetTrainJobLogResult, error) {
task, err := models.GetCloudbrainByJobID(jobID)
if err != nil {
log.Error("GetCloudbrainByJobID(%s) failed:%v", jobID, err.Error())
return nil, nil, err
}

resultLogFile, err := modelarts.GetTrainJobLogFileNames(jobID, strconv.FormatInt(task.VersionID, 10))
if err != nil {
log.Error("GetTrainJobLogFileNames(%s) failed:%v", jobID, err.Error())
return nil, nil, err
}

result, err := modelarts.GetTrainJobLog(jobID, strconv.FormatInt(task.VersionID, 10), "", resultLogFile.LogFileList[0], modelarts.OrderDesc, modelarts.Lines)
if err != nil {
log.Error("GetTrainJobLog(%s) failed:%v", jobID, err.Error())
return nil, nil, err
}

return resultLogFile, result, err
}

func TrainJobDel(ctx *context.Context) { func TrainJobDel(ctx *context.Context) {
var jobID = ctx.Cloudbrain.JobID var jobID = ctx.Cloudbrain.JobID
var listType = ctx.Query("listType") var listType = ctx.Query("listType")
@@ -1835,15 +1771,6 @@ func TrainJobStop(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/train-job?listType=" + listType) ctx.Redirect(setting.AppSubURL + ctx.Repo.RepoLink + "/modelarts/train-job?listType=" + listType)
} }


func canUserCreateTrainJob(uid int64) (bool, error) {
org, err := models.GetOrgByName(setting.AllowedOrg)
if err != nil {
log.Error("get allowed org failed: ", setting.AllowedOrg)
return false, err
}

return org.IsOrgMember(uid)
}
func canUserCreateTrainJobVersion(ctx *context.Context, userID int64) (bool, error) { func canUserCreateTrainJobVersion(ctx *context.Context, userID int64) (bool, error) {
if ctx == nil || ctx.User == nil { if ctx == nil || ctx.User == nil {
log.Error("user unlogin!") log.Error("user unlogin!")
@@ -2310,17 +2237,16 @@ func inferenceJobErrorNewDataPrepare(ctx *context.Context, form auth.CreateModel
} }
func InferenceJobShow(ctx *context.Context) { func InferenceJobShow(ctx *context.Context) {
ctx.Data["PageIsCloudBrain"] = true ctx.Data["PageIsCloudBrain"] = true
var jobID = ctx.Params(":jobid")

page := ctx.QueryInt("page") page := ctx.QueryInt("page")
if page <= 0 { if page <= 0 {
page = 1 page = 1
} }
task, err := models.GetCloudbrainByJobID(jobID)


var id = ctx.Params(":id")
task, err := models.GetCloudbrainByID(id)
if err != nil { if err != nil {
log.Error("GetInferenceTask(%s) failed:%v", jobID, err.Error())
ctx.RenderWithErr(err.Error(), tplModelArtsInferenceJobShow, nil)
log.Error("GetCloudbrainByID(%s) failed:%v", id, err.Error())
ctx.ServerError("GetCloudbrainByID failed", err)
return return
} }
//设置权限 //设置权限
@@ -2353,11 +2279,12 @@ func InferenceJobShow(ctx *context.Context) {


LabelName := strings.Fields(task.LabelName) LabelName := strings.Fields(task.LabelName)
ctx.Data["labelName"] = LabelName ctx.Data["labelName"] = LabelName
ctx.Data["jobID"] = jobID
ctx.Data["jobID"] = task.JobID
ctx.Data["jobName"] = task.JobName ctx.Data["jobName"] = task.JobName
ctx.Data["displayJobName"] = task.DisplayJobName ctx.Data["displayJobName"] = task.DisplayJobName
ctx.Data["task"] = task ctx.Data["task"] = task
ctx.Data["canDownload"] = cloudbrain.CanModifyJob(ctx, task) ctx.Data["canDownload"] = cloudbrain.CanModifyJob(ctx, task)
ctx.Data["id"] = id


tempUids := []int64{} tempUids := []int64{}
tempUids = append(tempUids, task.UserID) tempUids = append(tempUids, task.UserID)
@@ -2444,19 +2371,8 @@ func DeleteJobStorage(jobName string) error {
} }


func DownloadMultiResultFile(ctx *context.Context) { func DownloadMultiResultFile(ctx *context.Context) {
var jobID = ctx.Params(":jobid")
var versionName = ctx.Query("version_name") var versionName = ctx.Query("version_name")
task, err := models.GetCloudbrainByJobIDAndVersionName(jobID, versionName)
if err != nil {
log.Error("GetCloudbrainByJobID(%s) failed:%v", task.JobName, err.Error())
return
}
// if !isCanDeleteOrDownload(ctx, task) {
// ctx.ServerError("no right.", errors.New(ctx.Tr("repo.model_noright")))
// return
// }

// path := Model_prefix + models.AttachmentRelativePath(id) + "/"
task := ctx.Cloudbrain
path := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, task.JobName, "result/", versionName), "/") + "/" path := strings.TrimPrefix(path.Join(setting.TrainJobModelPath, task.JobName, "result/", versionName), "/") + "/"


allFile, err := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, path) allFile, err := storage.GetAllObjectByBucketAndPrefix(setting.Bucket, path)


+ 3
- 3
routers/routes/routes.go View File

@@ -1209,10 +1209,10 @@ func RegisterRoutes(m *macaron.Macaron) {


m.Group("/inference-job", func() { m.Group("/inference-job", func() {
m.Get("", reqRepoCloudBrainReader, repo.InferenceJobIndex) m.Get("", reqRepoCloudBrainReader, repo.InferenceJobIndex)
m.Group("/:jobid", func() {
m.Group("/:id", func() {
m.Get("", reqRepoCloudBrainReader, repo.InferenceJobShow) m.Get("", reqRepoCloudBrainReader, repo.InferenceJobShow)
m.Get("/result_download", cloudbrain.AdminOrJobCreaterRightForTrain, repo.ResultDownload)
m.Get("/downloadall", repo.DownloadMultiResultFile)
m.Get("/result_download", cloudbrain.AdminOrJobCreaterRight, repo.ResultDownload)
m.Get("/downloadall", cloudbrain.AdminOrJobCreaterRight, repo.DownloadMultiResultFile)
}) })
m.Get("/create", reqWechatBind, reqRepoCloudBrainWriter, repo.InferenceJobNew) m.Get("/create", reqWechatBind, reqRepoCloudBrainWriter, repo.InferenceJobNew)
m.Post("/create", reqWechatBind, reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsInferenceJobForm{}), repo.InferenceJobCreate) m.Post("/create", reqWechatBind, reqRepoCloudBrainWriter, bindIgnErr(auth.CreateModelArtsInferenceJobForm{}), repo.InferenceJobCreate)


+ 2
- 0
templates/repo/modelarts/trainjob/show.tmpl View File

@@ -792,6 +792,7 @@


let userName let userName
let repoPath let repoPath
let jobID
let id let id
let downlaodFlag = {{ $.canDownload }} let downlaodFlag = {{ $.canDownload }}
$(document).ready(function () { $(document).ready(function () {
@@ -800,6 +801,7 @@
userName = urlArr.slice(-5)[0] userName = urlArr.slice(-5)[0]
repoPath = urlArr.slice(-4)[0] repoPath = urlArr.slice(-4)[0]
id = urlArr.slice(-1)[0] id = urlArr.slice(-1)[0]
jobID = id
}) })
function stopBubbling(e) { function stopBubbling(e) {
e = window.event || e; e = window.event || e;


Loading…
Cancel
Save