我已经阅读了所有我能找到的关于 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) 我正在研究一种新的数据结构,它是 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)