- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 ray 在列表的每个元素上并行化函数的操作.下面是一个简化的片段
import numpy as np
import time
import ray
import psutil
num_cpus = psutil.cpu_count(logical=False)
ray.init(num_cpus=num_cpus)
@ray.remote
def f(a, b, c):
return a * b - c
def g(a, b, c):
return a * b - c
def my_func_par(large_list):
# arguments a and b are constant just to illustrate
# argument c is is each element of a list large_list
[f.remote(1.5, 2, i) for i in large_list]
def my_func_seq(large_list):
# arguments a anf b are constant just to illustrate
# argument c is is each element of a list large_list
[g(1.5, 2, i) for i in large_list]
my_list = np.arange(1, 10000)
s = time.time()
my_func_par(my_list)
print(time.time() - s)
>>> 2.007
s = time.time()
my_func_seq(my_list)
print(time.time() - s)
>>> 0.0372
问题是,当我计时
my_func_par
,它比
my_func_seq
慢得多(如上所示~54 倍) . ray 的一位作者确实回答了关于
this blog 的评论这似乎解释了我正在做的是设置
len(large_list)
不同的任务,这是不正确的。
large_list
分成块,块的数量等于 CPU 的数量)
f
需要接受多个参数 ray.put(large_list)
使larg_list
变量可以存储在共享内存中而不是复制到每个处理器 最佳答案
补充一下 Sang 上面所说的:
雷Distributed multiprocessing.Pool支持固定大小的 Ray Actors 池,以便于并行化。
import numpy as np
import time
import ray
from ray.util.multiprocessing import Pool
pool = Pool()
def f(x):
# time.sleep(1)
return 1.5 * 2 - x
def my_func_par(large_list):
pool.map(f, large_list)
def my_func_seq(large_list):
[f(i) for i in large_list]
my_list = np.arange(1, 10000)
s = time.time()
my_func_par(my_list)
print('Parallel time: ' + str(time.time() - s))
s = time.time()
my_func_seq(my_list)
print('Sequential time: ' + str(time.time() - s))
使用上面的代码,
my_func_par
运行速度更快(约 0.1 秒)。如果您玩弄代码并制作
f(x)
慢一些,比如
time.sleep
,您可以看到多处理的明显优势。
关于python - 如何使用 python Ray 并行处理一个大列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64247663/
有没有办法停止ray.tune实验(例如使用 PBT)当明显过度拟合或一个指标长时间没有改善时? 最佳答案 现在,这在 Tune 中得到了很好的支持,https://github.com/ray-pr
在 SimpleCorridor 之后我可以创建自己的环境并训练模型!好的。但是当我尝试评估这个经过训练的模型时,rllib 无法识别我的自定义环境。 如何在自定义环境中评估经过训练的模型? 当我像建
我正在运行 Ray Serve 来托管 ray 远程函数的 HTTP API。有没有比下面更好的方法在前台运行 Ray Serve(即非守护进程模式)。代码直接取自射线服务示例: import os
下面的代码完成了所需的行为。是否可以从前两个函数传递第二个参数而不必过早地调用 ray.get? @ray.remote def color(): image=cv2.imread("fram
我目前正在尝试理解由 Kevin Beason (smallpt: http://www.kevinbeason.com/smallpt/) 开发的光线追踪器,如果我正确理解代码,他会随机选择反射或折
当我在 Node 上运行 app.js 时,我在命令行中收到此错误: FATAL ERROR: v8::HandleScope::CreateHandle() Cannot create a hand
我想知道 - 是否有一种直接的方法可以在退出之前等待所有任务完成运行而不跟踪所有 ObjectID(和 get()ing他们)?用例是当我启动 @remote 以保存输出时,例如,在不需要返回结果的情
所以我只是跑了一个 tune实验并得到以下输出: +--------------------+------------+-------+-------------+----------------+-
我可以访问节点集群,我的理解是,一旦我在具有相同 Redis 地址的每个节点上启动 ray,头节点就可以访问所有节点的所有资源。 主要脚本: export LC_ALL=en_US.utf-8 exp
我正在寻找一个好的光线八叉树相交算法,它以迭代的方式为我提供光线穿过的叶子。我计划在 CPU 上实现它,因为我还不想深入研究 CUDA :) 目前,我的 Voxel raycaster 仅在 XxYx
来自 RISE 实验室的射线库 (https://rise.cs.berkeley.edu/blog/pandas-on-ray/) 我正在使用 64 位 Windows 10 专业版并从 Anaco
0. ray 简介 ray是开源分布式计算框架,为并行处理提供计算层,用于扩展AI与Python应用程序,是ML工作负载统一工具包 Ray AI Runtime
我有一个看起来更复杂的脚本: import ray var1 = 0 var2 = 0 @ray.remote def create(n): global var1 global va
我正在编写一个项目,该项目多次使用相同的数据进行写入,并且我一直在使用 ray 在集群设置中对其进行扩展,但是文件太大而无法来回发送/保存射线对象一直存储。有没有办法在远程函数调用之间将 python
我用 ray 创建了一个简单的远程函数,它占用的内存很少。但是,运行一小段时间后,内存稳步增加,并且出现 RayOutOfMemoryError 异常。 下面的代码是这个问题的一个非常简单的例子。 “
要检测一个点是否在多边形中,您可以从该点到无穷远投影一条线,然后查看它与多少个多边形顶点相交......足够简单。我的问题是,如果射线在其中一个点上与多边形相交,则将其视为与两个线段相交,并被视为在多
我有一个相当大的 Python 程序(~800 行),它具有以下结构: 设置说明,我在其中处理用户提供的输入文件并定义对程序执行具有全局性的变量/对象。 Main 函数,它利用前面的设置阶段并调用程序
正如您在图像中看到的那样,我在球体顶部看到了一个黑色圆圈,并且图像看起来有颗粒感。它应该更清晰,但是有这些小的黑白点。 这是阴影射线的代码 int pos = 0; float intersect(c
我有一个相当大的 Python 程序(~800 行),它具有以下结构: 设置说明,我在其中处理用户提供的输入文件并定义对程序执行具有全局性的变量/对象。 Main 函数,它利用前面的设置阶段并调用程序
我正在尝试实现一个“光线选择器”以在我的项目中选择对象。我不完全理解如何实现这一点,但我从概念上理解它应该如何工作。我一直在努力学习如何做到这一点,但我发现大多数教程都让我难以理解。我当前的代码基于我
我是一名优秀的程序员,十分优秀!