问题描述
在训练模型的过程中遇到了apex库的报错IndexError: tuple index out of range导致无法训练。在github查询后找到了解决方法
 
问题解决
需要修改/apex-master/apex/amp/utils.py这个文件的代码
 从93行开始修改
if x in cache:
        cached_x = cache[x]
        next_functions_available = False
        if x.requires_grad and cached_x.requires_grad:
            if len(cached_x.grad_fn.next_functions) > 1:
                next_functions_available = True
            # Make sure x is actually cached_x's autograd parent.
            if next_functions_available and cached_x.grad_fn.next_functions[1][0].variable is not x:

 在修改下边120行左右
 elif x.requires_grad and cached_x.requires_grad and not next_functions_available:
            del cache[x]

 最后重新运行一遍apex的安装程序,再次运行训练就不会报错了
 
|  | 点击访问博客查看更多内容 | 
|---|



















![[lesson19]对象的构造(下)](https://img-blog.csdnimg.cn/direct/00e16fabedd24b9baedee8478e4a2395.png#pic_center)