-
-
Notifications
You must be signed in to change notification settings - Fork 229
Add force_mode_constant parameter to bypass psutil overhead #883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Tested working with:
@inimaz as it's me who run Copilot, I can merge by myself 😉 |
- 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>
0d6d7b9 to
470062e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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.