Skip to content

Better support for Apple Silicon chips #758

Closed

Description

@makoeppel

Dear Codecarbon Team,

in your cpu_power.csv I can only find the Apple M1 chip. Since I started to use your tool on my M3 Pro it does not really find the TDP for this model. I did some research to get the number for all models together. As fare as I know Apple does not provide these numbers so all sources are external:

Version Approx. TDP Source
M1 (Base) 10W (MacBook Air), 15W (Mac Mini/Pro) NotebookCheck
M1 Pro ~35W CPU Monkey
M1 Max ~86W NotebookCheck
M1 Ultra ~90W-120W CPU Monkey
M2 (Base) 20-25W NotebookCheck
M2 Pro 30-40W CPU Monkey
M2 Max 40-60W NotebookCheck
M2 Ultra 90-120W CPU Monkey
M3 (Base) ~22W CPU Monkey
M3 Pro ~35W NotebookCheck
M3 Max ~50W NotebookCheck
M3 Ultra did not found this one -
M4 (Base) 20W CPU Monkey
M4 Pro did not found this one -
M4 Max did not found this one -
M4 Ultra did not found this one -

I think this still needs a review to get the numbers correct.

Activity

  1. changed the title [-]Better support for Apple Silicion chips[/-] [+]Better support for Apple Silicon chips[/+] on Jan 6, 2025
  2. benoit-cty commented on Jan 7, 2025

    @benoit-cty
    Contributor

    Hello,
    Codecarbon tracks Apple Silicon Chip energy consumption using powermetrics. It should be available natively on any mac. However, this tool is only usable with sudo rights.

    You can read more about it in the doc : https://mlco2.github.io/codecarbon/methodology.html#cpu

    We are working on a better solution : #731

  3. makoeppel commented on Jan 7, 2025

    @makoeppel
    Author

    Hi,

    I agree with your comment but I do think in general the support for M3/4 is not provided. I have the following issues:

    [codecarbon WARNING @ 23:26:23] We saw that you have a Apple M3 Pro but we don't know it. Please contact us.

    And in addition when adding:

    username ALL = (ALL) NOPASSWD: /usr/bin/powermetrics or
    username ALL = (root) NOPASSWD: /usr/bin/powermetrics via sudo visudo codecarbon stills give me:
    [codecarbon WARNING @ 23:26:23] No CPU tracking mode found. Falling back on CPU constant mode. Mac OS and ARM processor detected: Please enable PowerMetrics sudo to measure CPU

  4. benoit-cty commented on Jan 9, 2025

    @benoit-cty
    Contributor

    Thank you for the details.

    Looking at the code we do not test for M4, but M3 is supposed to work :

                        "M1" in detect_cpu_model()
                        or "M2" in detect_cpu_model()
                        or "M3" in detect_cpu_model()

    @LuisBlanche Have you an idea ?

  5. lotif commented on Jun 11, 2025

    @lotif

    Hi,

    I am running codecarbon in a desktop app that does not have the command line available. Is there a way to skip the check for powermetrics?

    Thanks.

  6. benoit-cty commented on Jun 12, 2025

    @benoit-cty
    Contributor

    Thanks for this interesting usecase.

    In codecarbon/codecarbon/core/powermetrics.py there is this code :

    if self._system.startswith("darwin"):
       # Run the powermetrics command with sudo and capture its output
      cmd = [ "sudo", "powermetrics", "-n", str(self._n_points), "", "--samplers", "cpu_power", "--format", "csv", "-i", str(self._interval), "-o", self._log_file_path, ]
      returncode = subprocess.call(cmd, universal_newlines=True)

    It cause a problem when a password is requested for sudo .

    If we just skip the check, you won't be able to use Powermetrics, will it be OK ?

    To give sudo rights without having to enter a password each time, you can modify the sudoers file with the following command:

    sudo visudo

    Then add the following line at the end of the file:

    username ALL = (root) NOPASSWD: /usr/bin/powermetrics

  7. salob commented on Sep 10, 2025

    @salob
    Contributor

    I found this very confusing it says [codecarbon WARNING @ 19:23:24] We saw that you have a Apple M3 but we don't know it. Please contact us. and then asks for a password but not clear what password it is asking for.

    Image
  8. benoit-cty commented on Sep 11, 2025

    @benoit-cty
    Contributor

    Yes it is confusing. @SaboniAmine do you have an idea on how we could deal with this ?
    At least we need a message to warn the users about why we ask for a password. Maybe we could have a test before to know if we will need a password ?

  9. ElliottKasoar commented on Sep 19, 2025

    @ElliottKasoar

    Can I ask what the status of #752 is? Presumably a sudoless power metric would reduce many of the instances where a password is requested.

  10. salob commented on Nov 15, 2025

    @salob
    Contributor

    just in response to my own query, I had an invalid entry in my visudo file so it was my root password it was asking for. I have hit another issue on mac though. I sometimes see the emissions.csv file is missing emissions and emissions_rate entries. Any idea why these would be empty for some runs but not others ? Anything I can check ? This is what I have in my config file and I have tried setting offline to both True and False

    [codecarbon]
    api_endpoint = https://api.codecarbon.io
    organization_id = <my organization id>
    project_id = <my project id>
    experiment_id = <my experiment id>
    api_key = <my api key>
    measure_power_secs=5
    output_dir=./logs
    log_level=warning
    country_iso_code = IRL
    country_2letter_iso_code = IE
    offline = False
    

    then in my code:

    primary_tracker = EmissionsTracker(project_name="IMDB_Transformer")
    primary_tracker.start()
    ...
    my code
    ...
    primary_tracker.stop()
    
    [codecarbon INFO @ 00:23:23] Codecarbon is taking the configuration from the local file <my path>/ml/.codecarbon.config
    [codecarbon WARNING @ 00:23:23] Multiple instances of codecarbon are allowed to run at the same time.
    [codecarbon WARNING @ 00:23:23] Error while trying to count physical CPUs: [Errno 2] No such file or directory: 'lscpu'. Defaulting to 1.
    [codecarbon WARNING @ 00:23:23] We saw that you have a Apple M3 but we don't know it. Please contact us.
    

    Only thing jumping out right now is could it be to do with the duration ? For longer running programs it seems to be missing

  11. williamacostalora commented on Jun 7, 2026

    @williamacostalora
    Contributor

    Hi! I'm a student contributor in the CodePath AI301 Open Source Capstone and I'd like to work on this issue. I've reviewed the TDP table shared above and the detection logic in emissions_tracker.py. My plan is to add M2/M3/M4 series entries to cpu_power.csv and extend the chip model string matching to cover M4. Happy to start reproducing locally this week, is the TDP data in the comments above the recommended source to use, or is there a preferred reference?

  12. added 4 commits that reference this issue on Jun 15, 2026
    fce8682
    7bab6a3
    0fdb2ee
    7d97afe
  13. added a commit that references this issue on Aug 9, 2026
    c301310
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions