feat: add Apple M2/M3/M4 chip TDP support#1256
Draft
williamacostalora wants to merge 2 commits into
Draft
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 changesTypes 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: