diff --git a/python/ray/state.py b/python/ray/state.py index d176689019a33..d16a6f3ca40ba 100644 --- a/python/ray/state.py +++ b/python/ray/state.py @@ -688,7 +688,7 @@ def cluster_resources(self): for key, value in client["Resources"].items(): resources[key] += value for k, v in resources.items(): - resources[k] = format_resource(k, v) + resources[k] = format_resource(k, v, use_float=True) return dict(resources) def _live_client_ids(self): @@ -757,7 +757,7 @@ def available_resources(self): subscribe_client.close() for k, v in total_available_resources.items(): - total_available_resources[k] = format_resource(k, v) + total_available_resources[k] = format_resource(k, v, use_float=True) return dict(total_available_resources) def _error_messages(self, job_id): diff --git a/python/ray/utils.py b/python/ray/utils.py index 7eec64c642863..b332f1c8c98cc 100644 --- a/python/ray/utils.py +++ b/python/ray/utils.py @@ -373,10 +373,10 @@ def resources_from_resource_arguments( return resources -def format_resource(resource_name, quantity): +def format_resource(resource_name, quantity, use_float=False): if resource_name in ["object_store_memory", "memory"]: - return "{} GiB".format( - round(ray_constants.from_memory_units(quantity) / (1024**3), 2)) + value = round(ray_constants.from_memory_units(quantity) / (1024**3), 2) + return value if use_float else "{} GiB".format(value) if isinstance(quantity, float) and quantity.is_integer(): quantity = int(quantity) return round(quantity, 2)