Skip to content

Commit

Permalink
Merge pull request #406 from jaypume/feature-knowledge-base
Browse files Browse the repository at this point in the history
Support showing knowledge base
  • Loading branch information
kubeedge-bot authored Jun 13, 2023
2 parents dad8203 + 6753b22 commit 3e8de61
Show file tree
Hide file tree
Showing 9 changed files with 318 additions and 12 deletions.
50 changes: 50 additions & 0 deletions build/crds/sedna.io_lifelonglearningjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21187,6 +21187,56 @@ spec:
- type
type: object
type: array
knowledgeBase:
properties:
AIClasses:
properties:
listOfAIClasses:
items:
type: string
type: array
numberOfAIClasses:
type: integer
required:
- numberOfAIClasses
type: object
AIModels:
properties:
listOfAIModels:
items:
properties:
averagePrecision:
type: number
modelID:
type: string
numberOfTrainSamples:
type: integer
required:
- averagePrecision
- modelID
- numberOfTrainSamples
type: object
type: array
numberOfAIModels:
type: integer
required:
- numberOfAIModels
type: object
samples:
properties:
numberOfLabeledUnseenSample:
type: integer
numberOfUnseenSample:
type: integer
required:
- numberOfLabeledUnseenSample
- numberOfUnseenSample
type: object
required:
- AIClasses
- AIModels
- samples
type: object
startTime:
description: Represents time when the job was acknowledged by the
job controller. It is not guaranteed to be set in happens-before
Expand Down
46 changes: 43 additions & 3 deletions pkg/apis/sedna/v1alpha1/lifelonglearningjob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,47 @@ type LLDeploySpec struct {

// LifelongLearningJobList is a list of LifelongLearningJobs.
type LifelongLearningJobList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []LifelongLearningJob `json:"items"`
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata"`
Items []LifelongLearningJob `json:"items"`
OverallKBStatus OverallStatus `json:"overallStatus"`
OverallKBDetails KnowledgeBase `json:"overallKBStatus"`
}

type OverallStatus struct {
NumberOfUnseenSample int `json:"numberOfUnseenSample"`
NumberOfNewUnseenSample int `json:"numberOfNewUnseenSample"`
NumberOfAIModels int `json:"numberOfAIModels"`
PercentOfNewAIModels float32 `json:"percentOfNewAIModels"`
NumberOfClasses int `json:"numberOfClasses"`
PercentOfNewClasses float32 `json:"percentOfNewClasses"`
}

type KnowledgeBase struct {
AIModels AIModels `json:"AIModels"`
AIClasses AIClasses `json:"AIClasses"`
Samples Samples `json:"samples"`
}

type AIModels struct {
NumberOfAIModels int `json:"numberOfAIModels"`
ListOfAIModels []AIModel `json:"listOfAIModels,omitempty"`
}

type AIModel struct {
ModelID string `json:"modelID"`
AveragePrecision float32 `json:"averagePrecision"`
NumberOfTrainSamples int `json:"numberOfTrainSamples"`
}

type AIClasses struct {
NumberOfAIClasses int `json:"numberOfAIClasses"`
ListOfAIClasses []string `json:"listOfAIClasses,omitempty"`
}

type Samples struct {
NumberOfLabeledUnseenSample int `json:"numberOfLabeledUnseenSample"`
NumberOfUnseenSample int `json:"numberOfUnseenSample"`
}

// LLJobStatus represents the current state of a lifelonglearning job
Expand All @@ -97,6 +135,8 @@ type LLJobStatus struct {
// +optional
Conditions []LLJobCondition `json:"conditions,omitempty"`

KnowledgeBase KnowledgeBase `json:"knowledgeBase,omitempty"`

// Represents time when the job was acknowledged by the job controller.
// It is not guaranteed to be set in happens-before order across separate operations.
// It is represented in RFC3339 form and is in UTC.
Expand Down
112 changes: 112 additions & 0 deletions pkg/apis/sedna/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/globalmanager/controllers/lifelonglearning/downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
func (c *Controller) syncToEdge(eventType watch.EventType, obj interface{}) error {
job, ok := obj.(*sednav1.LifelongLearningJob)
if !ok {
klog.V(4).Infof("get job %s failed, stop to sync to edge", job.Name)
return nil
}

Expand All @@ -54,6 +55,7 @@ func (c *Controller) syncToEdge(eventType watch.EventType, obj interface{}) erro
var deployNodeName string

getAnnotationsNodeName := func(nodeName sednav1.LLJobStage) string {
klog.V(4).Infof("getAnnotationsNodeName return %s", job.Name)
return runtime.AnnotationsKeyPrefix + string(nodeName)
}
ann := job.GetAnnotations()
Expand Down Expand Up @@ -88,6 +90,7 @@ func (c *Controller) syncToEdge(eventType watch.EventType, obj interface{}) erro
jobStage := latestCondition.Stage

syncJobWithNodeName := func(nodeName string) {
klog.V(4).Infof("syncJobWithNodeName nodeName is %s, job name is %s ", nodeName, job.Name)
if err := c.sendToEdgeFunc(nodeName, eventType, job); err != nil {
klog.Warningf("Error to sync lifelong learning job %s to node %s in stage %s: %v",
job.Name, nodeName, jobStage, err)
Expand All @@ -108,10 +111,13 @@ func (c *Controller) syncToEdge(eventType watch.EventType, obj interface{}) erro
doJobStageEvent := func(nodeName string) {
switch currentType {
case sednav1.LLJobStageCondWaiting:
klog.V(4).Infof("LLJobStageCondWaiting, dataset nodeName is %s", nodeName)
syncJobWithNodeName(dsNodeName)
case sednav1.LLJobStageCondRunning:
klog.V(4).Infof("LLJobStageCondRunning, nodeName is %s", nodeName)
syncJobWithNodeName(nodeName)
case sednav1.LLJobStageCondCompleted, sednav1.LLJobStageCondFailed:
klog.V(4).Infof("LLJobStageCondCompleted, nodeName is %s", nodeName)
if !isJobResidentNode(nodeName) {
// delete LC's job from nodeName that's different from dataset node when worker's status
// is completed or failed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func (c *Controller) sync(key string) (bool, error) {

if needUpdated {
if err := c.updateJobStatus(&job); err != nil {
klog.V(4).Infof("the job needUpdated, err is %s", err)
return forget, err
}

Expand All @@ -293,13 +294,13 @@ func (c *Controller) sync(key string) (bool, error) {

forget = true
}

return forget, err
}

// setWorkerNodeNameOfJob sets the worker nodeName of the specified job
// which is used for downstream to sync job info to the specified LC located in nodeName.
func (c *Controller) setWorkerNodeNameOfJob(job *sednav1.LifelongLearningJob, jobStage string, nodeName string) error {
klog.V(4).Infof("setWorkerNodeNameOfJob job name is %s, job Stage is %s, nodeName is %s", job.Name, jobStage, nodeName)
key := runtime.AnnotationsKeyPrefix + jobStage

return c.addJobAnnotations(job, key, nodeName)
Expand Down Expand Up @@ -368,6 +369,8 @@ func (c *Controller) transitJobState(job *sednav1.LifelongLearningJob) (bool, er
currentType := latestCondition.Type
newConditionType = currentType

//klog.Infof("==== stage is %s, type is %s, name is %s", jobStage, currentType, job.Name)

switch currentType {
case initialType:
newConditionType = sednav1.LLJobStageCondWaiting
Expand Down Expand Up @@ -780,8 +783,8 @@ func (c *Controller) createInferPod(job *sednav1.LifelongLearningJob) error {
"NAMESPACE": job.Namespace,
"JOB_NAME": job.Name,
"WORKER_NAME": "inferworker-" + utilrand.String(5),

"LC_SERVER": c.cfg.LC.Server,
"LC_SERVER": c.cfg.LC.Server,
"OUTPUT_URL": job.Spec.OutputDir,
}

workerParam.WorkerType = runtime.InferencePodType
Expand Down
Loading

0 comments on commit 3e8de61

Please sign in to comment.