MIT License

项目介绍

mlco2/codecarbon 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 MIT License 许可证,目前获得 1.9k 个 Star、351 次 Fork。

仓库全名
mlco2/codecarbon
开源许可证
MIT License
Star 数
1.9k
Fork 数
351
未关闭 Issue
147

README 摘要

Track & reduce CO₂ emissions from your local computing Estimate and track carbon emissions from your computer, quantify and analyze their impact. A lightweight, easy to use Python library – Simple API to track emissions Open source, free & community driven – Built by and for the community Effective visual outputs – Put emissions in context with real-world equivalents Tracking GenAI API calls? CodeCarbon measures…

完整内容见 GitHub 原始 README 或本页 。

常见问题

codecarbon 用什么语言开发?

主要使用 Python 编写,采用 MIT License 许可证,目前有 1.9k 个 Star。

codecarbon 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 codecarbon 的源码?

可以直接克隆仓库:git clone https://github.com/mlco2/codecarbon.git,默认分支为 master;安装与运行步骤见仓库 README。

codecarbon 最近还在维护吗?

仓库最近一次更新为 16 小时前,当前有 147 个未关闭 Issue;Star 数为 1.9k,可作为社区活跃度的参考。

关于

GitHub 原始描述(英文)

Track emissions from Compute and recommend ways to reduce their impact on the environment.

描述取自 GitHub 官方 API,保持仓库作者书写的原文。

简要分析

热度分
2671
价值分
1265
活跃状态
活跃

语言占比

CSS
Dockerfile
HTML
JavaScript
Jinja
Mako
Python
Shell
TypeScript

Release

README

banner

Track & reduce CO₂ emissions from your local computing

Estimate and track carbon emissions from your computer, quantify and analyze their impact.

DOI OpenSSF Scorecard codecov Discord

  • A lightweight, easy to use Python library – Simple API to track emissions
  • Open source, free & community driven – Built by and for the community
  • Effective visual outputs – Put emissions in context with real-world equivalents

Tracking GenAI API calls? CodeCarbon measures emissions from local computing (your hardware). To track emissions from remote GenAI API calls (OpenAI, Anthropic, Mistral, etc.), use EcoLogits. Both tools are complementary.

Join the community! Have questions, want to share your work, or contribute? Join us on Discord – we’re here to help and excited to hear from you!

Installation

pip install codecarbon

If you use Conda:

conda activate your_env
pip install codecarbon

More installation options: installation docs.

Something not working, or numbers that look wrong? See the troubleshooting guide.

Quickstart (Python)

from codecarbon import EmissionsTracker

tracker = EmissionsTracker()
tracker.start()

# Your code here

emissions = tracker.stop()
print(f"Emissions: {emissions} kg CO₂")

Learn more →

Quickstart (CLI)

Track a command without changing your code:

codecarbon monitor --no-api -- python train.py

Detect your hardware:

codecarbon detect

Full CLI guide: CLI tutorial.

Configuration

You can configure CodeCarbon using:

  • ~/.codecarbon.config (global)
  • ./.codecarbon.config (project-local)
  • CODECARBON_* environment variables
  • Python arguments (EmissionsTracker(...))

Configuration precedence and examples: configuration guide.

How it works

We created a Python package that estimates your hardware electricity power consumption (GPU + CPU + RAM) and we apply to it the carbon intensity of the region where the computing is done.

CodeCarbon focuses on the main compute components it can measure or estimate directly: CPU, GPU, and RAM. It does not separately model disk I/O, network transfers, displays, cooling, or other peripherals because those sources are usually much smaller for local code-level experiments and are not exposed through the same low-overhead measurement interfaces.

On Linux, CodeCarbon reads Intel RAPL hardware energy counters when it can. If those counters are not readable it falls back to estimating from CPU load, which is less accurate — see getting accurate CPU measurements to enable them.

calculation Summary

We explain more about this calculation in the Methodology section of the documentation, and we document how close those numbers are — and where they are not close — in Accuracy and validation.

Visualize

You can visualize your experiment emissions on the dashboard or locally with carbonboard.

dashboard

Section Description
Quickstart Get started in 5 minutes
Installation Install CodeCarbon
CLI Tutorial Track emissions from the command line
Python API Tutorial Track emissions in Python code
Comparing Model Efficiency Measure carbon efficiency across ML models
Accurate CPU measurements (Linux/RAPL) Read real energy counters instead of estimating
API Reference Full parameter documentation
Framework examples (scikit-learn) Task-oriented ML framework examples
Methodology How emissions are calculated
Accuracy and validation How accurate the numbers are, and why
Alternatives comparison CodeCarbon vs other carbon tracking tools
When to use CodeCarbon vs EcoLogits Choose the right tool
EcoLogits Track emissions from GenAI API calls
Discord Community Chat with us and the community

Contributing

We are hoping that the open-source community will help us edit the code and make it better!

You are welcome to open issues, even suggest solutions and better still contribute the fix/improvement! We can guide you if you’re not sure where to start but want to help us out.

Check out our contribution guidelines.

Feel free to chat with us on Discord.

Citation

If you find CodeCarbon useful for your research, use the Cite this repository button in the GitHub sidebar, or copy the BibTeX below. The DOI is a Zenodo concept DOI: it always resolves to the latest release. All versions and formats are on Zenodo.

@software{codecarbon,
  author       = {Benoit Courty and
                  Amine Saboni and
                  Iñigo Imaz Chacón and
                  Sasha Luccioni and
                  Victor Schmidt and
                  Boris Feld and
                  David Berenstein and
                  Jérémy Lecourt and
                  Mathilde Léval and
                  Luis Blanche and
                  Marion Coutarel and
                  Alexis Bogroff and
                  Patrick Lloret and
                  {The CodeCarbon contributors}},
  title        = {CodeCarbon: Estimate and track carbon emissions from computing},
  publisher    = {Zenodo},
  version      = {3.3.2},
  doi          = {10.5281/zenodo.4658424},
  url          = {https://doi.org/10.5281/zenodo.4658424}
}

Contact

Feel free to chat with us on Discord.

Codecarbon was formerly developed by volunteers from Mila and the DataForGoodFR community alongside donated professional time of engineers at Comet.ml and BCG GAMMA.

Now CodeCarbon is supported by Code Carbon, a French non-profit organization whose mission is to accelerate the development and adoption of CodeCarbon.

Sponsors

Clever Cloud     Data For Good     GitHub     Mozilla

评论

暂无评论