我想在主进程中做一些计算,并将张量广播到其他进程.下面是我当前代码的草图:
from accelerate.utils import broadcast
x = None
if accelerator.is_local_main_process:
x = <do_some_computation>
x = broadcast(x) # I have even tried moving this line out of the if block
print(x.shape)
这给了我以下错误:
TypeError: Unsupported types (<class 'NoneType'>) passed to `_gpu_broadcast_one` . Only nested list/tuple/dicts of objects that are valid for `is_torch_tensor` s hould be passed.
这意味着x
仍然是None
,并没有真正被播出.我该怎么解决这个问题?