小编hlu*_*hlu的帖子

torch.distributed.barrier() 如何工作

我已经阅读了所有我能找到的关于 torch.distributed.barrier() 的文档,但仍然无法理解它在这个脚本中的使用方式,非常感谢一些帮助。

因此,torch.distributed.barrier官方文档说它“同步所有进程。如果 async_op 为 False,或者如果在 wait() 上调用了异步工作句柄,则此集体会阻止进程,直到整个组进入此函数为止。”

它在脚本中的两个地方使用:

第一名

    if args.local_rank not in [-1, 0] and not evaluate:
        torch.distributed.barrier()  # Make sure only the first process in distributed training process the dataset, and the others will use the cache

        ... (preprocesses the data and save the preprocessed data)

    if args.local_rank == 0 and not evaluate:
        torch.distributed.barrier() 
Run Code Online (Sandbox Code Playgroud)

第二个地方

    if args.local_rank not in [-1, 0]:
        torch.distributed.barrier()  # Make sure only the first process in …
Run Code Online (Sandbox Code Playgroud)

pytorch huggingface-transformers

8
推荐指数
1
解决办法
3971
查看次数

带有必需参数的子类 Pandas DataFrame

我正在研究一种新的数据结构,它是 Pandas DataFrame 的子类。我想强制我的新数据结构具有 new_property,以便以后可以安全地处理它。但是,我在使用我的新数据结构时遇到了错误,因为构造函数被一些没有所需属性的内部 Pandas 函数调用。这是我的新数据结构。

import pandas as pd
class MyDataFrame(pd.DataFrame):

    @property
    def _constructor(self):
        return MyDataFrame

    _metadata = ['new_property']

    def __init__(self, data, new_property, index=None, columns=None, dtype=None, copy=True):

        super(MyDataFrame, self).__init__(data=data,
                                          index=index,
                                          columns=columns,
                                          dtype=dtype,
                                          copy=copy)
        self.new_property = new_property
Run Code Online (Sandbox Code Playgroud)

这是一个导致错误的示例

data1 = {'a': [1, 2, 3], 'b': [4, 5, 6], 'c': [15, 25, 30], 'd': [1, 1, 2]}
df1 = MyDataFrame(data1, new_property='value')
df1[['a', 'b']]
Run Code Online (Sandbox Code Playgroud)

这是错误信息

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-
packages\IPython\core\interactiveshell.py", line 2881, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File …
Run Code Online (Sandbox Code Playgroud)

subclass dataframe pandas

5
推荐指数
1
解决办法
1064
查看次数

为什么T-SQL中的LAG功能是非确定性的?

我正在尝试在T-SQL中使用LAG来计算一些滞后功能.当LAG参考页面说这个函数是非确定性的时候,我有点担心.关于函数确定性参考页面说"在查询中指定ORDER BY子句不会改变在该查询中使用的函数的确定性".但是,我不明白为什么LAG会在相同条件下返回不同的结果.如果是这样,为什么人们会使用它?也许我不是正确地解释"决定论"?谢谢!

t-sql sql-server lag non-deterministic

4
推荐指数
2
解决办法
840
查看次数