V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Morriaty
V2EX  ›  程序员

写 torch / tf 代码时大家有啥记住 size 的技巧或者工具吗,经常各种 view、unsqueeze、transpose 之后绕着绕着就把自己绕晕了

  •  
  •   Morriaty · 128 天前 · 825 次点击
    这是一个创建于 128 天前的主题,其中的信息可能已经有所发展或是发生改变。

    或者有啥关键字供搜索吗,我在 google 上尝试搜索 track tensor size ,没有搜到想搜的内容

    4 条回复    2024-01-09 18:47:08 +08:00
    pochy06
        1
    pochy06  
       128 天前   ❤️ 1
    每次 reshape 之前都加条注释,写一下 shape 变换 orz
    因为模型不是代码量最多的地方,所以多写点注释也不费事儿
    ronpay
        2
    ronpay  
       125 天前
    Morriaty
        3
    Morriaty  
    OP
       110 天前
    回来自答下,以便后来者能查看。
    经过一番查找,目前找到的最符合我初始需求的是[tsalib]( https://github.com/ofnote/tsalib)
    例子如下
    <script src="https://gist.github.com/Morriaty-The-Murderer/c621922429d1f6b4a91ed1fdc97798e3.js"></script>

    其中也结合了 2L 提到的`einops`,其实`tsalib`本身是自带类似的`warp`操作的,但由于`tsalib`本身很久没维护了( last commit 4years ago ),所以操作 tensor 还是选择了目前稳定维护的`einops`,仅保留了`tsalib`的`type annotation`

    由于我也是刚开始使用,所以不太清楚这样子写是否是 best practise ,还在摸索中。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1621 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 16:49 · PVG 00:49 · LAX 09:49 · JFK 12:49
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.