Skip to content
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

Sustainability POC Add Optimization #3515

Conversation

dmatch01
Copy link

@dmatch01 dmatch01 commented May 7, 2024

Initial implementation of sustainability support. Includes cost plus carbon footprint optimization. To enable cost plus carbon footprint optimization launch skypilot with the command line option--optimize-cost-target=carbon_footprint.

Tested (run the relevant ones):

  • Code formatting: bash format.sh
  • [n/a] Any manual or new tests for this PR (please specify below)
  • All smoke tests: pytest tests/test_smoke.py
  • Relevant individual smoke tests: pytest tests/test_smoke.py::test_fill_in_the_name
  • Backward compatibility tests: conda deactivate; bash -i tests/backward_compatibility_tests.sh

@dmatch01
Copy link
Author

dmatch01 commented May 7, 2024

@romilbhardwaj Ready for review. Please let me know if you have any questions.

Copy link
Collaborator

@romilbhardwaj romilbhardwaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dmatch01! Took a quick look, will continue testing/reading.

sky/optimizer.py Outdated
@@ -894,13 +1014,18 @@ def sort_key(row, accelerator_spot_list=accelerator_spot_list):

rows = sorted(rows, key=sort_key)
else:
rows = sorted(rows, key=lambda row: float(row.cost_str))
rows = sorted(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there are clouds with Unknown footprint, the optimizer selects that cloud. Is this behavior expected? Should we instead pick the lowest across all non-unknown values?

image

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I was able to recreate with a local k8s. I'm on it!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

region: Optional[str],
zone: Optional[str]) -> float:
"""Returns the hourly carbon cost for an instance type."""
raise NotImplementedError
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of NotImplementedError, should we return -1 as the default base implementation? I had some other clouds enabled (cudo, paperspace), and had to disable them otherwise I'd get this error:

Traceback (most recent call last):
  File "/Users/romilb/tools/anaconda3/bin/sky", line 8, in <module>
    sys.exit(cli())
  File "/Users/romilb/tools/anaconda3/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/Users/romilb/tools/anaconda3/lib/python3.9/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/utils/common_utils.py", line 354, in _record
    return f(*args, **kwargs)
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/cli.py", line 828, in invoke
    return super().invoke(ctx)
  File "/Users/romilb/tools/anaconda3/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/romilb/tools/anaconda3/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/romilb/tools/anaconda3/lib/python3.9/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/utils/common_utils.py", line 375, in _record
    return f(*args, **kwargs)
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/cli.py", line 1143, in launch
    _launch_with_confirm(task,
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/cli.py", line 592, in _launch_with_confirm
    dag = sky.optimize(dag, objective_target=optimize_cost_target_enum)
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/optimizer.py", line 154, in optimize
    unused_best_plan = Optimizer._optimize_dag(
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/optimizer.py", line 1138, in _optimize_dag
    Optimizer._estimate_nodes_cost_or_time(local_topo_order,
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/optimizer.py", line 302, in _estimate_nodes_cost_or_time
    _fill_in_launchable_resources(
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/optimizer.py", line 1395, in _fill_in_launchable_resources
    _make_launchables_for_valid_region_zones(
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/optimizer.py", line 1304, in _make_launchables_for_valid_region_zones
    ci_cost = launchable_res_cp.get_carbon_cost(execution_time)
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/resources.py", line 1007, in get_carbon_cost
    carbs = self.cloud.instance_type_to_hourly_carbon_cost(
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/clouds/cloud.py", line 247, in instance_type_to_hourly_carbon_cost
    raise NotImplementedError

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

@dmatch01 dmatch01 force-pushed the sustainability_poc_add_optimization branch 2 times, most recently from b92793f to 82a31d0 Compare May 9, 2024 22:47
@dmatch01
Copy link
Author

dmatch01 commented May 9, 2024

@romilbhardwaj Made fixes, ready for review.

Copy link
Collaborator

@romilbhardwaj romilbhardwaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dmatch01! Left some comments, otherwise looks mostly good to me!

examples/sustainability/README.md Outdated Show resolved Hide resolved
Comment on lines +158 to +159
carbon_footprint_objective=objective_target ==
OptimizeObjectiveTarget.CARBON_FOOTPRINT,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should be the behavior when the task requests a cloud that does not have any carbon information? E.g. this command currently fails:

sky launch --optimize-cost-target=carbon_footprint --cloud  lambda
Traceback (most recent call last):
  File "/Users/romilb/tools/anaconda3/bin/sky", line 8, in <module>
    sys.exit(cli())
  File "/Users/romilb/tools/anaconda3/lib/python3.9/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/Users/romilb/tools/anaconda3/lib/python3.9/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/utils/common_utils.py", line 354, in _record
    return f(*args, **kwargs)
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/cli.py", line 828, in invoke
    return super().invoke(ctx)
  File "/Users/romilb/tools/anaconda3/lib/python3.9/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/romilb/tools/anaconda3/lib/python3.9/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/romilb/tools/anaconda3/lib/python3.9/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/utils/common_utils.py", line 375, in _record
    return f(*args, **kwargs)
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/cli.py", line 1143, in launch
    _launch_with_confirm(task,
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/cli.py", line 592, in _launch_with_confirm
    dag = sky.optimize(dag, objective_target=optimize_cost_target_enum)
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/optimizer.py", line 155, in optimize
    unused_best_plan = Optimizer._optimize_dag(
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/optimizer.py", line 1181, in _optimize_dag
    local_best_plan, best_total_objective = Optimizer._optimize_by_dp(
  File "/Users/romilb/Romil/Berkeley/Research/sky-experiments/sky/optimizer.py", line 481, in _optimize_by_dp
    best_resources = dp_point_backs[node][best_resources]
KeyError: DummyResources

If carbon optimization fails (e.g., no cloud in the search space has carbon information), is it possible to fall back to $ optimization?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no worries if this is complex to implement, we can do it in future versions. As a stop gap, would be nice to print out a cleaner error/warning.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take a look at a fix to address failure.

with rebase.

Update examples/sustainability/README.md

Fix to handle carbon footprint optimization without a supported carbon supported cloud in the optimization plan.

Signed-off-by: dmatch01 <darroyo@us.ibm.com>
Co-authored-by: Romil Bhardwaj <romil.bhardwaj@gmail.com>
@dmatch01 dmatch01 force-pushed the sustainability_poc_add_optimization branch from c91aba2 to fbd01f0 Compare May 28, 2024 08:11
@dmatch01
Copy link
Author

@romilbhardwaj Made a fix to handle special use case of carbon footprint optimization with only unsupported clouds. The fix detects this condition and chooses cost price to optimize in place of carbon footprint. The output still respects the user request to optimize based on carbon footprint and produces information and summary related to unknown carbon footprints for each cloud. See example below:

$ sky launch --optimize-cost-target=carbon_footprint --cloud oci sky/my_task.yaml
Task from YAML spec: sky/my_task.yaml
I 05-28 01:13:54 optimizer.py:788] == Optimizer ==
I 05-28 01:13:54 optimizer.py:825] Estimated cost:  Unknown (g CO2e) / hour
I 05-28 01:13:54 optimizer.py:825] 
I 05-28 01:13:54 optimizer.py:977] Considered resources (1 node):
I 05-28 01:13:54 optimizer.py:1088] --------------------------------------------------------------------------------------------------------------------
I 05-28 01:13:54 optimizer.py:1088]  CLOUD   INSTANCE    vCPUs   Mem(GB)   ACCELERATORS   REGION/ZONE    COST ($)   CARBON FOOTPRINT(g CO2e)   CHOSEN   
I 05-28 01:13:54 optimizer.py:1088] --------------------------------------------------------------------------------------------------------------------
I 05-28 01:13:54 optimizer.py:1088]  OCI     VM.GPU3.1   12      90        V100:1         us-sanjose-1   2.95       Unknown                       ✔     
I 05-28 01:13:54 optimizer.py:1088] --------------------------------------------------------------------------------------------------------------------
I 05-28 01:13:54 optimizer.py:1088] 

Copy link
Collaborator

@romilbhardwaj romilbhardwaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dmatch01! This is good to be merged. Thanks for your contributions!

image

@romilbhardwaj romilbhardwaj merged commit 5e9d12f into skypilot-org:sustainability_poc May 29, 2024
@dmatch01
Copy link
Author

Thanks @romilbhardwaj!

@dmatch01 dmatch01 deleted the sustainability_poc_add_optimization branch May 29, 2024 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants