Я использовал следующий пример кода, полученного от ChatGPT при запросе «ошибка ObjectRef в ray.get после ray.put».
import ray
ray.init()
# Store a large object in Ray
data = [i for i in range(10**6)]
data_ref = ray.put(data)
# Define a task that uses the stored object
@ray.remote
def process_data(ref, start, end):
data = ray.get(ref) # Retrieve the object
return sum(data[start:end])
# Launch parallel tasks using the ObjectRef
tasks = [process_data.remote(data_ref, i * 100000, (i + 1) * 100000) for i in range(10)]
results = ray.get(tasks) # Fetch results
print(f"Total sum: {sum(results)}")
Подробнее здесь: https://stackoverflow.com/questions/792 ... t-an-ray-o
Мобильная версия