Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: unit test regressors to match estimator results #1804

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions pkg/model/estimator/local/regressor/local_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright 2021.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package regressor

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/klog/v2"

"github.com/sustainable-computing-io/kepler/pkg/config"
"github.com/sustainable-computing-io/kepler/pkg/model/types"
)

var (
testNodeFeatureValues = []float64{1000, 1000, 1000, 1000}
modelProcessFeatures = []string{config.CPUTime, config.PageCacheHit}
)

func testModel(modelURL, trainerType string, core, dram, pkg int) {
r := genRegressor(types.AbsPower, types.ComponentEnergySource, "", modelURL, "", trainerType)
r.FloatFeatureNames = modelProcessFeatures
err := r.Start()
Expect(err).To(BeNil())

r.ResetSampleIdx()
r.AddNodeFeatureValues(testNodeFeatureValues)

powers, err := r.GetComponentsPower(false)
Expect(err).NotTo(HaveOccurred())
Expect(len(powers)).Should(Equal(1))

klog.Infof("Core: %v, DRAM: %v, Pkg: %v", powers[0].Core, powers[0].DRAM, powers[0].Pkg)
Expect(powers[0].Core).Should(BeEquivalentTo(core))
Expect(powers[0].DRAM).Should(BeEquivalentTo(dram))
Expect(powers[0].Pkg).Should(BeEquivalentTo(pkg))
}

var _ = Describe("Test Regressor Weight Unit (models from URL)", func() {
It("Get Node Components Power By SGD Regression with model from URL", func() {
// Test power calculation. The results should match those from estimator
// https://github.com/sustainable-computing-io/kepler-model-server/pull/493#discussion_r1795610556
testModel("https://raw.githubusercontent.com/sustainable-computing-io/kepler-model-db/refs/heads/main/models/v0.7/ec2-0.7.11/rapl-sysfs/AbsPower/BPFOnly/SGDRegressorTrainer_0.json",
types.LinearRegressionTrainer, 146994, 18704, 146994)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may make the note that the expected value must be updated if when the model at the target URL has changed.

})

/* FIXME: the test result is Core: 70824, DRAM: 21137, Pkg: 70824, but the estimator result is Core: 59316, DRAM: 14266, Pkg: 59316, per // https://github.com/sustainable-computing-io/kepler-model-server/pull/493#discussion_r1795610556
It("Get Node Components Power By Logarithmic Regression with model from URL", func() {
testModel("https://raw.githubusercontent.com/sustainable-computing-io/kepler-model-db/refs/heads/main/models/v0.7/ec2-0.7.11/rapl-sysfs/AbsPower/BPFOnly/LogarithmicRegressionTrainer_0.json",
types.LogarithmicTrainer, 59316, 14266, 59316)
})
*/

})
Loading