Skip to content

Commit efa316d

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

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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/model/types"
25+
)
26+
27+
var _ = Describe("Test Regressor Weight Unit (SGD model from URL)", func() {
28+
It("Get Node Components Power By SGD Regression with model from URL", func() {
29+
modelURL := "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"
30+
31+
// Initialize the regressor with the URL
32+
r := genRegressor(types.AbsPower, types.ComponentEnergySource, "", modelURL, "", types.LogarithmicTrainer)
33+
err := r.Start()
34+
Expect(err).To(BeNil())
35+
36+
r.ResetSampleIdx()
37+
r.AddNodeFeatureValues(nodeFeatureValues)
38+
39+
powers, err := r.GetComponentsPower(false)
40+
Expect(err).NotTo(HaveOccurred())
41+
Expect(len(powers)).Should(Equal(1))
42+
43+
// Test power calculation. The results should match those from estimator
44+
// The following results are from kepler-model-server tests/estimator_power_request_test.py
45+
// {"trainer_name": "SGDRegressorTrainer_0", "metrics": ["bpf_cpu_time_ms", "bpf_page_cache_hit"], "system_features": ["node_info", "cpu_scaling_frequency_hertz"], "system_values": ["1", "1GHz"], "values": [[1.0, 1.0], [1.0, 1.0]], "output_type": "AbsPower", "source": "rapl-sysfs"}
46+
// {'powers': {'package': [143.81524594970784, 143.81524594970784], 'core': [0.0, 0.0], 'uncore': [0.0, 0.0], 'dram': [18.616373449562538, 18.616373449562538]}, 'msg': '', 'core_ratio': 0.16666666666666666}
47+
klog.Infof("Core: %v, DRAM: %v, Pkg: %v", powers[0].Core, powers[0].DRAM, powers[0].Pkg)
48+
Expect(powers[0].Core).Should(BeEquivalentTo(143812))
49+
Expect(powers[0].DRAM).Should(BeEquivalentTo(18616))
50+
Expect(powers[0].Pkg).Should(BeEquivalentTo(143812))
51+
})
52+
})

0 commit comments

Comments
 (0)