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

目录

  • 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]
相关推荐
熙梦数字化4 分钟前
2025汽车零部件行业数字化转型落地方案
大数据·人工智能·汽车
刘海东刘海东7 分钟前
逻辑方程结构图语言的机器实现(草稿)
人工智能
亮剑201810 分钟前
第2节:程序逻辑与控制流——让程序“思考”
开发语言·c++·人工智能
hixiong12312 分钟前
C# OpenCVSharp使用 读光-票证检测矫正模型
人工智能·opencv·c#
大千AI助手18 分钟前
HotpotQA:推动多跳推理问答发展的标杆数据集
人工智能·神经网络·llm·qa·大千ai助手·hotpotqa·多跳推理能力
红尘炼丹客24 分钟前
《DeepSeek-OCR: Contexts Optical Compression》速览
人工智能·python·自然语言处理·ocr
TiAmo zhang30 分钟前
现代C++的AI革命:C++20/C++23核心特性解析与实战应用
c++·人工智能·c++20
mwq3012337 分钟前
从傅里叶变换到 RoPE:解构位置编码的数学灵魂
人工智能
tyatyatya1 小时前
对比传统方法和深度学习方法在MATLAB视觉检测中的优缺点
深度学习·matlab·视觉检测