Skip to content

Commit

Permalink
chore: unit test regressors to match estimator results
Browse files Browse the repository at this point in the history
Signed-off-by: Huamin Chen <[email protected]>
  • Loading branch information
rootfs committed Oct 9, 2024
1 parent 6f4ff7e commit efa316d
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions pkg/model/estimator/local/regressor/local_test.go
Original file line number Diff line number Diff line change
@@ -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))
})
})

0 comments on commit efa316d

Please sign in to comment.