ctheodoris madhavanvenkatesh commited on
Commit
b8fda63
1 Parent(s): 6caf480

Config head node runtime via IP (#234)

Browse files

- Config head node runtime via IP (748f48ac03faa90488220eb2f9b5a76e128a6c06)
- Update minor formatting (c48e37c67945c09e6593d45c40c4cbe0df7cc757)


Co-authored-by: Madhavan Venkatesh <[email protected]>

examples/hyperparam_optimiz_for_disease_classifier.py CHANGED
@@ -18,10 +18,42 @@ import ray
18
  from ray import tune
19
  from ray.tune import ExperimentAnalysis
20
  from ray.tune.suggest.hyperopt import HyperOptSearch
 
21
  runtime_env = {"conda": "base",
22
  "env_vars": {"LD_LIBRARY_PATH": "/path/to/miniconda3/lib:/path/to/sw/lib:/path/to/sw/lib"}}
23
  ray.init(runtime_env=runtime_env)
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  import datetime
26
  import numpy as np
27
  import pandas as pd
@@ -123,6 +155,7 @@ def model_init():
123
  return model
124
 
125
  # define metrics
 
126
  def compute_metrics(pred):
127
  labels = pred.label_ids
128
  preds = pred.predictions.argmax(-1)
 
18
  from ray import tune
19
  from ray.tune import ExperimentAnalysis
20
  from ray.tune.suggest.hyperopt import HyperOptSearch
21
+ ray.shutdown() #engage new ray session
22
  runtime_env = {"conda": "base",
23
  "env_vars": {"LD_LIBRARY_PATH": "/path/to/miniconda3/lib:/path/to/sw/lib:/path/to/sw/lib"}}
24
  ray.init(runtime_env=runtime_env)
25
 
26
+ def initialize_ray_with_check(ip_address):
27
+ """
28
+ Initialize Ray with a specified IP address and check its status and accessibility.
29
+
30
+ Args:
31
+ - ip_address (str): The IP address (with port) to initialize Ray.
32
+
33
+ Returns:
34
+ - bool: True if initialization was successful and dashboard is accessible, False otherwise.
35
+ """
36
+ try:
37
+ ray.init(address=ip_address)
38
+ print(ray.nodes())
39
+
40
+ services = ray.get_webui_url()
41
+ if not services:
42
+ raise RuntimeError("Ray dashboard is not accessible.")
43
+ else:
44
+ print(f"Ray dashboard is accessible at: {services}")
45
+ return True
46
+ except Exception as e:
47
+ print(f"Error initializing Ray: {e}")
48
+ return False
49
+
50
+ # Usage:
51
+ ip = 'your_ip:xxxx' # Replace with your actual IP address and port
52
+ if initialize_ray_with_check(ip):
53
+ print("Ray initialized successfully.")
54
+ else:
55
+ print("Error during Ray initialization.")
56
+
57
  import datetime
58
  import numpy as np
59
  import pandas as pd
 
155
  return model
156
 
157
  # define metrics
158
+ # note: macro f1 score recommended for imbalanced multiclass classifiers
159
  def compute_metrics(pred):
160
  labels = pred.label_ids
161
  preds = pred.predictions.argmax(-1)