Skip to content

feat: add Apple M2/M3/M4 chip TDP support#1256

Draft
williamacostalora wants to merge 2 commits into
mlco2:masterfrom
williamacostalora:fix-issue-758
Draft

feat: add Apple M2/M3/M4 chip TDP support#1256
williamacostalora wants to merge 2 commits into
mlco2:masterfrom
williamacostalora:fix-issue-758

Conversation

@williamacostalora

Copy link
Copy Markdown

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 M1 in 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?

  • Reproduced the bug by mocking detect_cpu_model() to return "Apple M3 Pro", confirming the existing fallback warning and incorrect 32W estimate (vs. ~18W actual spec)
  • Added 12 new rows to cpu_power.csv covering M2, M2 Pro, M2 Max, M2 Ultra, M3, M3 Pro, M3 Max, M3 Ultra, M4, M4 Pro, M4 Max, M4 Ultra
  • Added 4 new unit tests to tests/test_cpu.py:
    • Correct TDP lookup for M2 series
    • Correct TDP lookup for M3 series
    • Correct TDP lookup for M4 series
    • Graceful fallback for an unrecognized future chip (e.g. "Apple M5 Pro") confirms no crash, falls back to existing default behavior
  • Ran full tests/test_cpu.py suite: 43 passed, 2 skipped (skips are pre-existing, platform-specific, unrelated to this change)
  • Rebased on latest upstream/master to confirm no conflicts with recent changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

AI Usage Disclosure

  • ⭐ AI-assisted. Car analogy: you drive the car, AI helps you find your way.

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 correct unittest.mock.patch usage (including a gotcha around patching codecarbon.core.cpu.detect_cpu_model rather than codecarbon.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:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have read the docs/how-to/contributing.md document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better support for Apple Silicon chips

1 participant