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

书生大模型实战营第四期-入门岛-4. maas课程任务

书生大模型实战营第四期-入门岛-4. maas课程任务

任务一、模型下载

任务内容

使用Hugging Face平台、魔搭社区平台(可选)和魔乐社区平台(可选)下载文档中提到的模型(至少需要下载config.json文件、model.safetensors.index.json文件),请在必要的步骤以及结果当中截图。

作业过程

下载internlm2_5-7b-chat的配置文件

新建一个hf_download_josn.py 文件,内容如下:

import os
from huggingface_hub import hf_hub_download# 指定模型标识符
repo_id = "internlm/internlm2_5-7b"# 指定要下载的文件列表
files_to_download = [{"filename": "config.json"},{"filename": "model.safetensors.index.json"}
]# 创建一个目录来存放下载的文件
local_dir = f"{repo_id.split('/')[1]}"
os.makedirs(local_dir, exist_ok=True)# 遍历文件列表并下载每个文件
for file_info in files_to_download:file_path = hf_hub_download(repo_id=repo_id,filename=file_info["filename"],local_dir=local_dir)print(f"{file_info['filename']} file downloaded to: {file_path}")

L0-maas-task4-hf-download

下载internlm2_5-chat-1_8b并打印示例输出

创建hf_download_1_8_demo.py文件,内容如下:

import torch
from transformers import AutoTokenizer, AutoModelForCausalLMtokenizer = AutoTokenizer.from_pretrained("internlm/internlm2_5-1_8b", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("internlm/internlm2_5-1_8b", torch_dtype=torch.float16, trust_remote_code=True)
model = model.eval()inputs = tokenizer(["A beautiful flower"], return_tensors="pt")
gen_kwargs = {"max_length": 128,"top_p": 0.8,"temperature": 0.8,"do_sample": True,"repetition_penalty": 1.0
}# 以下内容可选,如果解除注释等待一段时间后可以看到模型输出
output = model.generate(**inputs, **gen_kwargs)
output = tokenizer.decode(output[0].tolist(), skip_special_tokens=True)
print(output)

L0-maas-task4-hf-demo

任务二、模型上传(可选)

作业内容

将我们下载好的config.json文件(也自行添加其他模型相关文件)上传到对应HF平台和魔搭社区平台,并截图。

作业过程

上传模型文件到HF平台

通过CLI上传 Hugging Face同样是跟Git相关联,通常大模型的模型文件都比较大,因此我们需要安装git lfs,对大文件系统支持。

curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
# sudo apt-get install git-lfs # CodeSpace里面可能会有aptkey冲突且没有足够权限
git lfs install # 直接在git环境下配置git LFS
pip install huggingface_hub

在github的CodeSpace里面:

git config --global credential.helper store
huggingface-cli login

命令行登录hf,输入token(在hg创建并获取):

@lldhsds ➜ /workspaces/codespaces-jupyter (main) $ git config --global credential.helper store
@lldhsds ➜ /workspaces/codespaces-jupyter (main) $ huggingface-cli login_|    _|  _|    _|    _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|_|_|_|    _|_|      _|_|_|  _|_|_|_|_|    _|  _|    _|  _|        _|          _|    _|_|    _|  _|            _|        _|    _|  _|        _|_|_|_|_|  _|    _|  _|  _|_|  _|  _|_|    _|    _|  _|  _|  _|  _|_|      _|_|_|    _|_|_|_|  _|        _|_|_|_|    _|  _|    _|  _|    _|  _|    _|    _|    _|    _|_|  _|    _|      _|        _|    _|  _|        _|_|    _|    _|_|      _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|        _|    _|    _|_|_|  _|_|_|_|To log in, `huggingface_hub` requires a token generated from https://huggingface.co/settings/tokens .
Enter your token (input will not be visible): 
Add token as git credential? (Y/n) Y
Token is valid (permission: write).
The token `hf_internlm_test` has been saved to /home/codespace/.cache/huggingface/stored_tokens
Your token has been saved in your configured git credential helpers (store).
Your token has been saved to /home/codespace/.cache/huggingface/token
Login successful.
The current active token is: `hf_internlm_test`

创建hg项目:

# intern_study_L0_4就是model_name
@lldhsds ➜ /workspaces/codespaces-jupyter (main) $ huggingface-cli repo create intern_study_L0_4
git version 2.47.0
git-lfs/3.5.1 (GitHub; linux amd64; go 1.21.8)You are about to create lldhsds/intern_study_L0_4
Proceed? [Y/n] YYour repo now lives at:https://huggingface.co/lldhsds/intern_study_L0_4You can clone it locally with the command below, and commit/push as usual.git clone https://huggingface.co/lldhsds/intern_study_L0_4# 将上面创建的项目克隆到本地
@lldhsds ➜ /workspaces/codespaces-jupyter (main) $ git clone https://huggingface.co/lldhsds/intern_study_L0_4
Cloning into 'intern_study_L0_4'...
remote: Enumerating objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 3 (from 1)
Unpacking objects: 100% (3/3), 1.05 KiB | 1.05 MiB/s, done.

更新项目并推送到远程仓库:

# 添加README.md文件
@lldhsds ➜ /workspaces/codespaces-jupyter/intern_study_L0_4 (main) $ vim README.md@lldhsds ➜ /workspaces/codespaces-jupyter/intern_study_L0_4 (main) $ git add .
@lldhsds ➜ /workspaces/codespaces-jupyter/intern_study_L0_4 (main) $ git commit -m "add:intern_study_L0_4"
[main 380529d] add:intern_study_L0_41 file changed, 3 insertions(+)create mode 100644 README.md
@lldhsds ➜ /workspaces/codespaces-jupyter/intern_study_L0_4 (main) $ git push
remote: Password authentication in git is no longer supported. You must use a user access token or an SSH key instead. See https://huggingface.co/blog/password-git-deprecation
fatal: Authentication failed for 'https://huggingface.co/lldhsds/intern_study_L0_4/'
@lldhsds ➜ /workspaces/codespaces-jupyter/intern_study_L0_4 (main) $ export hf_token="xxx"	# 此处设置hf access key@lldhsds ➜ /workspaces/codespaces-jupyter/intern_study_L0_4 (main) $ git remote set-url origin  https://lldhsds:$hf_token@huggingface.co/lldhsds/intern_study_L0_4
@lldhsds ➜ /workspaces/codespaces-jupyter/intern_study_L0_4 (main) $ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 449 bytes | 449.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
remote: -------------------------------------------------------------------------
remote: Your push was accepted, but with warnings: 
remote: - Warning: empty or missing yaml metadata in repo card
remote: help: https://huggingface.co/docs/hub/model-cards#model-card-metadata
remote: -------------------------------------------------------------------------
remote: -------------------------------------------------------------------------
remote: Please find the documentation at:
remote: https://huggingface.co/docs/hub/model-cards#model-card-metadata
remote: 
remote: -------------------------------------------------------------------------
To https://huggingface.co/lldhsds/intern_study_L0_4510dcc0..380529d  main -> main

仓库信息:

L0-maas-task4-hf-repo

上传模型文件到魔搭社区平台
  1. 魔搭社区注册登录,并创建model

L0-maas-modelscope-model

  1. 下载模型并修改
git clone https://www.modelscope.cn/lldhsds/intern_study_L0_4.git
  1. 上传模型文件
(/root/share/pre_envs/pytorch2.1.2cu12.1) root@intern-studio-50014188:~/intern_study_L0_4# ls
README.md  configuration.json# 创建config.json
(/root/share/pre_envs/pytorch2.1.2cu12.1) root@intern-studio-50014188:~/intern_study_L0_4# vim config.json# git提交三部曲
(/root/share/pre_envs/pytorch2.1.2cu12.1) root@intern-studio-50014188:~/intern_study_L0_4# git add .
(/root/share/pre_envs/pytorch2.1.2cu12.1) root@intern-studio-50014188:~/intern_study_L0_4# git commit -m "add:intern_study_L0_4"
[master ac42332] add:intern_study_L0_41 file changed, 35 insertions(+)create mode 100644 config.json# 这一步需要进行验证,moodelscope用户名+ moodelscope git token
(/root/share/pre_envs/pytorch2.1.2cu12.1) root@intern-studio-50014188:~/intern_study_L0_4# git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 128 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 692 bytes | 57.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
To https://www.modelscope.cn/lldhsds/intern_study_L0_4.git5acaa46..ac42332  master -> master
  1. 查看仓库

上传的文件,modelspace需要审核。

L0-maas-modelscope-model-up

任务三、Space上传(可选)

作业内容

在HF平台上使用Spaces并把intern_cobuild部署成功,关键步骤截图。

作业过程

访问下面链接https://huggingface.co/spaces,点击右上角的Create new Space创建项目,输入项目名为intern_cobuild,并选择Static应用进行创建,创建成功后会自动跳转到一个默认的HTML页面。

创建好项目后,回到githuab的CodeSpace,接着clone并修改项目:

@lldhsds ➜ /workspaces/codespaces-jupyter (main) $ git clone https://huggingface.co/spaces/lldhsds/intern_cobuild
Cloning into 'intern_cobuild'...
remote: Enumerating objects: 6, done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 6 (from 1)
Unpacking objects: 100% (6/6), 1.88 KiB | 1.88 MiB/s, done.
@lldhsds ➜ /workspaces/codespaces-jupyter (main) $ cd intern_cobuild/
@lldhsds ➜ /workspaces/codespaces-jupyter/intern_cobuild (main) $ ls
README.md  index.html  style.css
@lldhsds ➜ /workspaces/codespaces-jupyter/intern_cobuild (main) $ mv index.html index.html.bak
@lldhsds ➜ /workspaces/codespaces-jupyter/intern_cobuild (main) $ vim index.html 

index.html文件内容修改如下:

<!doctype html>
<html>
<head><meta charset="utf-8" /><meta name="viewport" content="width=device-width" /><title>My static Space</title><style>html, body {margin: 0;padding: 0;height: 100%;}body {display: flex;justify-content: center;align-items: center;}iframe {width: 430px;height: 932px;border: none;}</style>
</head>
<body><iframe src="https://colearn.intern-ai.org.cn/cobuild" title="description"></iframe>
</body>
</html>

推送修改:

@lldhsds ➜ /workspaces/codespaces-jupyter/intern_cobuild (main) $ export hf_token="xxx" # 这里操作时改为
@lldhsds ➜ /workspaces/codespaces-jupyter/intern_cobuild (main) $ git remote set-url origin https://lldhsds:$hf_token@huggingface.co/spaces/lldhsds/intern_cobuild/
@lldhsds ➜ /workspaces/codespaces-jupyter/intern_cobuild (main) $ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 4 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 596 bytes | 596.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 (from 0)
To https://huggingface.co/spaces/lldhsds/intern_cobuild/fb177af..3b8fef2  main -> main

推送成功后查看Space界面,界面已更新:

L0-maas-task4-hf-space

相关文章:

书生大模型实战营第四期-入门岛-4. maas课程任务

书生大模型实战营第四期-入门岛-4. maas课程任务 任务一、模型下载 任务内容 使用Hugging Face平台、魔搭社区平台&#xff08;可选&#xff09;和魔乐社区平台&#xff08;可选&#xff09;下载文档中提到的模型&#xff08;至少需要下载config.json文件、model.safetensor…...

Spring ApplicationListener监听

【JavaWeb】Spring ApplicationListener-CSDN博客 ApplicationEvent以及Listener是Spring为我们提供的一个事件监听、订阅的实现&#xff0c;内部实现原理是观察者设计模式&#xff0c;设计初衷也是为了系统业务逻辑之间的解耦&#xff0c;提高可扩展性以及可维护性。事件发布…...

K8s调度器扩展(scheduler)

1.K8S调度器 筛选插件扩展 为了熟悉 K8S调度器扩展步骤&#xff0c;目前只修改 筛选 插件 准备环境&#xff08;到GitHub直接下载压缩包&#xff0c;然后解压&#xff0c;解压要在Linux系统下完成&#xff09; 2. 编写调度器插件代码 在 Kubernetes 源代码目录下编写调度插件…...

IntelliJ IDEA 中,自动导包功能

在 IntelliJ IDEA 中&#xff0c;自动导包功能可以极大地提高开发效率&#xff0c;减少手动导入包所带来的繁琐和错误。以下是如何在 IntelliJ IDEA 中设置和使用自动导包功能的详细步骤&#xff1a; 一、设置自动导包 打开 IntelliJ IDEA&#xff1a; 启动 IntelliJ IDEA 并打…...

Spring事务笔记

目录 1.Spring 编程式事务 2.Transactional 3.事务隔离级别 4.Spring 事务传播机制 什么是事务? 事务是⼀组操作的集合, 是⼀个不可分割的操作. 事务会把所有的操作作为⼀个整体, ⼀起向数据库提交或者是撤销操作请求. 所以这组操作要么同时成 功, 要么同时失败 1.Spri…...

SQLite 管理工具 SQLiteStudio 3.4.5 发布

SQLiteStudio 3.4.5 版本现已发布&#xff0c;它带来了大量的 bug 修复&#xff0c;并增加了一些小功能。SQLiteStudio 是一个跨平台的 SQLite 数据库的管理工具。 具体更新内容包括&#xff1a; 现在可以使用 Collations Editor 窗口在数据库中注册 Extension-based collatio…...

QT 实现组织树状图

1.实现效果 在Qt中使用QGraphicsItem和QGraphicsScene实现树状图,你需要创建自定义的QGraphicsItem类来表示树的节点,并管理它们的位置和连接,以下是实现效果图。 2.实现思路 可以看见,上图所示,我们需要自定义连线类和节点类。 每个节点类Node,需要绘制矩形框体文字…...

go-学习

文章目录 简介标识符字符串的拼接&#xff0c;关键字数据类型声明变量常量算术运算符关系运算符逻辑运算符位运算赋值运算符其他运算符 简介 Go 语言的基础组成有以下几个部分&#xff1a; 1.包声明 2.引入包 3.函数 4.变量 5.语句 & 表达式 6.注释 package main import &q…...

【面试分享】主流编程语言的内存回收机制及其优缺点

以下是几种主流编程语言的内存回收机制及其优缺点&#xff1a; 一、Java 内存回收机制&#xff1a; Java 使用自动内存管理&#xff0c;主要通过垃圾回收器&#xff08;Garbage Collector&#xff0c;GC&#xff09;来回收不再被使用的对象所占用的内存。Java 的垃圾回收器会定…...

STM32-- 串口发送数据

while(USART_GetFlagStatus(USART2,USART_FLAG_TXE)RESET);&#xff1f;&#xff1f; 答&#xff1a; 这行代码&#xff1a; while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) RESET);的作用是等待串口 USART2 的发送数据寄存器&#xff08;TXE&#xff0c;Transmit Dat…...

数据结构 (13)串的应用举例

前言 数据结构中的串&#xff08;String&#xff09;&#xff0c;也称为字符串&#xff0c;是一种常见且重要的数据结构&#xff0c;在计算机科学中被广泛应用于各种场景。 一、文本处理 文本编辑器&#xff1a;在文本编辑器中&#xff0c;字符串被用来表示和存储用户输入的文本…...

qt-- - 版本和下载介绍

qt版本很多&#xff0c;每个大版本都有几个版本是长期支持的&#xff08;LTS&#xff09;&#xff0c;最好使用长期支持的。 例如qt5.15 qt6.2 qt6.8 都是LTS版本的。 qt在线安装需要提供账号&#xff0c;之前安装qt6.8因为账号问题试了很长时间&#xff0c;密码错了。 …...

解锁 Vue 项目中 TSX 配置与应用简单攻略

在 Vue 项目中配置 TSX 写法 在 Vue 项目中使用 TSX 可以为我们带来更灵活、高效的开发体验&#xff0c;特别是在处理复杂组件逻辑和动态渲染时。以下是详细的配置步骤&#xff1a; 一、安装相关依赖 首先&#xff0c;我们需要在命令行中输入以下命令来安装 vitejs/plugin-v…...

ShuffleNet:一种为移动设备设计的极致高效的卷积神经网络

摘要 https://arxiv.org/pdf/1707.01083 我们介绍了一种名为ShuffleNet的计算效率极高的卷积神经网络&#xff08;CNN&#xff09;架构&#xff0c;该架构专为计算能力非常有限的移动设备&#xff08;例如10-150 MFLOPs&#xff09;而设计。新架构利用两种新操作&#xff1a;逐…...

yum源问题的解决方案

linux课堂作业 问题描述 yum 直接安装tree的问题截图 这个错误表明你的系统没有正确注册到 Red Hat Subscription Management&#xff08;这个问题不用管&#xff09;&#xff0c;也没有配置有效的 YUM 软件仓库&#xff0c;因此无法安装或更新软件包。 解决方案&#xff08…...

在Linux中备份msyql数据库和表的详细操作

目录 前情提要 一、备份mysql数据库 原库展示 (一)新建一个数据库 (二)在linux根目录下找个位置暂时存放 (三)临时sql还原真正存放到库中 (四)查看是否备份成功 备份库成功展示 二、备份表的操作 ​编辑 原表emp展示 (一)快速新建一个原结构相同的表 (二)原表所…...

实时数仓Kappa架构:从入门到实战

引言 随着大数据技术的不断发展&#xff0c;企业对实时数据处理和分析的需求日益增长。实时数仓&#xff08;Real-Time Data Warehouse, RTDW&#xff09;应运而生&#xff0c;其中Kappa架构作为一种简化的数据处理架构&#xff0c;通过统一的流处理框架&#xff0c;解决了传统…...

【老白学 Java】Warship v2.0(四)

Warship v2.0&#xff08;四&#xff09; 文章来源&#xff1a;《Head First Java》修炼感悟。 上一篇文章中&#xff0c;老白仔细分析了 v2.0 的设计思路以及实现手段&#xff0c;如果大家有好的设计方案也可以自行尝试。 本篇文章的主要内容是对 Warship 类进行最后的修改&a…...

LLM之学习笔记(一)

前言 记录一下自己的学习历程&#xff0c;也怕自己忘掉了某些知识点 Prefix LM 和 Causal LM区别是什么&#xff1f; Prefix LM &#xff08;前缀语⾔模型&#xff09;和 Causal LM&#xff08;因果语言模型&#xff09;是两者不同类型的语言模型&#xff0c;它们的区别在于生…...

C# 反射详解

反射是C#中的一个强大特性&#xff0c;允许程序在运行时检查和操作类型和对象的信息。 通过反射&#xff0c;你可以获取类型的属性、方法、构造函数等信息&#xff0c;并可以动态创建对象、调用方法或访问属性&#xff0c;甚至可以实现某些框架或库的核心功能。 反射的基本概念…...

RocketMQ延迟消息机制

两种延迟消息 RocketMQ中提供了两种延迟消息机制 指定固定的延迟级别 通过在Message中设定一个MessageDelayLevel参数&#xff0c;对应18个预设的延迟级别指定时间点的延迟级别 通过在Message中设定一个DeliverTimeMS指定一个Long类型表示的具体时间点。到了时间点后&#xf…...

FFmpeg 低延迟同屏方案

引言 在实时互动需求激增的当下&#xff0c;无论是在线教育中的师生同屏演示、远程办公的屏幕共享协作&#xff0c;还是游戏直播的画面实时传输&#xff0c;低延迟同屏已成为保障用户体验的核心指标。FFmpeg 作为一款功能强大的多媒体框架&#xff0c;凭借其灵活的编解码、数据…...

1688商品列表API与其他数据源的对接思路

将1688商品列表API与其他数据源对接时&#xff0c;需结合业务场景设计数据流转链路&#xff0c;重点关注数据格式兼容性、接口调用频率控制及数据一致性维护。以下是具体对接思路及关键技术点&#xff1a; 一、核心对接场景与目标 商品数据同步 场景&#xff1a;将1688商品信息…...

NFT模式:数字资产确权与链游经济系统构建

NFT模式&#xff1a;数字资产确权与链游经济系统构建 ——从技术架构到可持续生态的范式革命 一、确权技术革新&#xff1a;构建可信数字资产基石 1. 区块链底层架构的进化 跨链互操作协议&#xff1a;基于LayerZero协议实现以太坊、Solana等公链资产互通&#xff0c;通过零知…...

学习STC51单片机32(芯片为STC89C52RCRC)OLED显示屏2

每日一言 今天的每一份坚持&#xff0c;都是在为未来积攒底气。 案例&#xff1a;OLED显示一个A 这边观察到一个点&#xff0c;怎么雪花了就是都是乱七八糟的占满了屏幕。。 解释 &#xff1a; 如果代码里信号切换太快&#xff08;比如 SDA 刚变&#xff0c;SCL 立刻变&#…...

Springboot社区养老保险系统小程序

一、前言 随着我国经济迅速发展&#xff0c;人们对手机的需求越来越大&#xff0c;各种手机软件也都在被广泛应用&#xff0c;但是对于手机进行数据信息管理&#xff0c;对于手机的各种软件也是备受用户的喜爱&#xff0c;社区养老保险系统小程序被用户普遍使用&#xff0c;为方…...

Java毕业设计:WML信息查询与后端信息发布系统开发

JAVAWML信息查询与后端信息发布系统实现 一、系统概述 本系统基于Java和WML(无线标记语言)技术开发&#xff0c;实现了移动设备上的信息查询与后端信息发布功能。系统采用B/S架构&#xff0c;服务器端使用Java Servlet处理请求&#xff0c;数据库采用MySQL存储信息&#xff0…...

使用LangGraph和LangSmith构建多智能体人工智能系统

现在&#xff0c;通过组合几个较小的子智能体来创建一个强大的人工智能智能体正成为一种趋势。但这也带来了一些挑战&#xff0c;比如减少幻觉、管理对话流程、在测试期间留意智能体的工作方式、允许人工介入以及评估其性能。你需要进行大量的反复试验。 在这篇博客〔原作者&a…...

接口自动化测试:HttpRunner基础

相关文档 HttpRunner V3.x中文文档 HttpRunner 用户指南 使用HttpRunner 3.x实现接口自动化测试 HttpRunner介绍 HttpRunner 是一个开源的 API 测试工具&#xff0c;支持 HTTP(S)/HTTP2/WebSocket/RPC 等网络协议&#xff0c;涵盖接口测试、性能测试、数字体验监测等测试类型…...

【JVM】Java虚拟机(二)——垃圾回收

目录 一、如何判断对象可以回收 &#xff08;一&#xff09;引用计数法 &#xff08;二&#xff09;可达性分析算法 二、垃圾回收算法 &#xff08;一&#xff09;标记清除 &#xff08;二&#xff09;标记整理 &#xff08;三&#xff09;复制 &#xff08;四&#xff…...