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

vscode debug Transformer源码说明

  1. 首选确认conda env 环境中未使用 install 安装Transformer;
  2. 下载源码:
git clone https://github.com/huggingface/transformers.git
cd transformers# pip
pip install '.[torch]'

安装后通过pip list 可以看到是指向你的本地目录:
在这里插入图片描述
3. 自测demo,放在根目录即可

from transformers import AutoModelForCausalLM, AutoTokenizermodel_name = "Qwen/Qwen3-0.6B"# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, use_fast=False)
model = AutoModelForCausalLM.from_pretrained(model_name,trust_remote_code=True,dtype="auto",device_map="auto"
)# prepare the model input
prompt = "Give me a short introduction to large language model."
messages = [{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True,
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)# conduct text completion
generated_ids = model.generate(**model_inputs,max_new_tokens=512
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()content = tokenizer.decode(output_ids, skip_special_tokens=True)print("content:", content)
  1. vscode debug:按照以往代码debug即可;
  • 安装插件
    在这里插入图片描述

  • vscode 右下角选择你的env,如下
    在这里插入图片描述

  • 点击上方的三个点-》运行-》启动调试
    在这里插入图片描述

http://www.dtcms.com/a/520399.html

相关文章:

  • 仓颉语言核心特性深度解析:类型系统与内存安全实践
  • IP 地址 (Internet Protocol Address) 详细介绍
  • PHP网站开发常用函数房城乡建设部网站
  • 开源的SSR框架都是怎么实现的?
  • RLVR训练多模态文档解析模型-olmOCR 2技术方案(模型、数据和代码均开源)
  • AI 领域热门方向或代表性技术/模型
  • MySQL 体系结构、SQL 执行与设计范式
  • 个人网站如何搭建国家企业信用信息网官网
  • MySQL学习之SQL语法与操作
  • “麻烦您了”英语怎么说?
  • 临时上线没有回滚方案会怎样
  • 哪个网站做高仿衣服中小学网站建设建议
  • Linux 中的 DNS 工作原理(二):各级 DNS 缓存
  • vip影视网站如何做app建设电子商务网站的预期收益
  • 从 DeepWalk 到 Node2Vec:如何让图学习“更聪明”?
  • leetcode合并有序链表
  • 知识图谱遇上大语言模型:天作之合还是理想泡影?
  • Kafka入门:基础架构讲解,安装与使用
  • 深圳seo网站推广报价wordpress导航栏的文件在哪
  • 电手术刀VS神经调音师:解密电刺激技术差异
  • lance + duckdb 替代 parquet + pandas
  • CHIA考试报告手册
  • Linux操作系统学习之---线程互斥(互斥锁)
  • 【物联网控制体系项目实战】—— 整体架构流程与 WS 实现
  • dedecms网站后台模板做汽车网站费用
  • 做网站就上房山华网天下大型网站如何开发
  • 从「能用」到「可靠」:深入探讨C++异常安全
  • 如何让AI更好地理解中文PDF中的复杂格式?
  • Mount Image Pro,在取证安全的环境中挂载和访问镜像文件内容
  • 四元数(Quaternion)之Eigen::Quaternion使用详解(5)