Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void testEmptyNodeLabels() {
}

public void testSetNodeLabels() {
System.setProperty("ray.head-args.0", "--labels=\"gpu_type=A100,azone=azone-1\"");
System.setProperty("ray.head-args.0", "--labels={\"gpu_type\":\"A100\",\"azone\":\"azone-1\"}");
try {
Ray.init();
List<NodeInfo> nodeInfos = Ray.getRuntimeContext().getAllNodeInfo();
Expand Down
100 changes: 0 additions & 100 deletions python/ray/_private/label_utils.py

This file was deleted.

6 changes: 4 additions & 2 deletions python/ray/_private/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
from typing import Dict, List, Optional

import ray._private.ray_constants as ray_constants
from ray._private.label_utils import validate_node_labels
from ray._private.utils import check_ray_client_dependencies_installed
from ray._private.utils import (
validate_node_labels,
check_ray_client_dependencies_installed,
)


logger = logging.getLogger(__name__)
Expand Down
37 changes: 37 additions & 0 deletions python/ray/_private/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,43 @@ def update_envs(env_vars: Dict[str, str]):
os.environ[key] = result


def parse_node_labels_json(
labels_json: str, cli_logger, cf, command_arg="--labels"
) -> Dict[str, str]:
try:
labels = json.loads(labels_json)
if not isinstance(labels, dict):
raise ValueError(
"The format after deserialization is not a key-value pair map"
)
for key, value in labels.items():
if not isinstance(key, str):
raise ValueError("The key is not string type.")
if not isinstance(value, str):
raise ValueError(f'The value of the "{key}" is not string type')
except Exception as e:
cli_logger.abort(
"`{}` is not a valid JSON string, detail error:{}"
"Valid values look like this: `{}`",
cf.bold(f"{command_arg}={labels_json}"),
str(e),
cf.bold(f'{command_arg}=\'{{"gpu_type": "A100", "region": "us"}}\''),
)
return labels


def validate_node_labels(labels: Dict[str, str]):
if labels is None:
return
for key in labels.keys():
if key.startswith(ray_constants.RAY_DEFAULT_LABEL_KEYS_PREFIX):
raise ValueError(
f"Custom label keys `{key}` cannot start with the prefix "
f"`{ray_constants.RAY_DEFAULT_LABEL_KEYS_PREFIX}`. "
f"This is reserved for Ray defined labels."
)


def parse_pg_formatted_resources_to_original(
pg_formatted_resources: Dict[str, float]
) -> Dict[str, float]:
Expand Down
49 changes: 4 additions & 45 deletions python/ray/scripts/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,11 @@
import ray
import ray._private.ray_constants as ray_constants
import ray._private.services as services
from ray._private.label_utils import (
parse_node_labels_from_yaml_file,
parse_node_labels_string,
)
from ray._private.utils import (
check_ray_client_dependencies_installed,
load_class,
parse_resources_json,
parse_node_labels_json,
)
from ray._private.internal_api import memory_summary
from ray._private.usage import usage_lib
Expand Down Expand Up @@ -638,19 +635,9 @@ def debug(address: str, verbose: bool):
"--labels",
required=False,
hidden=True,
default="",
type=str,
help="a string list of key-value pairs mapping label name to label value."
"These values take precedence over conflicting keys passed in from --labels-file."
'Ex: --labels "key1=val1,key2=val2"',
)
@click.option(
"--labels-file",
required=False,
hidden=True,
default="",
default="{}",
type=str,
help="a path to a YAML file containing a dictionary mapping of label keys to values.",
help="a JSON serialized dictionary mapping label name to label value.",
)
@click.option(
"--include-log-monitor",
Expand Down Expand Up @@ -708,7 +695,6 @@ def start(
ray_debugger_external,
disable_usage_stats,
labels,
labels_file,
include_log_monitor,
):
"""Start Ray processes manually on the local machine."""
Expand All @@ -729,34 +715,7 @@ def start(
node_ip_address = services.resolve_ip_for_localhost(node_ip_address)

resources = parse_resources_json(resources, cli_logger, cf)

# Compose labels passed in with `--labels` and `--labels-file`.
# The label value from `--labels` will overrwite the value of any duplicate keys.
try:
labels_from_file_dict = parse_node_labels_from_yaml_file(labels_file)
except Exception as e:
cli_logger.abort(
"The file at `{}` is not a valid YAML file, detailed error:{}"
"Valid values look like this: `{}`",
cf.bold(f"--labels-file={labels_file}"),
str(e),
cf.bold("--labels-file='gpu_type: A100\nregion: us'"),
)
try:
labels_from_string = parse_node_labels_string(labels)
except Exception as e:
cli_logger.abort(
"`{}` is not a valid string of key-value pairs, detail error:{}"
"Valid values look like this: `{}`",
cf.bold(f"--labels={labels}"),
str(e),
cf.bold('--labels="key1=val1,key2=val2"'),
)
labels_dict = (
{**labels_from_file_dict, **labels_from_string}
if labels_from_file_dict
else labels_from_string
)
labels_dict = parse_node_labels_json(labels, cli_logger, cf)

if plasma_store_socket_name is not None:
warnings.warn(
Expand Down
1 change: 0 additions & 1 deletion python/ray/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ py_test_module_list(
py_test_module_list(
size = "medium",
files = [
"test_label_utils.py",
"test_minimal_install.py",
"test_runtime_env_ray_minimal.py",
"test_utils.py",
Expand Down
121 changes: 0 additions & 121 deletions python/ray/tests/test_label_utils.py

This file was deleted.

2 changes: 1 addition & 1 deletion python/ray/tests/test_node_label_scheduling_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_node_id():

@pytest.mark.parametrize(
"call_ray_start",
["ray start --head --labels gpu_type=A100,region=us"],
['ray start --head --labels={"gpu_type":"A100","region":"us"}'],
indirect=True,
)
def test_node_label_scheduling_basic(call_ray_start):
Expand Down
Loading