Repository navigation
Add force_mode_constant parameter to bypass psutil overhead - #883
benoit-cty with Copilot wants to merge 11 commits into
Conversation
|
Tested working with:
@inimaz as it's me who run Copilot, I can merge by myself 😉 |
0d6d7b9 to
470062e
Compare
inimaz
left a comment
There was a problem hiding this comment.
Nice thanks! Minor comment
| :param force_cpu_power: cpu power to be used instead of automatic detection. | ||
| :param force_ram_power: ram power to be used instead of automatic detection. | ||
| :param pue: PUE (Power Usage Effectiveness) of the datacenter. | ||
| :param force_mode_cpu_load: Force the addition of a CPU in MODE_CPU_LOAD |
There was a problem hiding this comment.
is it possible to have force_mode_cpu_load=True and force_mode_constant=True at the same time? What does it mean in that case?
There was a problem hiding this comment.
Good catch, we need force_mode_constant to take precedence on force_mode_cpu_load.
470062e to
3762ad2
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #883 +/- ##
==========================================
+ Coverage 92.07% 92.24% +0.16%
==========================================
Files 49 49
Lines 5202 5249 +47
==========================================
+ Hits 4790 4842 +52
+ Misses 412 407 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
81985d8 to
5ed7310
Compare
- Make psutil imports graceful in cpu.py and util.py - Add force_mode_constant parameter to EmissionsTracker - Update CPU tracking logic to prioritize force_mode_constant - Add comprehensive test suite for new functionality - Update documentation with new parameter details Co-authored-by: benoit-cty <6603048+benoit-cty@users.noreply.github.com>
d046ab1 to
a3fab12
Compare
|
Rebased onto master by merging it in: kept master's platform-ordered backends and |
This PR adds a new
force_mode_constantparameter toEmissionsTrackerthat allows users to bypass psutil completely and use constant CPU power estimation instead. This addresses significant performance overhead issues wherepsutil.cpu_percent(interval=0.5)calls were causing 10x+ slowdowns in ML training workflows.Problem
Users reported severe performance overhead when tracking short ML training iterations:
The overhead was caused by repeated
psutil.cpu_percent(interval=0.5)calls that take 0.5 seconds each. Additionally, uninstalling psutil to force fallback mode resulted inModuleNotFoundErrordue to unconditional imports.Solution
1. Graceful psutil imports
Made psutil imports conditional in
codecarbon/core/cpu.pyandcodecarbon/core/util.py:2. New force_mode_constant parameter
Added
force_mode_constantparameter to bypass psutil entirely:3. Updated CPU tracking logic
Modified
codecarbon/core/resource_tracker.pyto prioritizeforce_mode_constantbefore all other tracking methods, ensuring it completely bypasses psutil when enabled.Features
psutil.cpu_percent()callsforce_cpu_powerparameterforce_mode_cpu_loadPerformance Impact
Testing shows successful elimination of psutil overhead:
Documentation
Added parameter documentation to
docs/edit/parameters.rst:* - force_mode_constant - | Force the use of constant mode for CPU power consumption measurement, | defaults to ``False``. When enabled, bypasses psutil completely and | uses a constant power consumption based on CPU TDP. Useful when | psutil overhead is significant or psutil is unavailable.Fixes #878.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
get.geojs.iopython /tmp/test_force_constant.py(dns block)python -c from codecarbon import EmissionsTracker import tempfile with tempfile.TemporaryDirectory() as temp_dir: tracker = EmissionsTracker(output_dir=temp_dir) print('Available attributes:', [attr for attr in dir(tracker) if 'resource' in attr.lower() or 'tracker' in attr.lower()])(dns block)python /tmp/test_simple_constant.py(dns block)ip-api.compython /tmp/test_force_constant.py(dns block)python -c from codecarbon import EmissionsTracker import tempfile with tempfile.TemporaryDirectory() as temp_dir: tracker = EmissionsTracker(output_dir=temp_dir) print('Available attributes:', [attr for attr in dir(tracker) if 'resource' in attr.lower() or 'tracker' in attr.lower()])(dns block)python /tmp/test_simple_constant.py(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.