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

目录

  • 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]
相关推荐
像风没有归宿a4 分钟前
2025年人工智能十大技术突破:从AGI到多模态大模型
人工智能
噜~噜~噜~12 分钟前
显式与隐式欧拉法(Explicit Euler and Implicit Euler)的个人理解
深度学习·显式欧拉法·隐式欧拉法·动力学系统
深鱼~14 分钟前
十分钟在 openEuler 上搭建本地 AI 服务:LocalAI 快速部署教程
人工智能
飞哥数智坊31 分钟前
不敢把个人信息喂给 AI?OneAIFW 简单搞定隐私保护!
人工智能
Coder_Boy_1 小时前
【人工智能应用技术】-基础实战-环境搭建(基于springAI+通义千问)(二)
数据库·人工智能
Jurio.1 小时前
Python Ray 分布式计算应用
linux·开发语言·python·深度学习·机器学习
爱加糖的橙子1 小时前
Dify升级到Dify v1.10.1-fix修复CVE-2025-55182漏洞
人工智能·python·ai
齐齐大魔王2 小时前
OpenCV
人工智能·opencv·计算机视觉