Skip to content

Commit 7bab6a3

Browse files
feat: add Apple M2/M3/M4 chip TDP values to cpu_power.csv
Fixes #758 - Apple Silicon chips from M2 onwards were not recognized by CodeCarbon's TDP lookup table, causing users to fall back to a constant default power estimate instead of a real measurement. Added TDP entries for: - Apple M2, M2 Pro, M2 Max, M2 Ultra - Apple M3, M3 Pro, M3 Max, M3 Ultra - Apple M4, M4 Pro, M4 Max, M4 Ultra Added unit tests to verify correct TDP lookup for all new chip variants.
1 parent 150cac8 commit 7bab6a3

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

codecarbon/data/hardware/cpu_power.csv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4902,3 +4902,15 @@ TL-60,31
49024902
TL-64,35
49034903
X1150,17
49044904
X940,45
4905+
Apple M2,15
4906+
Apple M2 Pro,20
4907+
Apple M2 Max,30
4908+
Apple M2 Ultra,60
4909+
Apple M3,15
4910+
Apple M3 Pro,18
4911+
Apple M3 Max,30
4912+
Apple M3 Ultra,60
4913+
Apple M4,15
4914+
Apple M4 Pro,20
4915+
Apple M4 Max,35
4916+
Apple M4 Ultra,70

tests/test_cpu.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,42 @@ def test_main_returns_unknown_when_cpu_detection_fails(self):
577577
self.assertEqual(tdp.model, "Unknown")
578578
self.assertIsNone(tdp.tdp)
579579

580+
def test_apple_m2_chips_have_correct_tdp(self):
581+
for chip, expected_tdp in [
582+
("Apple M2", 15),
583+
("Apple M2 Pro", 20),
584+
("Apple M2 Max", 30),
585+
("Apple M2 Ultra", 60),
586+
]:
587+
with mock.patch("codecarbon.core.cpu.detect_cpu_model", return_value=chip):
588+
tdp = TDP()
589+
self.assertEqual(tdp.model, chip)
590+
self.assertEqual(tdp.tdp, expected_tdp)
591+
592+
def test_apple_m3_chips_have_correct_tdp(self):
593+
for chip, expected_tdp in [
594+
("Apple M3", 15),
595+
("Apple M3 Pro", 18),
596+
("Apple M3 Max", 30),
597+
("Apple M3 Ultra", 60),
598+
]:
599+
with mock.patch("codecarbon.core.cpu.detect_cpu_model", return_value=chip):
600+
tdp = TDP()
601+
self.assertEqual(tdp.model, chip)
602+
self.assertEqual(tdp.tdp, expected_tdp)
603+
604+
def test_apple_m4_chips_have_correct_tdp(self):
605+
for chip, expected_tdp in [
606+
("Apple M4", 15),
607+
("Apple M4 Pro", 20),
608+
("Apple M4 Max", 35),
609+
("Apple M4 Ultra", 70),
610+
]:
611+
with mock.patch("codecarbon.core.cpu.detect_cpu_model", return_value=chip):
612+
tdp = TDP()
613+
self.assertEqual(tdp.model, chip)
614+
self.assertEqual(tdp.tdp, expected_tdp)
615+
580616

581617
class TestResourceTrackerCPUTracking(unittest.TestCase):
582618
def test_set_cpu_tracking_skips_tdp_when_rapl_available(self):

0 commit comments

Comments
 (0)