Skip to content

Commit

Permalink
Beautify the output table of infeasibility reasons.
Browse files Browse the repository at this point in the history
  • Loading branch information
Conless committed Oct 28, 2024
1 parent 6932181 commit 575ba56
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions sky/backends/cloud_vm_ray_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import pathlib
import re
import shlex
import shutil
import signal
import subprocess
import sys
Expand Down Expand Up @@ -151,15 +152,6 @@
# might be added during ssh.
_MAX_INLINE_SCRIPT_LENGTH = 120 * 1024

# The summarized reason for each type of exception
_EXCEPTION_SUMMARY_MESSAGE = {
exceptions.InvalidClusterNameError: 'Cluster name is invalid.',
exceptions.NotSupportedError: 'Cloud does not support requested features.',
exceptions.CloudUserIdentityError: 'Cloud user identity is invalid.',
exceptions.ResourcesUnavailableError: 'Requested resources cannot be '
'satisfied on this cloud.',
}

_RESOURCES_UNAVAILABLE_LOG = (
'The reasons for the infeasibility of each resource are summarized below. '
'For detailed explanations, please refer to the log above.')
Expand Down Expand Up @@ -2069,10 +2061,17 @@ def provision_with_retries(
# ends here.
table = log_utils.create_table(['Resource', 'Reason'])
for (resource, exception) in resource_exceptions.items():
table.add_row([
resource,
_EXCEPTION_SUMMARY_MESSAGE[exception.__class__]
])
launched_resource_str = str(resource)
# accelerator_args is way too long.
# Convert from:
# GCP(n1-highmem-8, {'tpu-v2-8': 1}, accelerator_args={'runtime_version': '2.12.0'} # pylint: disable=line-too-long
# to:
# GCP(n1-highmem-8, {'tpu-v2-8': 1}...)
pattern = ', accelerator_args={.*}'
launched_resource_str = re.sub(pattern, '...',
launched_resource_str)
table.add_row([launched_resource_str, exception])
table.max_table_width = shutil.get_terminal_size().columns
raise exceptions.ResourcesUnavailableError(
_RESOURCES_UNAVAILABLE_LOG + '\n' + table.get_string(),
failover_history=failover_history)
Expand Down

0 comments on commit 575ba56

Please sign in to comment.