首页 > 解决方案 > 如何检查一个模块是否嵌套在另一个模块中的某个地方

问题描述

我目前正在使用

def check_is_descendent(root_module: nn.Module, query_module: nn.Module) -> bool:
    for m in root_module.modules():
        if isinstance(m, query_module):
            return True
    return False

只是想知道是否有 PyTorch 函数或方法可以做到这一点。

标签: pytorch

解决方案


推荐阅读