RuntimeError: Expected to have finished reduction in the prior iteration before starting a new one.
启用 find_unused_parameters: 确保在 accelerate 的 Accelerator 初始化中使用了 find_unused_parameters 参数。设置调试信息环境变量: 通过设置 TORCH_DISTRIBUTED_DEBUG 环境变量为 INFO 或 DETAIL,获取关于哪些参数没有接收到梯度的详细信息。实例化 Accelerator: 使用 accelera
·
RuntimeError: Expected to have finished reduction in the prior iteration before starting a new one.
Accelerator 单机多卡报错
RuntimeError: Expected to have finished reduction in the prior iteration before starting a new one. This error indicates that your module has parameters that were not used in producing loss. You can enable unused parameter detection by passing the keyword argument `find_unused_parameters=True` to `torch.nn.parallel.DistributedDataParallel`, and by
making sure all `forward` function outputs participate in calculating loss.
If you already have done the above, then the distributed data parallel module wasn't able to locate the output tensors in the return value of your module's `forward` function. Please include the loss function and the structure of the return value of `forward` of your module when reporting this issue (e.g. list, dict, iterable).
Parameter indices which did not receive grad for rank 1: 32 33 34 35 36 37
In addition, you can set the environment variable TORCH_DISTRIBUTED_DEBUG to either INFO or DETAIL to print out information about which particular parameters did not receive gradient on this rank as part of this error
启用 find_unused_parameters: 确保在 accelerate 的 Accelerator 初始化中使用了 find_unused_parameters 参数。例如:
accelerator = Accelerator(kwargs_handlers=[DistributedDataParallelKwargs(find_unused_parameters=True)])
确保所有输出参与损失计算: 检查模型的 forward 函数,确保其所有输出都参与了损失计算。
设置调试信息环境变量: 通过设置 TORCH_DISTRIBUTED_DEBUG 环境变量为 INFO 或 DETAIL,获取关于哪些参数没有接收到梯度的详细信息。
实例化 Accelerator: 使用 accelerate.Accelerator 类来管理模型、优化器和损失函数的准备工作。
我的主要问题是没有使用find_unused_parameters=True)
from accelerate import Accelerator, DistributedDataParallelKwargs
accelerator = Accelerator(
mixed_precision=args.mixed_precision,
log_with=args.report_to,
project_config=accelerator_project_config,
kwargs_handlers=[DistributedDataParallelKwargs(find_unused_parameters=True)]
)
更多推荐
所有评论(0)