|
|
|
@@ -1,6 +1,7 @@ |
|
|
|
package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"code.gitea.io/gitea/services/cloudbrain/resource" |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
@@ -106,15 +107,11 @@ func grampusTrainJobNewDataPrepare(ctx *context.Context, processType string) err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//get valid resource specs |
|
|
|
specs, err := grampus.GetResourceSpecs(processType) |
|
|
|
|
|
|
|
grampusSpecs := getFilterSpecBySpecialPool(specs, includeCenters, excludeCenters) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
log.Error("GetResourceSpecs failed:", err.Error()) |
|
|
|
} else { |
|
|
|
ctx.Data["flavor_infos"] = grampusSpecs |
|
|
|
//prepare available specs |
|
|
|
if processType == grampus.ProcessorTypeNPU { |
|
|
|
prepareGrampusTrainSpecs(ctx, models.NPU) |
|
|
|
} else if processType == grampus.ProcessorTypeGPU { |
|
|
|
prepareGrampusTrainSpecs(ctx, models.GPU) |
|
|
|
} |
|
|
|
|
|
|
|
//get branches |
|
|
|
@@ -140,6 +137,15 @@ func grampusTrainJobNewDataPrepare(ctx *context.Context, processType string) err |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func prepareGrampusTrainSpecs(ctx *context.Context, computeResource string) { |
|
|
|
noteBookSpecs, _ := resource.FindAvailableSpecs(ctx.User.ID, models.FindSpecsOptions{ |
|
|
|
JobType: models.JobTypeTrain, |
|
|
|
ComputeResource: computeResource, |
|
|
|
Cluster: models.C2NetCluster, |
|
|
|
}) |
|
|
|
ctx.Data["Specs"] = noteBookSpecs |
|
|
|
} |
|
|
|
|
|
|
|
func getFilterSpecBySpecialPool(specs *models.GetGrampusResourceSpecsResult, includeCenters map[string]struct{}, excludeCenters map[string]struct{}) []models.GrampusSpec { |
|
|
|
if len(includeCenters) == 0 && len(excludeCenters) == 0 { |
|
|
|
return specs.Infos |
|
|
|
@@ -206,7 +212,6 @@ func GrampusTrainJobGpuCreate(ctx *context.Context, form auth.CreateGrampusTrain |
|
|
|
codeMinioPath := setting.CBCodePathPrefix + jobName + cloudbrain.CodeMountPath + "/" |
|
|
|
dataMinioPath := setting.Attachment.Minio.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid |
|
|
|
branchName := form.BranchName |
|
|
|
flavorName := form.FlavorName |
|
|
|
image := strings.TrimSpace(form.Image) |
|
|
|
|
|
|
|
if !jobNamePattern.MatchString(displayJobName) { |
|
|
|
@@ -264,6 +269,18 @@ func GrampusTrainJobGpuCreate(ctx *context.Context, form auth.CreateGrampusTrain |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//check specification |
|
|
|
spec, err := resource.GetAndCheckSpec(ctx.User.ID, form.SpecId, models.FindSpecsOptions{ |
|
|
|
JobType: models.JobTypeTrain, |
|
|
|
ComputeResource: models.GPU, |
|
|
|
Cluster: models.C2NetCluster, |
|
|
|
}) |
|
|
|
if err != nil || spec == nil { |
|
|
|
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeGPU) |
|
|
|
ctx.RenderWithErr("Resource specification not available", tplGrampusTrainJobGPUNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//check dataset |
|
|
|
attachment, err := models.GetAttachmentByUUID(uuid) |
|
|
|
if err != nil { |
|
|
|
@@ -328,7 +345,6 @@ func GrampusTrainJobGpuCreate(ctx *context.Context, form auth.CreateGrampusTrain |
|
|
|
ComputeResource: models.GPUResource, |
|
|
|
ProcessType: grampus.ProcessorTypeGPU, |
|
|
|
Command: command, |
|
|
|
ResourceSpecId: form.FlavorID, |
|
|
|
ImageUrl: image, |
|
|
|
Description: description, |
|
|
|
BootFile: bootFile, |
|
|
|
@@ -336,12 +352,12 @@ func GrampusTrainJobGpuCreate(ctx *context.Context, form auth.CreateGrampusTrain |
|
|
|
CommitID: commitID, |
|
|
|
BranchName: branchName, |
|
|
|
Params: form.Params, |
|
|
|
FlavorName: flavorName, |
|
|
|
EngineName: image, |
|
|
|
DatasetName: attachment.Name, |
|
|
|
IsLatestVersion: modelarts.IsLatestVersion, |
|
|
|
VersionCount: modelarts.VersionCount, |
|
|
|
WorkServerNumber: 1, |
|
|
|
Spec: spec, |
|
|
|
} |
|
|
|
|
|
|
|
err = grampus.GenerateTrainJob(ctx, req) |
|
|
|
@@ -389,7 +405,6 @@ func GrampusTrainJobNpuCreate(ctx *context.Context, form auth.CreateGrampusTrain |
|
|
|
dataObsPath := setting.BasePath + path.Join(uuid[0:1], uuid[1:2]) + "/" + uuid + "/" |
|
|
|
branchName := form.BranchName |
|
|
|
isLatestVersion := modelarts.IsLatestVersion |
|
|
|
flavorName := form.FlavorName |
|
|
|
versionCount := modelarts.VersionCount |
|
|
|
engineName := form.EngineName |
|
|
|
|
|
|
|
@@ -448,6 +463,18 @@ func GrampusTrainJobNpuCreate(ctx *context.Context, form auth.CreateGrampusTrain |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//check specification |
|
|
|
spec, err := resource.GetAndCheckSpec(ctx.User.ID, form.SpecId, models.FindSpecsOptions{ |
|
|
|
JobType: models.JobTypeTrain, |
|
|
|
ComputeResource: models.NPU, |
|
|
|
Cluster: models.C2NetCluster, |
|
|
|
}) |
|
|
|
if err != nil || spec == nil { |
|
|
|
grampusTrainJobNewDataPrepare(ctx, grampus.ProcessorTypeNPU) |
|
|
|
ctx.RenderWithErr("Resource specification not available", tplGrampusTrainJobNPUNew, &form) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
//check dataset |
|
|
|
attachment, err := models.GetAttachmentByUUID(uuid) |
|
|
|
if err != nil { |
|
|
|
@@ -502,7 +529,6 @@ func GrampusTrainJobNpuCreate(ctx *context.Context, form auth.CreateGrampusTrain |
|
|
|
ComputeResource: models.NPUResource, |
|
|
|
ProcessType: grampus.ProcessorTypeNPU, |
|
|
|
Command: command, |
|
|
|
ResourceSpecId: form.FlavorID, |
|
|
|
ImageId: form.ImageID, |
|
|
|
DataUrl: dataObsPath, |
|
|
|
Description: description, |
|
|
|
@@ -515,11 +541,11 @@ func GrampusTrainJobNpuCreate(ctx *context.Context, form auth.CreateGrampusTrain |
|
|
|
IsLatestVersion: isLatestVersion, |
|
|
|
BranchName: branchName, |
|
|
|
Params: form.Params, |
|
|
|
FlavorName: flavorName, |
|
|
|
EngineName: engineName, |
|
|
|
VersionCount: versionCount, |
|
|
|
TotalVersionCount: modelarts.TotalVersionCount, |
|
|
|
DatasetName: attachment.Name, |
|
|
|
Spec: spec, |
|
|
|
} |
|
|
|
|
|
|
|
err = grampus.GenerateTrainJob(ctx, req) |
|
|
|
|