贝隆

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
cat /tmp/ray/session_latest/logs/dashboard_agent.log

sudo apt install nvidia-utils-510


import ray
import os

ray.init()

@ray.remote
def f(x):
    return x * x

futures = [f.remote(i) for i in range(4)]
print("task", ray.get(futures)) # [0, 1, 4, 9]

@ray.remote
class Counter(object):
    def __init__(self):
        self.n = 0

    def increment(self):
        self.n += 1

    def read(self):
        return self.n

RAY_DEDUP_LOGS=0
counters = [Counter.remote() for i in range(4)]
[c.increment.remote() for c in counters]
futures = [c.read.remote() for c in counters]
print("actor",ray.get(futures)) # [1, 1, 1, 1]

ray.shutdown()
os._exit(0)

 

import ray
ds = ray.data.read_csv("local:///home/xiaof/ray/iris.csv")

# ds = ds.map(lambda x: {"target1": x["target"] * 2})
# ds = ds.map(lambda x: {"target2": x["target1"] * 2})
ds.show(limit=1)

from typing import Dict
import numpy as np

# Define a transformation to compute a "petal area" attribute
def transform_batch(batch: Dict[str, np.ndarray]) -> Dict[str, np.ndarray]:
    vec_a = batch["petal.length"]
    vec_b = batch["petal.width"]
    batch["petal.area"] = vec_a * vec_b
    return batch

# Apply the transformation to our dataset
transformed_ds = ds.map_batches(transform_batch)
transformed_ds.show(limit=1)

 

 
posted on 2025-12-04 00:27  贝隆  阅读(6)  评论(0)    收藏  举报