当前位置: 首页 > news >正文

使用vscode调试transformers源码

简要介绍如何使用vscode调试transformers源码

以源码的方式安装transformers(官方手册为Editable install)

优先参考官方手册

git clone https://github.com/huggingface/transformers.git
cd transformers
pip install -e .

以下展示transformers/examples/pytorch/image-classification样例的调试方法

  • 阅读image-classification的README.md文件,可知需要下载数据集beans和ViT模型(默认为google/vit-base-patch16-224-in21k),下图是我的数据集目录:
    在这里插入图片描述

  • 配置launch.json文件,这里面需要根据自己的路径修改一些变量,仅供参考:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
    
        {
            "name": "Python Debugger: Current File",
            "type": "debugpy",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "run_image_classification.py",
            "type": "debugpy",
            "request": "launch",
            "program": "${workspaceFolder}/transformers/examples/pytorch/image-classification/run_image_classification.py",
            "args": [
                "--train_dir", "transformers/examples/pytorch/image-classification/beans/data/train",
                "--validation_dir", "transformers/examples/pytorch/image-classification/beans/data/validation",
                "--output_dir", "./beans_outputs/",
                "--remove_unused_columns","False",
                "--label_column_name", "label",
                "--do_train",
                "--do_eval",
                "--num_train_epochs", "5",
            ],
            "console": "integratedTerminal",
            "justMyCode": false,
            "env": {
              "PYTHONPATH": "${workspaceFolder}"
            }
          },
    ]
}

进入调试环境即可跳转transformers源码阅读

在这里插入图片描述

相关文章:

  • Linux中的Ctrl+C与Ctrl+Z
  • Docker 容器安装 Dify的两种方法
  • 审计级别未启用扩展模式导致查询 DBA_AUDIT_TRAIL 时 SQL_TEXT 列为空
  • Swupdate升级不强制依赖version字段
  • 装win10系统提示“windows无法安装到这个磁盘,选中的磁盘采用GPT分区形式”解决方法
  • DeepSeek 通过 ollama 轻松本地部署
  • LeetCode 热题 100_N 皇后 (62_51_困难_C++)(递归(回溯))
  • 【一文读懂】JS与Java的区别
  • 基于Python的Diango旅游数据分析推荐系统设计与实现+毕业论文(15000字)
  • Android 平台GB28181设备接入实战指南
  • day 19
  • 量化自学 - 金融理论与python - Net Present Value 净现值
  • Linux arm64 IOMMU总结
  • 【产品小白】B端产品系统从需求到落地
  • 前端对话框项目 react如何实时接收,Node.js 服务端转发Coze API响应结果详解
  • deepin 下安装nvm(npm+node)
  • 【LeetCode】LCR 139. 训练计划 I
  • SAP-工单技术性关闭操作手册
  • 【STM32学习】标准库实现STM32 ADC采集1路、2路、多路
  • JWT 令牌
  • 中保协发布《保险机构适老服务规范》,全面规范保险机构面向老年人提供服务的统一标准
  • “降息潮”延续,多家民营银行下调存款利率
  • 世贸组织欢迎中美经贸高层会谈取得积极成果
  • 中国目的地·入境游简报006|外国网红游中国启示录
  • 西藏日喀则市拉孜县发生5.5级地震,震源深度10千米
  • 汉斯·季默:不会指挥的声音工程师终成音乐“大神”