feat: add Apple M2/M3/M4 chip TDP support#1256
Conversation
Fixes mlco2#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.
Adds a regression test confirming that chip variants not yet in cpu_power.csv (e.g. a future Apple M5) still resolve to the existing default per-thread power estimate instead of raising an error.
8a3e388 to
635b281
Compare
Updates M2/M3/M4 TDP estimates to align with the sources cited in issue mlco2#758 (NotebookCheck, CPU Monkey). Previous values were rough estimates that didn't match the maintainer-reviewed table in the issue thread. Values without a direct source (M3 Ultra, M4 Pro/Max/Ultra) are extrapolated proportionally from the equivalent M3 generation chips and noted as such in the PR description, since Apple does not publish official TDP specs.
|
Hi! I've updated the TDP values in this PR to match the sourced table @makoeppel shared in the issue thread, rather than the rough estimates I originally used. Also added a note in the description explaining where each value came from and flagging which ones (M3 Ultra, M4 Pro/Max/Ultra) had no direct source and were extrapolated. Let me know if you'd prefer a different approach for those, or if it makes sense to scope them out for now. Thanks for your time! |
benoit-cty
left a comment
There was a problem hiding this comment.
Thanks a lot !
Sorry for the delay.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1256 +/- ##
=======================================
Coverage 89.39% 89.39%
=======================================
Files 47 47
Lines 4565 4565
=======================================
Hits 4081 4081
Misses 484 484 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@benoit-cty! Really appreciate it. Let me know if there's anything else needed before merging. |
|
Hi @benoit-cty ! The branch update triggered a new workflow approval request. Could you approve the CI workflows when you get a chance so the pre-commit check can run? Thanks again! |
Description
Adds TDP (Thermal Design Power) entries for Apple M2, M3, and M4 chip variants to
cpu_power.csv, and adds unit tests covering correct TDP lookup for all new entries plus a fallback test for unrecognized future Apple chips.Related Issue
Fixes #758
Motivation and Context
CodeCarbon's CPU power detection only had an entry for
Apple M1in its TDP lookup table. Users on M2, M3, or M4 Macs received a "We saw that you have a Apple M3 Pro but we don't know it" warning and fell back to a generic estimate of 4W per CPU thread, producing inaccurate emissions data for a large and growing portion of ML practitioners on Apple Silicon.How Has This Been Tested?
detect_cpu_model()to return"Apple M3 Pro", confirming the existing fallback warning and incorrect 32W estimate (vs. ~18W actual spec)cpu_power.csvcovering M2, M2 Pro, M2 Max, M2 Ultra, M3, M3 Pro, M3 Max, M3 Ultra, M4, M4 Pro, M4 Max, M4 Ultratests/test_cpu.py:tests/test_cpu.pysuite: 43 passed, 2 skipped (skips are pre-existing, platform-specific, unrelated to this change)upstream/masterto confirm no conflicts with recent changesNote on TDP value sourcing
TDP values are sourced from NotebookCheck and CPU Monkey, matching the
table @makoeppel shared in this issue thread (since Apple does not
publish official TDP specs):
the ranges in the issue's sourced table
table
thread, so these are extrapolated proportionally from the equivalent
M3-generation values (M3 Ultra: 100W, M4 Pro: 35W, M4 Max: 55W,
M4 Ultra: 110W). Happy to adjust if better sources are available, or
to leave these out of scope for a follow-up if preferred.
Types of changes
AI Usage Disclosure
I used Claude as a pair-programming assistant throughout: it helped me locate the relevant files, explained the existing fuzzy-matching lookup logic in
TDP._get_matching_cpu(), and walked me through correctunittest.mock.patchusage (including a gotcha around patchingcodecarbon.core.cpu.detect_cpu_modelrather thancodecarbon.core.util.detect_cpu_model). I wrote, ran, and reviewed every command and test myself, sourced the actual Apple Silicon TDP values independently, and made all decisions about test structure and scope.Checklist: