当前位置: 首页 > article >正文

AF3 TriangleMultiplicativeUpdate类代码解读

AlphaFold3的TriangleMultiplicativeUpdate类继承自BaseTriangleMultiplicativeUpdate 类是,他有两个子类 TriangleMultiplicationOutgoing和TriangleMultiplicationIncoming类,他们差异在于__init__初始化方法_outgoing参数不同,分别表示 “输出”/“输入”边三角形乘法更新类。TriangleMultiplicativeUpdate 主要用于实现算法 11 和 12 的三角乘法更新。这些算法在结构生物信息学中,如蛋白质结构预测的 AlphaFold 模型中,被用来更新氨基酸残基对的表示。

源代码:

class TriangleMultiplicativeUpdate(BaseTriangleMultiplicativeUpdate):
    """
    Implements Algorithms 11 and 12.
    """

    def __init__(self, c_z, c_hidden, _outgoing=True):
        """
        Args:
            c_z:
                Input channel dimension
            c:
                Hidden channel dimension
        """
        super(TriangleMultiplicativeUpdate, self).__init__(c_z=c_z,
                                                           c_hidden=c_hidden,
                                                           _outgoing=_outgoing)

        self.linear_a_p = Linear(self.c_z, self.c_hidden)
        self.linear_a_g = Linear(self.c_z, self.c_hidden, init="gating")
        self.linear_b_p = Linear(self.c_z, self.c_hidden)
        self.linear_b_g = Linear(self.c_z, self.c_hidden, init="gating")

    def _inference_forward(self,
                           z: torch.Tensor,
                           mask: Optional[torch.Tensor] = None,
                           inplace_chunk_size: Optional[int] = None,
                           with_add: bool = True,
                           ):
        """
        Args:
            z:
                A [*, N, N, C_z] pair representation
            mask:
                A [*, N, N] pair mask
            inplace_chunk_size:
                Size of chunks used in the main computation. Increase to trade
                memory for speed.
            with_add:
                If True, z is overwritten with (z + update). Otherwise, it is
                overwritten with (update).
        Returns:
            A reference to the overwritten z

        More memory-efficient, inference-only version of the forward function.
        Uses in-place operations, fusion of the addition that happens after
        this module in the Evoformer, a smidge of recomputation, and 
        a cache of overwritten values to lower peak memory consumption of this
        module from 5x the size of the x tensor z to 2.5x its size. Useful
        for inference on extremely long sequences. 
        
        It works as follows. We will make reference to variables used in the
        default forward implementation below. Naively, triangle multiplication
        attention requires the manifestation of 5 tensors the size of z:
        1) z, the "square" x tensor, 2) a, the first projection of z,
        3) b, the second projection of b, 4) g, a z-sized mask, and 5) a 
        z-sized tensor for intermediate computations. For large N, this is 
        prohibitively expensive; for N=4000, for example, z is more than 8GB 
        alone. To avoid this problem, we compute b, g, and all intermediate
        tensors in small chunks, noting that the chunks required to compute a
        chunk of the output depend only on the tensor a and corresponding 
        vertical and horizontal chunks of z. This suggests an algorithm that 
        

http://www.kler.cn/a/508146.html

相关文章:

  • 【2024年华为OD机试】 (C卷,100分)- 小明找位置(Java JS PythonC/C++)
  • 如何使用Ultralytics训练自己的yolo5 yolo8 yolo10 yolo11等目标检测模型
  • Python基于Django的图像去雾算法研究和系统实现(附源码,文档说明)
  • C 语言运算符的优先级和结合性
  • Windows图形界面(GUI)-QT-C/C++ - QT 窗口属性
  • React 中hooks之useLayoutEffect 用法总结以及与useEffect的区别
  • CVPR 2024 图像处理方向总汇(图像去噪、图像增强、图像分割和图像恢复等)
  • ChatGPT结合Excel辅助学术数据分析详细步骤分享!
  • 洛谷 P2392 kkksc03考前临时抱佛脚 刷题笔记 dfs
  • 先进制造aps专题二十七 西门子opcenter aps架构分析
  • 考研数据结构线性表之顺序表
  • Azure Synapse Dedicated SQL Pool通过配置选项和参数优化性能
  • python http server运行Angular 单页面路由时重定向,解决404问题
  • LeetCode 3097.或值至少为 K 的最短子数组 II:滑动窗口
  • 3.数据库系统
  • 面试题解析
  • 电子应用设计方案93:智能AI电火锅系统设计
  • MS5263数模转换器可兼容AD5663/DAC8552
  • 芝麻http/品易http/太阳http/极光http退市后,还有哪家好用推荐?
  • 嵌入式驱动开发详解12(LCD驱动)
  • 我在讯方智汇云校备考云计算HCIE的经验分享
  • window下用vim
  • Python大数据可视化:基于Python对B站热门视频的数据分析与研究_flask+hive+spider
  • 协作机器人公司切入人形机器人赛道,大有可为!
  • 【Mac】MacOS如何显示隐藏的文件或文件夹
  • 骑砍2霸主MOD开发(11)-可编程渲染管线Shader编程