Skip to content

Commit befbb5f

Browse files
committed
chore: unit test regressors to match estimator results
Signed-off-by: Huamin Chen <[email protected]>
1 parent 6f4ff7e commit befbb5f

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

Diff for: pkg/model/estimator/local/regressor/local_test.go

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2021.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package regressor
18+
19+
import (
20+
. "github.com/onsi/ginkgo/v2"
21+
. "github.com/onsi/gomega"
22+
"k8s.io/klog/v2"
23+
24+
"github.com/sustainable-computing-io/kepler/pkg/config"
25+
"github.com/sustainable-computing-io/kepler/pkg/model/types"
26+
)
27+
28+
var (
29+
testNodeFeatureValues = []float64{1000, 1000, 1000, 1000}
30+
modelProcessFeatures = []string{config.CPUTime, config.PageCacheHit}
31+
)
32+
33+
func testModel(modelURL, trainerType string, core, dram, pkg int) {
34+
r := genRegressor(types.AbsPower, types.ComponentEnergySource, "", modelURL, "", trainerType)
35+
r.FloatFeatureNames = modelProcessFeatures
36+
err := r.Start()
37+
Expect(err).To(BeNil())
38+
39+
r.ResetSampleIdx()
40+
r.AddNodeFeatureValues(testNodeFeatureValues)
41+
42+
powers, err := r.GetComponentsPower(false)
43+
Expect(err).NotTo(HaveOccurred())
44+
Expect(len(powers)).Should(Equal(1))
45+
46+
klog.Infof("Core: %v, DRAM: %v, Pkg: %v", powers[0].Core, powers[0].DRAM, powers[0].Pkg)
47+
Expect(powers[0].Core).Should(BeEquivalentTo(core))
48+
Expect(powers[0].DRAM).Should(BeEquivalentTo(dram))
49+
Expect(powers[0].Pkg).Should(BeEquivalentTo(pkg))
50+
}
51+
52+
var _ = Describe("Test Regressor Weight Unit (models from URL)", func() {
53+
It("Get Node Components Power By SGD Regression with model from URL", func() {
54+
// Test power calculation. The results should match those from estimator
55+
// https://github.com/sustainable-computing-io/kepler-model-server/pull/493#discussion_r1795610556
56+
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",
57+
types.LinearRegressionTrainer, 146994, 18704, 146994)
58+
})
59+
60+
/* 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
61+
It("Get Node Components Power By Logarithmic Regression with model from URL", func() {
62+
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",
63+
types.LogarithmicTrainer, 59316, 14266, 59316)
64+
})
65+
*/
66+
67+
})

0 commit comments

Comments
 (0)