Skip to content

Commit

Permalink
update copy
Browse files Browse the repository at this point in the history
  • Loading branch information
jlewitt1 committed May 13, 2024
1 parent c242133 commit 59ea240
Showing 1 changed file with 32 additions and 40 deletions.
72 changes: 32 additions & 40 deletions runhouse/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def ssh(cluster_name: str, up: bool = typer.Option(False, help="Start the cluste

def _adjust_resource_type(resource_type: str):
"""
status helping function. transforms a str form runhouse.resources.{X.Y...}.resource_type to runhouse.resource_type
Transforms a str form runhouse.resources.{X.Y...}.resource_type to runhouse.resource_type
"""
try:
resource_type = resource_type.split(".")[-1]
Expand All @@ -150,13 +150,10 @@ def _adjust_resource_type(resource_type: str):
return resource_type


# cannot import the resource type


def _resource_name_to_rns(name: str):
"""
If possible, transform the resource name to a rns address.
If not, return the name as is (it is the key in the object store).
If possible, transform the resource name to its RNS address. Otherwise, return the name as defined as by its
key in the object store.
"""
resource_config = rns_client.load_config(name)
if resource_config and resource_config.get("resource_type") != "env":
Expand All @@ -167,20 +164,19 @@ def _resource_name_to_rns(name: str):

def _print_cluster_config(cluster_config: Dict):
"""
helping function to the _print_status, printing the relevant info from the cluster config.
:param cluster_config:
Helping function to the `_print_status` which prints the relevant info from the cluster config.
"""
if "name" in cluster_config.keys():
console.print(cluster_config.get("name"))

first_info_to_print = [
top_level_config = [
"server_port",
"server_pid",
"den_auth",
"server_connection_type",
]

backend_config_to_print = [
backend_config = [
"resource_subtype",
"use_local_telemetry",
"domain",
Expand All @@ -190,35 +186,36 @@ def _print_cluster_config(cluster_config: Dict):
]

if cluster_config.get("resource_subtype") != "Cluster":
backend_config_to_print.append("autostop_mins")
backend_config.append("autostop_mins")

if cluster_config.get("default_env") and isinstance(
cluster_config.get("default_env"), Dict
):
cluster_config["default_env"] = cluster_config["default_env"]["name"]

for info in first_info_to_print:
console.print(f"{BULLET_UNICODE} {info}: {cluster_config[info]}")
for key in top_level_config:
console.print(f"{BULLET_UNICODE} {key}: {cluster_config[key]}")

console.print("\u2022 backend config:")
for info in backend_config_to_print:
if info == "autostop_mins" and cluster_config[info] == -1:
for key in backend_config:
if key == "autostop_mins" and cluster_config[key] == -1:
console.print(
f"{DOUBLE_SPACE_UNICODE}{BULLET_UNICODE} {info}: autostop disabled"
f"{DOUBLE_SPACE_UNICODE}{BULLET_UNICODE} {key}: autostop disabled"
)
else:
console.print(
f"{DOUBLE_SPACE_UNICODE}{BULLET_UNICODE} {info}: {cluster_config[info]}"
f"{DOUBLE_SPACE_UNICODE}{BULLET_UNICODE} {key}: {cluster_config[key]}"
)


def _print_envs_info(envs: Dict, envs_info: Dict, current_cluster: Cluster):
"""
Prints info about the envs in the current_cluster.
Prints the resources in each env, and the CPU and GPU usage of the env (if exists).
:param envs: Dict of envs in each cluster, and the resources associated with them.
:param envs_info: Dict of cpu and gpu info of the envs.
:param current_cluster: The cluster whose status we are printing.
Prints the resources in each env, and the CPU and GPU usage of the env (where relevant).
envs (dict): Dict of envs in each cluster, and the resources associated with them.
envs_info (dict): Dict of cpu and gpu info of the envs.
current_cluster (Cluster): The cluster whose status we are printing.
"""
# Print headline
envs_in_cluster_headline = "Serving 🍦 :"
Expand All @@ -227,7 +224,7 @@ def _print_envs_info(envs: Dict, envs_info: Dict, current_cluster: Cluster):
if len(envs) == 0:
console.print("This cluster has no environment nor resources.")

first_envs_to_print = []
envs_with_no_resources = []

# First: if the default env does not have resources, print it.
default_env_name = current_cluster.default_env.name
Expand All @@ -243,13 +240,13 @@ def _print_envs_info(envs: Dict, envs_info: Dict, current_cluster: Cluster):
)

else:
# case where the default env have other resources. We make sure that our of all the envs which have reosirces,
# case where the default env have other resources. We make sure that our of all the envs which have resources,
# the default_env will be printed first.
first_envs_to_print = [default_env_name]
envs_with_no_resources = [default_env_name]

# Make sure to print envs with no resources first.
# (the only resource they have is a runhouse.env, which is the env itself).
first_envs_to_print = first_envs_to_print + [
envs_with_no_resources = envs_with_no_resources + [
env_name
for env_name in envs
if (len(envs[env_name]) <= 1 and env_name != default_env_name)
Expand All @@ -259,21 +256,20 @@ def _print_envs_info(envs: Dict, envs_info: Dict, current_cluster: Cluster):
# If the env have packages installed, that means that it contains an env resource. In that case:
# * If the env contains only itself, we will print that the env contains only the installed packages.
# * Else, we will print the resources (rh.function, th.module) associated with the env.

envs_to_print = first_envs_to_print + [
loaded_envs = envs_with_no_resources + [
env_name
for env_name in envs
if env_name not in first_envs_to_print + [default_env_name]
if env_name not in envs_with_no_resources + [default_env_name]
]

for env_name in envs_to_print:
for env_name in loaded_envs:
resources_in_env = envs[env_name]
env_process_info = envs_info[env_name]
current_env = [
resource for resource in resources_in_env if resource["name"] == env_name
]

# sometimes the env itself is not a resource (key) inside the env's servlet.
# sometimes the env itself does not have a key associated with the env's servlet.
if len(current_env) == 0:
env_name_print = _resource_name_to_rns(env_name)
env_type = "runhouse.Env"
Expand Down Expand Up @@ -302,14 +298,12 @@ def _print_envs_info(envs: Dict, envs_info: Dict, current_cluster: Cluster):
)
cpu_usage_percent = round(float(env_cpu_info["cpu_usage_percent"]), 2)

cpu_usage_summery = f"{DOUBLE_SPACE_UNICODE}CPU: {cpu_usage_percent}% | Memory: {memory_usage_gb} / {total_cluster_memory} Gb ({cpu_memory_usage_percent}%)"
cpu_usage_summary = f"{DOUBLE_SPACE_UNICODE}CPU: {cpu_usage_percent}% | Memory: {memory_usage_gb} / {total_cluster_memory} Gb ({cpu_memory_usage_percent}%)"

console.print(cpu_usage_summery)
console.print(cpu_usage_summary)

# Print GPU info
env_gpu_info = env_process_info.get("env_gpu_usage")

# sometimes the cluster has no GPU, therefore the env_gpu_info is an empty dictionary.
if env_gpu_info:
# get the gpu usage info, and convert it to GB.
total_gpu_memory = math.ceil(
Expand All @@ -322,8 +316,8 @@ def _print_envs_info(envs: Dict, envs_info: Dict, current_cluster: Cluster):
gpu_memory_usage_percent = round(
float(used_gpu_memory / total_gpu_memory) * 100, 2
)
gpu_usage_summery = f"{DOUBLE_SPACE_UNICODE}GPU: {gpu_util_percent}% | Memory: {used_gpu_memory} / {total_gpu_memory} Gb ({gpu_memory_usage_percent}%)"
console.print(gpu_usage_summery)
gpu_usage_summary = f"{DOUBLE_SPACE_UNICODE}GPU: {gpu_util_percent}% | Memory: {used_gpu_memory} / {total_gpu_memory} Gb ({gpu_memory_usage_percent}%)"
console.print(gpu_usage_summary)

resources_in_env = [
resource for resource in resources_in_env if resource is not current_env
Expand All @@ -332,7 +326,7 @@ def _print_envs_info(envs: Dict, envs_info: Dict, current_cluster: Cluster):
if len(resources_in_env) == 0:
# No resources were found in the env, only the associated installed python reqs were installed.
console.print(
f"{DOUBLE_SPACE_UNICODE}This environment has only python packages installed, if such provided. No resources were "
f"{DOUBLE_SPACE_UNICODE}This environment has only python packages installed. No resources were "
"found."
)

Expand All @@ -348,10 +342,8 @@ def _print_envs_info(envs: Dict, envs_info: Dict, current_cluster: Cluster):
def _print_status(config: dict, current_cluster: Cluster):
"""
Prints the status of the cluster to the console
:param config: cluster's config
:return: cluster's config
config (dict): cluster's config
"""

cluster_config = config.get("cluster_config")
envs = cluster_config.pop("envs", [])
envs_info = config.pop("env_servlet_actors", [])
Expand Down

0 comments on commit 59ea240

Please sign in to comment.