Skip to content

Commit 46f51fe

Browse files
committed
Learn: Ray
[ci skip] Signed-off-by: Jonghyun Park <parjong@gmail.com>
1 parent 9637e68 commit 46f51fe

File tree

10 files changed

+93
-0
lines changed

10 files changed

+93
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/uv.lock

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.10

0.ray_core.function.log

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2025-11-07 21:41:40,603 INFO worker.py:2012 -- Started a local Ray instance.
2+
2025-11-07 21:41:40,630 INFO packaging.py:588 -- Creating a file package for local module '/home/parjong/craftroom/learn-ray'.
3+
2025-11-07 21:41:40,673 INFO packaging.py:380 -- Pushing file package 'gcs://_ray_pkg_4301945bed39b81b.zip' (0.08MiB) to Ray cluster...
4+
2025-11-07 21:41:40,679 INFO packaging.py:393 -- Successfully pushed file package 'gcs://_ray_pkg_4301945bed39b81b.zip'.
5+
/home/parjong/craftroom/learn-ray/.venv/lib/python3.10/site-packages/ray/_private/worker.py:2051: FutureWarning: Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0
6+
warnings.warn(
7+
(raylet) warning: `VIRTUAL_ENV=/home/parjong/craftroom/learn-ray/.venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
8+
(raylet) Using CPython 3.10.19
9+
(raylet) Creating virtual environment at: .venv
10+
(raylet) Installed 18 packages in 226ms
11+
[0, 1, 4, 9]
12+
(raylet) warning: `VIRTUAL_ENV=/home/parjong/craftroom/learn-ray/.venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead

0.ray_core.function.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import ray
2+
3+
ray.init()
4+
5+
@ray.remote
6+
def f(x):
7+
return x * x
8+
9+
futures = [f.remote(i) for i in range(4)]
10+
print(ray.get(futures)) # [0, 1, 4, 9]
11+
12+
# https://docs.ray.io/en/latest/ray-overview/getting-started.html#libraries-quickstart

1.ray_core.actor.log

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2025-11-07 21:41:48,245 INFO worker.py:2012 -- Started a local Ray instance.
2+
2025-11-07 21:41:48,272 INFO packaging.py:588 -- Creating a file package for local module '/home/parjong/craftroom/learn-ray'.
3+
2025-11-07 21:41:48,307 INFO packaging.py:380 -- Pushing file package 'gcs://_ray_pkg_1eec9e354a1f3b8d.zip' (0.08MiB) to Ray cluster...
4+
2025-11-07 21:41:48,309 INFO packaging.py:393 -- Successfully pushed file package 'gcs://_ray_pkg_1eec9e354a1f3b8d.zip'.
5+
/home/parjong/craftroom/learn-ray/.venv/lib/python3.10/site-packages/ray/_private/worker.py:2051: FutureWarning: Tip: In future versions of Ray, Ray will no longer override accelerator visible devices env var if num_gpus=0 or num_gpus=None (default). To enable this behavior and turn off this error message, set RAY_ACCEL_ENV_VAR_OVERRIDE_ON_ZERO=0
6+
warnings.warn(
7+
(raylet) warning: `VIRTUAL_ENV=/home/parjong/craftroom/learn-ray/.venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead
8+
(raylet) Using CPython 3.10.19
9+
(raylet) Creating virtual environment at: .venv
10+
(raylet) Installed 18 packages in 209ms
11+
[1, 1, 1, 1]
12+
(raylet) warning: `VIRTUAL_ENV=/home/parjong/craftroom/learn-ray/.venv` does not match the project environment path `.venv` and will be ignored; use `--active` to target the active environment instead [repeated 3x across cluster] (Ray deduplicates logs by default. Set RAY_DEDUP_LOGS=0 to disable log deduplication, or see https://docs.ray.io/en/master/ray-observability/user-guides/configure-logging.html#log-deduplication for more options.)

1.ray_core.actor.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import ray
2+
3+
ray.init() # Only call this once.
4+
5+
@ray.remote
6+
class Counter(object):
7+
def __init__(self):
8+
self.n = 0
9+
10+
def increment(self):
11+
self.n += 1
12+
13+
def read(self):
14+
return self.n
15+
16+
counters = [Counter.remote() for i in range(4)]
17+
[c.increment.remote() for c in counters]
18+
futures = [c.read.remote() for c in counters]
19+
print(ray.get(futures)) # [1, 1, 1, 1]

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.PHONY: all run sync
2+
3+
all:
4+
5+
run:
6+
./run.sh 0.ray_core.function
7+
./run.sh 1.ray_core.actor
8+
9+
sync:
10+
git add -u
11+
git commit --amend --no-edit
12+
git push --force

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# prototype
22
For fast prototyping!
3+
4+
## Troubleshooting
5+
6+
```
7+
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf8 in position 0: invalid start byte
8+
```
9+
10+
nvidia driver bug? from https://github.com/ray-project/ray/issues/4549
11+
12+
581.57 is working

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[project]
2+
name = "learn-ray"
3+
version = "0.1.0"
4+
readme = "README.md"
5+
requires-python = ">=3.10"
6+
dependencies = [
7+
"ray",
8+
]
9+
# https://docs.ray.io/en/latest/ray-overview/installation.html

run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
(
4+
uv run python $1.py
5+
) 2>&1 | tee $1.log

0 commit comments

Comments
 (0)