__init__.py — PyTorch 补丁包标识¶
源码路径: -
verl/third_party/torch/__init__.py-verl/third_party/torch/distributed/__init__.py-verl/third_party/torch/distributed/checkpoint/__init__.py
文件概述¶
这三个文件是 PyTorch 补丁代码的包标识文件。它们都包含相同的注释说明和版权信息,表明这些代码是从 PyTorch 2.7.0 复制而来的。
共同的注释¶
# official torch 2.6.0 set_model_state_dict API leads to OOM
# this is a copy of torch/distributed/checkpoint from torch 2.7.0
这行注释说明了为什么需要复制 PyTorch 的代码:PyTorch 2.6.0 版本的 set_model_state_dict API 会导致内存溢出(OOM),而 PyTorch 2.7.0 修复了这个问题。verl 将修复后的代码复制到项目中,确保即使用户使用 PyTorch 2.6.0 也不会遇到此问题。
目录结构与 PyTorch 的对应关系¶
verl/third_party/torch/ ←→ torch/
distributed/ ←→ torch/distributed/
_state_dict_utils.py ←→ torch/distributed/_state_dict_utils.py
checkpoint/ ←→ torch/distributed/checkpoint/
state_dict.py ←→ torch/distributed/checkpoint/state_dict.py
这种目录结构完全镜像了 PyTorch 的源码组织,便于追溯和比较。
核心类/函数列表¶
无(这三个文件均只包含注释和版权声明)。
与其他模块的关系¶
这些文件使得以下导入路径成为可能:
from verl.third_party.torch.distributed._state_dict_utils import _gather_state_dict
from verl.third_party.torch.distributed.checkpoint.state_dict import set_model_state_dict
小结¶
这三个 __init__.py 文件纯粹是包标识,但它们的注释揭示了一个重要的工程实践:当上游库存在已知 bug 时,可以将修复版本的代码复制到项目中,既保证功能正确,又避免强制要求用户升级依赖。