Skip to content

Commit

Permalink
feat: add model_name attribute to ComponentModelWeights
Browse files Browse the repository at this point in the history
Signed-off-by: Sunyanan Choochotkaew <[email protected]>
  • Loading branch information
sunya-ch committed Aug 16, 2024
1 parent c9d8467 commit a6f75a4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 12 deletions.
9 changes: 8 additions & 1 deletion pkg/model/estimator/local/regressor/model_weights.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,11 @@ type NormalizedNumericalFeature struct {
Weight float64 `json:"weight,omitempty"`
}

type ComponentModelWeights map[string]ModelWeights
type ComponentModelWeights struct {
ModelName string `json:"model_name,omitempty"`
Platform *ModelWeights `json:"platform,omitempty"`
Core *ModelWeights `json:"core,omitempty"`
Uncore *ModelWeights `json:"uncore,omitempty"`
Package *ModelWeights `json:"package,omitempty"`
DRAM *ModelWeights `json:"dram,omitempty"`
}
41 changes: 36 additions & 5 deletions pkg/model/estimator/local/regressor/regressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,41 @@ func (r *Regressor) Start() error {
r.enabled = true
r.modelWeight = weight
r.modelPredictors = map[string]Predictor{}
for component, allWeights := range *weight {
var predictor Predictor
predictor, err = r.createPredictor(allWeights)
if err != nil {
if weight.Platform != nil {
if predictor, err := r.createPredictor(*weight.Platform); err != nil {
return err
} else {
r.modelPredictors[config.PLATFORM] = predictor
}
} else {
if weight.Package != nil {
if predictor, err := r.createPredictor(*weight.Package); err != nil {
return err
} else {
r.modelPredictors[config.PKG] = predictor
}
}
if weight.Core != nil {
if predictor, err := r.createPredictor(*weight.Core); err != nil {
return err
} else {
r.modelPredictors[config.CORE] = predictor
}
}
if weight.Uncore != nil {
if predictor, err := r.createPredictor(*weight.Uncore); err != nil {
return err
} else {
r.modelPredictors[config.UNCORE] = predictor
}
}
if weight.DRAM != nil {
if predictor, err := r.createPredictor(*weight.DRAM); err != nil {
return err
} else {
r.modelPredictors[config.DRAM] = predictor
}
}
r.modelPredictors[component] = predictor
}
return nil
} else {
Expand Down Expand Up @@ -157,6 +185,9 @@ func (r *Regressor) getWeightFromServer() (*ComponentModelWeights, error) {
if err != nil {
return nil, fmt.Errorf("model unmarshal error: %v (%s)", err, string(body))
}
if powerResonse.ModelName != "" {
klog.V(3).Infof("Using weights trained by %s", powerResonse.ModelName)
}
return &powerResonse, nil
}

Expand Down
10 changes: 5 additions & 5 deletions pkg/model/estimator/local/regressor/regressor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ var (

func GenPlatformModelWeights(curveFitWeights []float64) ComponentModelWeights {
return ComponentModelWeights{
config.PLATFORM: genWeights(SampleCoreNumericalVars, curveFitWeights),
Platform: genWeights(SampleCoreNumericalVars, curveFitWeights),
}
}

func GenComponentModelWeights(curveFitWeights []float64) ComponentModelWeights {
return ComponentModelWeights{
config.CORE: genWeights(SampleCoreNumericalVars, curveFitWeights),
config.DRAM: genWeights(SampleDramNumbericalVars, curveFitWeights),
Core: genWeights(SampleCoreNumericalVars, curveFitWeights),
DRAM: genWeights(SampleDramNumbericalVars, curveFitWeights),
}
}

func genWeights(numericalVars map[string]NormalizedNumericalFeature, curveFitWeights []float64) ModelWeights {
return ModelWeights{
func genWeights(numericalVars map[string]NormalizedNumericalFeature, curveFitWeights []float64) *ModelWeights {
return &ModelWeights{
AllWeights{
BiasWeight: 1.0,
CategoricalVariables: map[string]map[string]CategoricalFeature{"cpu_architecture": SampleCategoricalFeatures},
Expand Down
2 changes: 1 addition & 1 deletion pkg/sensors/platform/source/redfish.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (rf *RedFishClient) IsSystemCollectionSupported() bool {
}
}
}()
return rf.systems != nil && len(rf.systems) > 0
return len(rf.systems) > 0
}

// GetAbsEnergyFromPlatform returns the power consumption in Watt
Expand Down

0 comments on commit a6f75a4

Please sign in to comment.