在自定义Dask图中包括关键字参数(kwargs) [英] Including keyword arguments (kwargs) in custom Dask graphs
问题描述
我正在为Dask的一项操作构建自定义图形。熟悉如何在Dask图中将参数传递给函数,并已阅读 docs 。但是,似乎仍然缺少某些东西。
在Dask图中使用的函数之一带有关键字参数。尽管对于如何将关键字参数传递给它感到困惑。其中一些关键字参数代表Dask对象,因此它们必须明确地位于图形中(即 functools.partial
无效)。可以看到以下选项。
- 尝试以正确的位置顺序传递任何关键字参数。 (不适用于通用
** kwargs
或仅关键字参数) - 编写一个包装程序,该包装程序将位置参数转换为关键字参数,并在图中使用它。 (可以,但有一些开销)
- 以某种方式直接将它们包括在图形中? (理想,但不清楚如何做)
有人对如何最好地做到这一点有什么想法?
常见的解决方法是使用 apply
函数
<$来自dask.compatibility import的p $ p>
导入apply
task =(apply,func,args,kwargs)#func(* args,** kwargs)
Am building a custom graph for one operation with Dask. Am familiar with how to pass arguments to a function in Dask graph and have read up on the docs. However still seem to be missing something.
One of the functions used in the Dask graph takes keyword arguments. Though am confused as to how the keyword arguments can be passed to it. Some of these keyword arguments represent Dask objects so they must be in the graph explicitly (i.e. functools.partial
won't work). Can see the following options.
- Try to pass any keyword arguments in the correct positional order. (won't work for generic
**kwargs
or keyword only arguments) - Write a wrapper that converts positional arguments to keywords arguments and use that in the graph. (works ok, but has some overhead)
- Include them directly in the graph somehow? (ideal, but unclear how)
Any thoughts on how best to do this?
A common workaround is to use the apply
function
from dask.compatibility import apply
task = (apply, func, args, kwargs) # func(*args, **kwargs)
这篇关于在自定义Dask图中包括关键字参数(kwargs)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!