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

目录

  • 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]
相关推荐
渲吧云渲染40 分钟前
SaaS模式重构工业软件竞争规则,助力中小企业快速实现数字化转型
大数据·人工智能·sass
算家云43 分钟前
DeepSeek-OCR本地部署教程:DeepSeek突破性开创上下文光学压缩,10倍效率重构文本处理范式
人工智能·计算机视觉·算家云·模型部署教程·镜像社区·deepseek-ocr
AgeClub44 分钟前
1.2亿老人需助听器:本土品牌如何以AI破局,重构巨头垄断市场?
人工智能
PPIO派欧云2 小时前
PPIO上线Qwen-VL-8B/30B、GLM-4.5-Air等多款中小尺寸模型
人工智能
chenchihwen3 小时前
AI代码开发宝库系列:FAISS向量数据库
数据库·人工智能·python·faiss·1024程序员节
张登杰踩4 小时前
工业产品表面缺陷检测方法综述:从传统视觉到深度学习
人工智能·深度学习
sponge'4 小时前
opencv学习笔记6:SVM分类器
人工智能·机器学习·支持向量机·1024程序员节
zandy10114 小时前
2025年AI IDE的深度评测与推荐:从单一功能效率转向生态壁垒
ide·人工智能
andyguo4 小时前
ChatGPT Atlas vs Chrome:AI 浏览器的新纪元
人工智能·chrome·chatgpt