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

【经验总结】超算互联网服务器 transformers 加载本地模型

1. 背景

使用 超算互联网 的云服务,不能连接外网,只能把模型下载到本地,再上传上去到云服务。

2. 模型下载

在 模型中 https://huggingface.co/models 找到所需的模型后
在这里插入图片描述
点击下载 config.json pytorch_model.bin vocab.txt

3. 上传模型文件

打开文件管理 e-file
点击 上传,选择 本地上传
在这里插入图片描述

4. 运行代码

由原来的代码:

from transformers import BertTokenizer, BertForSequenceClassificationmodel = BertForSequenceClassification.from_pretrained('bert-base-chinese', num_labels=2)
tokenizer = BertTokenizer.from_pretrained('bert-base-chinese')

改成这样的:

from transformers import BertTokenizer, BertForSequenceClassificationpath_to_local_model_directory="/public/home/acc5trotmy/jupyter/models/bert-base-chinese"model = BertForSequenceClassification.from_pretrained(path_to_local_model_directory, num_labels=2)
tokenizer = BertTokenizer.from_pretrained(path_to_local_model_directory)

或者:

from transformers import BertTokenizer, BertForSequenceClassification, BertConfigconfig = BertConfig.from_pretrained(path_to_local_model_directory)
model = BertForSequenceClassification.from_pretrained(path_to_local_model_directory, config=config)
tokenizer = BertTokenizer.from_pretrained(path_to_local_model_directory)
http://www.lryc.cn/news/349168.html

相关文章:

  • ubuntu编译pcl时报错
  • Rust中的单元测试
  • ubuntu18.04系统安装pangolin
  • 洛谷P10397题解
  • 【Linux】自动化编译工具——make/makefile(超细图例详解!!)
  • goroutine调度策略
  • TypeScript中`unknown`的使用场景:安全处理未知类型
  • react18【系列实用教程】JSX (2024最新版)
  • Docker 创建网络
  • ASME美国机械工程师学会文献如何查询下载经验分享
  • Spring MVC分页示例
  • C++基础——继承(上)
  • 编译安装Python3
  • MySQL数据库核心面试题
  • Golang | Leetcode Golang题解之第85题最大矩形
  • Linux基础知识面试题
  • 中国高分辨率国家土壤信息网格基本属性数据集(2010-2018)
  • 数据仓库项目---Day01
  • 若依生成树表和下拉框选择树表结构(在其他页面使用该下拉框输入)
  • 考研数学|李林《880》做不动,怎么办!?看这一篇!
  • paddle ocr 版面分析
  • 25. K 个一组翻转链表 - 力扣(LeetCode)
  • 使用 GPT-4-turbo+Streamlit+wiki+calculator构建Math Agents应用【Step by Step】
  • [240514] OpenAI 发布 GPT-4o,人机交互的历史性时刻 | 苹果芯片进军服务器剑指AI​ | 谷歌大会以AI为主
  • Maximo 在 Automation Script 中访问数据库
  • gitee 简易使用 上传文件
  • iOS Xcode 升级Xcode15报错: SDK does not contain ‘libarclite
  • 即插即用篇 | YOLOv8引入轴向注意力 Axial Attention | 多维变换器中的轴向注意力
  • 【芯片制造】【常用术语】CP、FT、WAT
  • 计算机vcruntime140.dll找不到如何修复,分享5种靠谱的修复教程