Skip to content

Commit

Permalink
Migrate the code to the latest changes in DW
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolovison committed Apr 26, 2024
1 parent 7915318 commit 026f4b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@ def ray_fn(openshift_server: str, openshift_token: str) -> int:
import ray
from codeflare_sdk.cluster.auth import TokenAuthentication
from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration
from codeflare_sdk import generate_cert

print("before login")
auth = TokenAuthentication(token=openshift_token, server=openshift_server, skip_tls=True)
auth_return = auth.login()
print(f'auth_return: "{auth_return}"')
print("after login")
# openshift_oauth is a workaround for RHOAIENG-3981
cluster = Cluster(
ClusterConfiguration(
name="raytest",
openshift_oauth=True,
num_workers=1,
head_cpus="500m",
min_memory=1,
max_memory=1,
num_gpus=0,
image="quay.io/project-codeflare/ray:latest-py39-cu118",
instascale=False,
verify_tls=False
)
)

Expand All @@ -48,7 +48,9 @@ def ray_fn(openshift_server: str, openshift_token: str) -> int:
# reset the ray context in case there's already one.
ray.shutdown()
# establish connection to ray cluster
ray.init(address=ray_cluster_uri)
generate_cert.generate_tls_cert(cluster.config.name, cluster.config.namespace)
generate_cert.export_env(cluster.config.name, cluster.config.namespace)
ray.init(address=cluster.cluster_uri())
print("Ray cluster is up and running: ", ray.is_initialized())

@ray.remote
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,15 @@ deploymentSpec:
\ *\n\ndef ray_fn(openshift_server: str, openshift_token: str) -> int:\n\
\ import ray\n from codeflare_sdk.cluster.auth import TokenAuthentication\n\
\ from codeflare_sdk.cluster.cluster import Cluster, ClusterConfiguration\n\
\n print(\"before login\")\n auth = TokenAuthentication(token=openshift_token,\
\ server=openshift_server, skip_tls=True)\n auth_return = auth.login()\n\
\ print(f'auth_return: \"{auth_return}\"')\n print(\"after login\"\
)\n cluster = Cluster(\n ClusterConfiguration(\n name=\"\
raytest\",\n # namespace must exist, and it is the same from\
\ 432__data-science-pipelines-tekton.robot\n namespace=\"pipelineskfp1\"\
,\n num_workers=1,\n head_cpus=\"500m\",\n \
\ min_memory=1,\n max_memory=1,\n num_gpus=0,\n\
\ image=\"quay.io/project-codeflare/ray:latest-py39-cu118\",\n\
\ instascale=False,\n )\n )\n\n # always clean the\
\ from codeflare_sdk import generate_cert\n\n print(\"before login\"\
)\n auth = TokenAuthentication(token=openshift_token, server=openshift_server,\
\ skip_tls=True)\n auth_return = auth.login()\n print(f'auth_return:\
\ \"{auth_return}\"')\n print(\"after login\")\n cluster = Cluster(\n\
\ ClusterConfiguration(\n name=\"raytest\",\n \
\ num_workers=1,\n head_cpus=\"500m\",\n min_memory=1,\n\
\ max_memory=1,\n num_gpus=0,\n image=\"\
quay.io/project-codeflare/ray:latest-py39-cu118\",\n instascale=False,\n\
\ verify_tls=False\n )\n )\n\n # always clean the\
\ resources\n cluster.down()\n print(cluster.status())\n cluster.up()\n\
\ cluster.wait_ready()\n print(cluster.status())\n print(cluster.details())\n\
\n ray_dashboard_uri = cluster.cluster_dashboard_uri()\n ray_cluster_uri\
Expand All @@ -67,10 +66,12 @@ deploymentSpec:
\ empty\n assert ray_cluster_uri, \"Ray cluster needs to be started and\
\ set before proceeding\"\n\n # reset the ray context in case there's\
\ already one.\n ray.shutdown()\n # establish connection to ray cluster\n\
\ ray.init(address=ray_cluster_uri)\n print(\"Ray cluster is up and\
\ running: \", ray.is_initialized())\n\n @ray.remote\n def train_fn():\n\
\ return 100\n\n result = ray.get(train_fn.remote())\n assert\
\ 100 == result\n ray.shutdown()\n cluster.down()\n auth.logout()\n\
\ generate_cert.generate_tls_cert(cluster.config.name, cluster.config.namespace)\n\
\ generate_cert.export_env(cluster.config.name, cluster.config.namespace)\n\
\ ray.init(address=cluster.cluster_uri())\n print(\"Ray cluster is\
\ up and running: \", ray.is_initialized())\n\n @ray.remote\n def\
\ train_fn():\n return 100\n\n result = ray.get(train_fn.remote())\n\
\ assert 100 == result\n ray.shutdown()\n cluster.down()\n auth.logout()\n\
\ return result\n\n"
image: registry.redhat.io/ubi8/python-39@sha256:3523b184212e1f2243e76d8094ab52b01ea3015471471290d011625e1763af61
pipelineInfo:
Expand Down

0 comments on commit 026f4b3

Please sign in to comment.