From efa316d927138cdebb27a7353bd28a402355dcea Mon Sep 17 00:00:00 2001 From: Huamin Chen Date: Wed, 9 Oct 2024 10:55:01 -0400 Subject: [PATCH] chore: unit test regressors to match estimator results Signed-off-by: Huamin Chen --- .../estimator/local/regressor/local_test.go | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 pkg/model/estimator/local/regressor/local_test.go diff --git a/pkg/model/estimator/local/regressor/local_test.go b/pkg/model/estimator/local/regressor/local_test.go new file mode 100644 index 0000000000..2e894a8466 --- /dev/null +++ b/pkg/model/estimator/local/regressor/local_test.go @@ -0,0 +1,52 @@ +/* +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/model/types" +) + +var _ = Describe("Test Regressor Weight Unit (SGD model from URL)", func() { + It("Get Node Components Power By SGD Regression with model from URL", func() { + 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" + + // Initialize the regressor with the URL + r := genRegressor(types.AbsPower, types.ComponentEnergySource, "", modelURL, "", types.LogarithmicTrainer) + err := r.Start() + Expect(err).To(BeNil()) + + r.ResetSampleIdx() + r.AddNodeFeatureValues(nodeFeatureValues) + + powers, err := r.GetComponentsPower(false) + Expect(err).NotTo(HaveOccurred()) + Expect(len(powers)).Should(Equal(1)) + + // Test power calculation. The results should match those from estimator + // The following results are from kepler-model-server tests/estimator_power_request_test.py + // {"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"} + // {'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} + klog.Infof("Core: %v, DRAM: %v, Pkg: %v", powers[0].Core, powers[0].DRAM, powers[0].Pkg) + Expect(powers[0].Core).Should(BeEquivalentTo(143812)) + Expect(powers[0].DRAM).Should(BeEquivalentTo(18616)) + Expect(powers[0].Pkg).Should(BeEquivalentTo(143812)) + }) +})