Emissions tracker plugin
Emissions Tracker Plugin Module.
This module defines a plugin for tracking carbon emissions using the codecarbon library.
For usage examples, refer to the docstring of the EmissionsTrackerPlugin class.
class EmissionsTrackerPlugin(*args, **kwargs)
#
Bases: Plugin
A plugin that tracks carbon emissions using codecarbon library.
Usage Example:
from concurrent.futures import ThreadPoolExecutor
from amltk.scheduling import Scheduler
from amltk.scheduling.plugins.emissions_tracker_plugin import EmissionsTrackerPlugin
def some_function(x: int) -> int:
return x * 2
executor = ThreadPoolExecutor(max_workers=1)
# Create a Scheduler instance with the executor
scheduler = Scheduler(executor=executor)
# Create a task with the emissions tracker plugin
task = scheduler.task(some_function, plugins=[
# Pass any codecarbon parameters as args here
EmissionsTrackerPlugin(log_level="info", save_to_file=False)
])
@scheduler.on_start
def on_start():
task.submit(5) # Submit any args here
@task.on_submitted
def on_submitted(future, *args, **kwargs):
print(f"Task was submitted", future, args, kwargs)
@task.on_done
def on_done(future):
# Result is the return value of the function
print("Task done: ", future.result())
scheduler.run()
PARAMETER | DESCRIPTION |
---|---|
*args |
Additional arguments to pass to codecarbon library.
TYPE:
|
**kwargs |
Additional keyword arguments to pass to codecarbon library.
TYPE:
|
You can pass any codecarbon parameters as args to EmissionsTrackerPlugin. Please refer to the official codecarbon documentation for more details: mlco2.github.io/codecarbon/parameters.html
Source code in src/amltk/scheduling/plugins/emissions_tracker_plugin.py
name: ClassVar
classvar
attr
#
The name of the plugin.
def attach_task(task)
#
def pre_submit(fn, *args, **kwargs)
#
Pre-submit hook.
Source code in src/amltk/scheduling/plugins/emissions_tracker_plugin.py
def copy()
#
def __rich__()
#
Return a rich panel.