深度学习踩坑记录(持续更新)

目录

  • 4060显卡cuda版本异常
  • [transformers 初始化 TrainingArguments 时 output_dir 指定问题](#transformers 初始化 TrainingArguments 时 output_dir 指定问题)

4060显卡cuda版本异常

环境:torch1.11.0+cu113

程序报错

复制代码
RuntimeError: nvrtc: error: invalid value for --gpu-architecture (-arch)

可能原因与解决办法

  1. 4060显卡是sm_89架构,支持11.7以上cuda,低版本cuda有异常

    运行以下代码可查看当前torch版本支持的gpu的架构,和当前gpu的架构

    python 复制代码
    import torch
    
    print(torch.cuda.get_arch_list())  # 返回['sm_37', 'sm_50', 'sm_60', 'sm_61', 'sm_70', 'sm_75', 'sm_80', 'sm_86', 'compute_37']
    print(torch.cuda.get_device_capability(0))  # 返回(8, 9),代表sm_89

    查看返回结果可知,当前torch版本不支持sm_89,可更新torch版本,运行以下代码安装

    复制代码
     pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117
  2. 程序打断点可以找到报错程序是一个带有 @torch.jit.script 装饰器的函数

    torch.jit.script 是将模型转换为脚本的函数。它接受一个 PyTorch 模型作为输入,并将其转换为可运行的脚本。转换后的脚本可以像普通的 Python 函数一样调用,也可以保存到磁盘并在没有 PyTorch 依赖的环境中执行。

    主要作用是降低解释器消耗,如果不要求性能,可以将装饰器注释掉,即可顺利运行。

transformers 初始化 TrainingArguments 时 output_dir 指定问题

环境:transformers=4.27.1

程序报错

复制代码
main.py: error: the following arguments are required: --output_dir

可能原因与解决办法

  1. 运行时未指定 output_dir 参数

    解决办法1:使用命令行运行程序 python main.py --output_dir ./output

    解决办法2:若使用pycharm 运行,可右键选择 Modify Run Configuration ,设置运行脚本参数--output_dir ./output

    解决办法3:继承TrainingArguments重新初始化output_dir,同时也可以初始化其他超参数

    python 复制代码
    from transformers import TrainingArguments
    
    @dataclass
    class MyTrainingArguments(TrainingArguments):
        max_steps: int = field(default=5000)
        save_steps: int = field(default=100)
        learning_rate: float = field(default=5e-5)
        logging_steps: int = field(default=10)
        output_dir: str = field(default='output')
        per_device_train_batch_size: int = field(default=1)
        gradient_accumulation_steps: int = field(default=8)
        do_train: bool = field(default=True)
    
    training_args = HfArgumentParser(MyTrainingArguments).parse_args_into_dataclasses()[0]
相关推荐
jonyleek21 分钟前
如何搭建一套安全的,企业级本地AI专属知识库系统?从安装系统到构建知识体系,全流程!
人工智能·安全
MQ_SOFTWARE1 小时前
AI驱动的金融推理:Fin-R1模型如何重塑行业决策逻辑
人工智能·金融
生医转码,四海为家1 小时前
零基础-动手学深度学习-6.6 卷积神经网络(LeNet)
人工智能·深度学习·cnn
无名工程师1 小时前
AI 学习过程中各阶段的学习重点、时间规划以及不同方向的选择与建议等内容
人工智能·学习
WXX_s2 小时前
【OpenCV篇】OpenCV——03day.图像预处理(2)
人工智能·python·opencv·学习·计算机视觉
CoovallyAIHub2 小时前
避开算力坑!无人机桥梁检测场景下YOLO模型选型指南
深度学习·算法·计算机视觉
有才不一定有德2 小时前
深入剖析 MetaGPT 中的提示词工程:WriteCode 动作的提示词设计
人工智能·aigc·提示词工程
花月mmc3 小时前
CanMV-K230 AI学习笔记系列
人工智能·笔记·学习
s1ckrain3 小时前
【论文阅读】ON THE ROLE OF ATTENTION HEADS IN LARGE LANGUAGE MODEL SAFETY
论文阅读·人工智能·语言模型·大模型安全