四期书生大模型实战营(【入门岛】- 第4关 | 玩转HF/魔搭/魔乐社区)

news2024/10/28 0:37:06

文章目录

  • 1. 任务介绍
    • 闯关任务
  • 2. 平台介绍
    • 2.1. HF 平台
      • 2.1.1. HF的Transformers库介绍
    • 2.2. GitHub CodeSpaces 和 Hugging Face Spaces 介绍。
      • 2.2.1. GitHub CodeSpaces
      • 2.2.2. Hugging Face Spaces
      • 2.2.3. 总结
  • 3. 模型下载
    • 3.1. GitHub CodeSpaces使用
    • 3.1.下载internlm2_5-7b-chat的配置文件
    • 3.2. 下载internlm2_5-chat-1_8b并打印示例输出
  • 3. Space上传(可选)
    • 3.1. Hugging Face Spaces的使用
    • 3.2. 创建页面
    • 3.3. 回到我们的CodeSpace clone项目
    • 3.4. 保存后push到远程仓库上(它会自动更新页面)
  • 4. 模型上传(可选)
    • 4.1. 安装git lfs
    • 4.2. 获取HF登录过程中需要输入用户的Access Tokens
    • 4.3. 在CodeSpace里面登录
    • 4.4. 创建项目
    • 4.5. 用git提交到远程仓库

1. 任务介绍

闯关任务

闯关任务需要在关键步骤当中截图!

任务描述时间
模型下载使用Hugging Face平台、魔搭社区平台(可选)和魔乐社区平台(可选)下载文档中提到的模型(至少需要下载config.json文件、odel.safetensors.index.json文件),请在必要的步骤以及结果当中截图。20min
模型上传(可选)将我们下载好的config.json文件(也自行添加其他模型相关文件)上传到对应HF平台和魔搭社区平台,并截图。10min
Space上传(可选)在HF平台上使用Spaces并把intern_cobuild部署成功,关键步骤截图。10min

优秀作业必做可选内容 请将作业发布到知乎、CSDN等任一社交媒体,将作业链接提交到以下问卷,助教老师批改后将获得 50 算力点奖励!!!

提交地址:https://aicarrier.feishu.cn/share/base/form/shrcnUqshYPt7MdtYRTRpkiOFJd

2. 平台介绍

2.1. HF 平台

Hugging Face
最初专注于开发聊天机器人服务。尽管他们的聊天机器人项目并未取得预期的成功,但他们在GitHub上开源的Transformers库却意外地在机器学习领域引起了巨大轰动。如今,Hugging Face已经发展成为一个拥有超过100,000个预训练模型和10,000个数据集的平台,被誉为机器学习界的GitHub。

2.1.1. HF的Transformers库介绍

在正式下载之前,介绍一下HF的Transformers库,作为HF最核心的项目,它可以:
在这里插入图片描述

  • 直接使用预训练模型进行推理
  • 提供了大量预训练模型可供使用
  • 使用预训练模型进行迁移学习 因此在使用HF前,我们需要下载Transformers等一些常用依赖库

这里我们以internlm2_5-1_8b举例,查看Hugging Face上该模型的地址

https://huggingface.co/internlm/internlm2_5-1_8b

2.2. GitHub CodeSpaces 和 Hugging Face Spaces 介绍。

后面的下载和上传需要用到GitHub CodeSpaces 和 Hugging Face Spaces。下面介绍一下他们的异同:GitHub CodeSpacesHugging Face Spaces 都是强大的云端开发环境,分别由 GitHub 和 Hugging Face 提供,设计用来简化不同类型项目的开发流程。以下是它们的功能、特点和适用场景:


2.2.1. GitHub CodeSpaces

GitHub CodeSpaces 是 GitHub 提供的一个基于云的开发环境,旨在让开发者可以快速创建和配置所需的开发环境,直接在浏览器或本地支持远程连接的 IDE(如 VS Code)中使用。这极大地减少了传统开发环境的配置时间,尤其适用于需要频繁切换项目的开发者。

特点和功能

  • 环境定制:支持 Docker 容器的自定义配置,使你可以配置和存储特定的开发环境,供团队中的其他成员直接使用。
  • 快速启动:开发者可以从 GitHub 仓库快速启动一个新的开发空间,无需手动安装依赖或配置环境。
  • 资源管理:提供不同配置的资源选项(如 CPU、RAM 配置),适用于不同类型的项目,从简单的脚本开发到大型应用。
  • 集成 GitHub 工作流:自动与 GitHub 仓库关联,便于代码版本控制和提交。
  • 多端支持:可在本地的 VS Code 使用,也可直接在浏览器中使用。

适用场景

  • 用于快速搭建和部署开发环境,减少开发配置时间。
  • 团队合作开发,确保所有开发者在一致的环境中进行代码编辑。
  • 适合需要频繁切换或同时处理多个项目的开发者。

2.2.2. Hugging Face Spaces

Hugging Face Spaces 是 Hugging Face 提供的云端应用托管平台,主要面向 AI 和机器学习应用的展示和交互。开发者可以将自己的模型部署到 Hugging Face Spaces 上,用户可以直接在网页中进行交互,试用模型的功能。

特点和功能

  • 支持 Gradio 和 Streamlit:可直接使用 Gradio 或 Streamlit 等流行框架,快速构建交互式前端界面。
  • 轻松部署机器学习模型:支持 Hugging Face 的 Transformers、Diffusers 等库的快速集成,便于展示和使用预训练模型。
  • 免费与付费资源:免费用户可以使用有限的计算资源,专业和企业用户可以选择更高的资源配置,适合部署资源需求更高的项目。
  • 开源和社区分享:支持公开或私有空间的选择,开发者可以将模型分享给社区使用,便于 AI 应用的测试和推广。

适用场景

  • 部署和展示 AI 模型的交互界面,便于用户直接体验模型功能。
  • 面向数据科学、AI 开发人员,便于共享和推广模型和项目。
  • 适用于快速构建可视化界面,并希望与社区分享的机器学习项目。

2.2.3. 总结

  • GitHub CodeSpaces:适用于通用软件开发环境的快速配置和共享,专注于代码编辑和调试。
  • Hugging Face Spaces:专为机器学习和 AI 模型展示而设计,支持互动界面创建和模型托管。

两者都有助于提高开发效率,一个专注于代码编辑环境,一个专注于 AI 模型展示和体验。

3. 模型下载

模型下载 ,这里需要进入Hugging Face的官网进行注册:https://huggingface.co/

3.1. GitHub CodeSpaces使用

因为网络和磁盘有限的原因,强烈不建议在 InternStudio 运行,因此这里使用CodeSpace。

https://github.com/codespaces

Github CodeSpace是Github推出的线上代码平台,提供了一系列templates,我们这里选择Jupyter Notebook进行创建环境。创建好环境后,可以进入网页版VSCode的界面,这就是CodeSpace提供给我们的在线编程环境。
在这里插入图片描述
在这里插入图片描述

在界面下方的终端(terminal)安装以下依赖,便于模型运行。

# 安装transformers
pip install transformers==4.38
pip install sentencepiece==0.1.99
pip install einops==0.8.0
pip install protobuf==5.27.2
pip install accelerate==0.33.0

运行结果:

@banjr ➜ /workspaces/codespaces-jupyter (main) $ # 安装transformers
p install sentencepiece==0.1.99
pip install einops==0.8.0
pip install protobuf==5.27.2
pip install accelerate==0.33.0@banjr ➜ /workspaces/codespaces-jupyter (main) $ pip install transformers==4.38
Collecting transformers==4.38
  Downloading transformers-4.38.0-py3-none-any.whl.metadata (131 kB)
Requirement already satisfied: filelock in /home/codespace/.local/lib/python3.12/site-packages (from transformers==4.38) (3.13.1)
Collecting huggingface-hub<1.0,>=0.19.3 (from transformers==4.38)
  Downloading huggingface_hub-0.26.1-py3-none-any.whl.metadata (13 kB)
Requirement already satisfied: numpy>=1.17 in /home/codespace/.local/lib/python3.12/site-packages (from transformers==4.38) (2.1.2)
Requirement already satisfied: packaging>=20.0 in /home/codespace/.local/lib/python3.12/site-packages (from transformers==4.38) (24.1)
Requirement already satisfied: pyyaml>=5.1 in /home/codespace/.local/lib/python3.12/site-packages (from transformers==4.38) (6.0.2)
Collecting regex!=2019.12.17 (from transformers==4.38)
  Downloading regex-2024.9.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (40 kB)
Requirement already satisfied: requests in /home/codespace/.local/lib/python3.12/site-packages (from transformers==4.38) (2.32.3)
Collecting tokenizers<0.19,>=0.14 (from transformers==4.38)
  Downloading tokenizers-0.15.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (6.7 kB)
Collecting safetensors>=0.4.1 (from transformers==4.38)
  Downloading safetensors-0.4.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (3.8 kB)
Requirement already satisfied: tqdm>=4.27 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from transformers==4.38) (4.66.4)
Requirement already satisfied: fsspec>=2023.5.0 in /home/codespace/.local/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.19.3->transformers==4.38) (2024.2.0)
Requirement already satisfied: typing-extensions>=3.7.4.3 in /home/codespace/.local/lib/python3.12/site-packages (from huggingface-hub<1.0,>=0.19.3->transformers==4.38) (4.9.0)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/codespace/.local/lib/python3.12/site-packages (from requests->transformers==4.38) (3.4.0)
Requirement already satisfied: idna<4,>=2.5 in /home/codespace/.local/lib/python3.12/site-packages (from requests->transformers==4.38) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/codespace/.local/lib/python3.12/site-packages (from requests->transformers==4.38) (2.2.3)
Requirement already satisfied: certifi>=2017.4.17 in /home/codespace/.local/lib/python3.12/site-packages (from requests->transformers==4.38) (2024.8.30)
Downloading transformers-4.38.0-py3-none-any.whl (8.5 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.5/8.5 MB 53.1 MB/s eta 0:00:00
Downloading huggingface_hub-0.26.1-py3-none-any.whl (447 kB)
Downloading regex-2024.9.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (797 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 797.0/797.0 kB 5.4 MB/s eta 0:00:00
Downloading safetensors-0.4.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (434 kB)
Downloading tokenizers-0.15.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.6/3.6 MB 46.3 MB/s eta 0:00:00
Installing collected packages: safetensors, regex, huggingface-hub, tokenizers, transformers
Successfully installed huggingface-hub-0.26.1 regex-2024.9.11 safetensors-0.4.5 tokenizers-0.15.2 transformers-4.38.0

[notice] A new release of pip is available: 24.2 -> 24.3
[notice] To update, run: python3 -m pip install --upgrade pip
@banjr ➜ /workspaces/codespaces-jupyter (main) $ pip install sentencepiece==0.1.99
Collecting sentencepiece==0.1.99
  Downloading sentencepiece-0.1.99.tar.gz (2.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.6/2.6 MB 28.9 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: sentencepiece
  Building wheel for sentencepiece (pyproject.toml) ... \
done
  Created wheel for sentencepiece: filename=sentencepiece-0.1.99-cp312-cp312-linux_x86_64.whl size=1287194 sha256=b7585537f47518fcdfb9191f604d89a69b231550fc9dcc074e90f3ec98caecba
  Stored in directory: /home/codespace/.cache/pip/wheels/e0/8c/e0/65e33b1f4b8462dfc537a0cac02e5c03e1207564c300e4bde5
Successfully built sentencepiece
Installing collected packages: sentencepiece
Successfully installed sentencepiece-0.1.99

[notice] A new release of pip is available: 24.2 -> 24.3
[notice] To update, run: python3 -m pip install --upgrade pip
@banjr ➜ /workspaces/codespaces-jupyter (main) $ pip install einops==0.8.0
Collecting einops==0.8.0
  Downloading einops-0.8.0-py3-none-any.whl.metadata (12 kB)
Downloading einops-0.8.0-py3-none-any.whl (43 kB)
Installing collected packages: einops
Successfully installed einops-0.8.0

[notice] A new release of pip is available: 24.2 -> 24.3
[notice] To update, run: python3 -m pip install --upgrade pip
@banjr ➜ /workspaces/codespaces-jupyter (main) $ pip install protobuf==5.27.2
Collecting protobuf==5.27.2
  Downloading protobuf-5.27.2-cp38-abi3-manylinux2014_x86_64.whl.metadata (592 bytes)
Downloading protobuf-5.27.2-cp38-abi3-manylinux2014_x86_64.whl (309 kB)
Installing collected packages: protobuf
Successfully installed protobuf-5.27.2

[notice] A new release of pip is available: 24.2 -> 24.3
[notice] To update, run: python3 -m pip install --upgrade pip
@banjr ➜ /workspaces/codespaces-jupyter (main) $ pip install accelerate==0.33.0
Collecting accelerate==0.33.0
  Downloading accelerate-0.33.0-py3-none-any.whl.metadata (18 kB)
Collecting numpy<2.0.0,>=1.17 (from accelerate==0.33.0)
  Downloading numpy-1.26.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (61 kB)
Requirement already satisfied: packaging>=20.0 in /home/codespace/.local/lib/python3.12/site-packages (from accelerate==0.33.0) (24.1)
Requirement already satisfied: psutil in /home/codespace/.local/lib/python3.12/site-packages (from accelerate==0.33.0) (6.0.0)
Requirement already satisfied: pyyaml in /home/codespace/.local/lib/python3.12/site-packages (from accelerate==0.33.0) (6.0.2)
Requirement already satisfied: torch>=1.10.0 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from accelerate==0.33.0) (2.3.0)
Requirement already satisfied: huggingface-hub>=0.21.0 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from accelerate==0.33.0) (0.26.1)
Requirement already satisfied: safetensors>=0.3.1 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from accelerate==0.33.0) (0.4.5)
Requirement already satisfied: filelock in /home/codespace/.local/lib/python3.12/site-packages (from huggingface-hub>=0.21.0->accelerate==0.33.0) (3.13.1)
Requirement already satisfied: fsspec>=2023.5.0 in /home/codespace/.local/lib/python3.12/site-packages (from huggingface-hub>=0.21.0->accelerate==0.33.0) (2024.2.0)
Requirement already satisfied: requests in /home/codespace/.local/lib/python3.12/site-packages (from huggingface-hub>=0.21.0->accelerate==0.33.0) (2.32.3)
Requirement already satisfied: tqdm>=4.42.1 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from huggingface-hub>=0.21.0->accelerate==0.33.0) (4.66.4)
Requirement already satisfied: typing-extensions>=3.7.4.3 in /home/codespace/.local/lib/python3.12/site-packages (from huggingface-hub>=0.21.0->accelerate==0.33.0) (4.9.0)
Requirement already satisfied: sympy in /home/codespace/.local/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (1.13.1)
Requirement already satisfied: networkx in /home/codespace/.local/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (3.2.1)
Requirement already satisfied: jinja2 in /home/codespace/.local/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (3.1.4)
Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (12.1.105)
Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (12.1.105)
Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (12.1.105)
Requirement already satisfied: nvidia-cudnn-cu12==8.9.2.26 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (8.9.2.26)
Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (12.1.3.1)
Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (11.0.2.54)
Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (10.3.2.106)
Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (11.4.5.107)
Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (12.1.0.106)
Requirement already satisfied: nvidia-nccl-cu12==2.20.5 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (2.20.5)
Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from torch>=1.10.0->accelerate==0.33.0) (12.1.105)
Requirement already satisfied: nvidia-nvjitlink-cu12 in /usr/local/python/3.12.1/lib/python3.12/site-packages (from nvidia-cusolver-cu12==11.4.5.107->torch>=1.10.0->accelerate==0.33.0) (12.6.77)
Requirement already satisfied: MarkupSafe>=2.0 in /home/codespace/.local/lib/python3.12/site-packages (from jinja2->torch>=1.10.0->accelerate==0.33.0) (3.0.1)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/codespace/.local/lib/python3.12/site-packages (from requests->huggingface-hub>=0.21.0->accelerate==0.33.0) (3.4.0)
Requirement already satisfied: idna<4,>=2.5 in /home/codespace/.local/lib/python3.12/site-packages (from requests->huggingface-hub>=0.21.0->accelerate==0.33.0) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/codespace/.local/lib/python3.12/site-packages (from requests->huggingface-hub>=0.21.0->accelerate==0.33.0) (2.2.3)
Requirement already satisfied: certifi>=2017.4.17 in /home/codespace/.local/lib/python3.12/site-packages (from requests->huggingface-hub>=0.21.0->accelerate==0.33.0) (2024.8.30)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in /home/codespace/.local/lib/python3.12/site-packages (from sympy->torch>=1.10.0->accelerate==0.33.0) (1.3.0)
Downloading accelerate-0.33.0-py3-none-any.whl (315 kB)
Downloading numpy-1.26.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (18.0 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 18.0/18.0 MB 67.3 MB/s eta 0:00:00
Installing collected packages: numpy, accelerate
  Attempting uninstall: numpy
    Found existing installation: numpy 2.1.2
    Uninstalling numpy-2.1.2:
      Successfully uninstalled numpy-2.1.2
Successfully installed accelerate-0.33.0 numpy-1.26.4

[notice] A new release of pip is available: 24.2 -> 24.3
[notice] To update, run: python3 -m pip install --upgrade pip
@banjr ➜ /workspaces/codespaces-jupyter (main) $ 

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

考虑到个人GitHub CodeSpace硬盘空间有限(32GB可用),而7B的模型相对较大,这里我们先演示如何下载模型文件夹的特定文件。考虑到CodeSpace平台上默认的用户权限不是root权限,这里为方便演示直接在工作区创建文件,即/workspaces/codespaces-jupyter 目录

以下载模型的配置文件为例,先新建一个hf_download_josn.py 文件。

touch 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}")

在这里插入图片描述
运行该文件(注意文件目录请在该文件所在目录下运行该文件)

python hf_download_josn.py

可以看到,已经从Hugging Face上下载了相应配置文件
在这里插入图片描述

虽然在这里我们没有完全下载internlm2_5-7b-chat模型,但是在实战营课程中,我们的InternStudio平台的 /root/share 目录下已经提供了InterLM2.5系列的模型,可以找到它们作为model_name_or_path进行使用,如/root/share/new_models/Shanghai_AI_Laboratory/internlm2_5-7b-chat

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

那么如果我们需想要下载一个完整的模型文件怎么办呢?创建一个python文件用于下载internlm2_5-1_8B模型并运行。下载速度跟网速和模型参数量大小相关联,如果网速较慢的小伙伴可以只尝试下载1.8b模型对应的config.json文件以及其他配置文件。

touch hf_download_1_8_demo.py

在这里插入图片描述
注意到在CodeSpace平台上是没有GPU资源的,因此我们Python代码中只使用CPU进行推理,我们需要修改跟CUDA有关的API,在hf_download_1_8_demo.py文件中粘贴以下内容:

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = 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)

等待几分钟后,会在控制台返回模型生成的结果(解除注释后)

没有解除注释:
在这里插入图片描述
在这里插入图片描述
解除注释后:
在这里插入图片描述

这里以“A beautiful flower”开头,模型对其进行“续写”,InternLM的模型拥有强大的数学方面的能力。这边它输出的文本似乎是关于一个数学问题。

具体这道题的意思是:
一个美丽的花盆由一个底部的圆柱体和顶部的半球体组成。底部圆柱体的半径是 10 ,顶部半球体的半径也是 10。求这个花盆的体积。

3. Space上传(可选)

3.1. Hugging Face Spaces的使用

Hugging Face Spaces 是一个允许我们轻松地托管、分享和发现基于机器学习模型的应用的平台。Spaces 使得开发者可以快速将我们的模型部署为可交互的 web 应用,且无需担心后端基础设施或部署的复杂性。 首先访问以下链接,进入Spaces。在右上角点击Create new Space进行创建:
https://huggingface.co/spaces
在这里插入图片描述

3.2. 创建页面

在创建页面中,输入项目名为intern_cobuild,并选择Static应用进行创建
在这里插入图片描述
创建成功后会自动跳转到一个默认的HTML页面。创建好项目后,回到我们的CodeSpace,接着clone项目。
在这里插入图片描述

3.3. 回到我们的CodeSpace clone项目

注意这里请替换你自己的username

cd /workspaces/codespaces-jupyter
# 请将<your_username>替换你自己的username
git clone https://huggingface.co/spaces/<your_username>/intern_cobuild
cd /workspaces/codespaces-jupyter/intern_cobuild

找到该目录文件夹下的index.html文件,修改我们的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>

在这里插入图片描述

3.4. 保存后push到远程仓库上(它会自动更新页面)

保存后就可以push到远程仓库上了,它会自动更新页面。

git add .
git commit -m "update: colearn page"
git push

如果报错:remote: Password authentication in git is no longer supported. You must use a user access token or an SSH key instead. 请再次设置这个项目的验证,这个地方需要用户的Access Tokens(具体获取方式见下文 “4.2 获取登录过程中需要输入的用户的Access Tokens”)
git remote set-url origin https://<user_name>:@huggingface.co/<repo_path>
例如:
git remote set-url origin https://jack:hf_xxxxx@huggingface.co/spaces/jack/intern_cobuild/
然后再次git push即可

这个命令用于更新 Git 仓库的远程 URL,将其设置为 Hugging Face 的仓库地址。具体来看:

  1. git remote set-url origin <URL>

    • git remote set-url 是 Git 的命令,用于更改已存在的远程仓库 URL。
    • origin 是默认的远程仓库名称,表示要修改的仓库的名称。
  2. https://<user_name>:<token>@huggingface.co/<repo_path>

    • https:// 后面的部分指定新的远程仓库 URL。
    • <user_name> 是你的 Hugging Face 用户名。
    • <token> 是 Hugging Face 提供的访问令牌,通常用于身份验证,避免每次提交时都要手动输入用户名和密码。
    • huggingface.co/<repo_path> 是 Hugging Face 仓库的地址和路径。

这样配置后,Git 会使用指定的用户凭证自动连接到 Hugging Face 仓库,简化了推送和拉取代码的流程。

再次进入Space界面,就可以看到实战营的共建活动。
在这里插入图片描述

4. 模型上传(可选)

4.1. 安装git lfs

  • 通过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

这个命令是在 Linux 系统上安装 git-lfs(Git Large File Storage) 的脚本,具体分解如下:

  1. curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh
    • curl 是一个命令行工具,用于从 URL 下载内容。
    • -s 参数让 curl 静默运行,不输出下载过程的进度信息。

总结

这个命令通过下载并执行 GitHub 提供的 git-lfs 安装脚本,以便自动完成 Git LFS 的设置和依赖安装。

4.2. 获取HF登录过程中需要输入用户的Access Tokens

使用huggingface-cli login命令进行登录,登录过程中需要输入用户的Access Tokens,获取时,需要先验证email
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

完成验证后,点击create new token,创建一个类型为“Write”的token,并请复制好token后要存储在合适的地方
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

4.3. 在CodeSpace里面登录

接着可以在CodeSpace里面,使用

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

命令进行登录,这时需要输入刚刚的token
在这里插入图片描述

在这里插入图片描述

4.4. 创建项目

cd /workspaces/codespaces-jupyter

#intern_study_L0_4就是model_name
huggingface-cli repo create intern_study_L0_4

# 克隆到本地 your_github_name 注意替换成你自己的
git clone https://huggingface.co/{your_github_name}/intern_study_L0_4

克隆好之后,刷新文件目录可以看到克隆好的intern_study_L0_4文件夹。

我们可以把训练好的模型保存进里面,这里考虑到网速问题,只上传我们刚刚下载好的config.json,把它复制粘贴进这个文件夹里面,还可以写一个README.md文件,比如可以粘贴以下内容:

# 书生浦语大模型实战营camp4
- hugging face模型上传测试
- 更多内容请访问 https://github.com/InternLM/Tutorial/tree/camp4

在这里插入图片描述

4.5. 用git提交到远程仓库

现在可以用git提交到远程仓库

cd intern_study_L0_4
git add .
git commit -m "add:intern_study_L0_4"
git push

在这里插入图片描述

注意,如果git push 报错,可能是第一次上传时需要验证,请使用以下命令,注意替换<>里面的内容,然后再次git push一下就可以了

git remote set-url origin https://<user_name>:<token>@huggingface.co/<repo_path>

# 如 git remote set-url origin https://blank:hf_xxxxxxxxxxx@huggingface.co/blank/intern_study_L0_4

# 这里blank和hf_xxxxxxxxxxxx只是示例 请替换为你的username和之前申请的access token

git pull origin

现在可以在Hugging Face的个人profile里面看到这个model,也可以直接将下面的Url输入到浏览器网址栏上

https://huggingface.co/<user_name>/intern_study_L0_4

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2225051.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

MySQL任意版本安装卸载和数据库原理图绘制

MYSQL任意版本安装和卸载 安装&#xff1a; 1、解压文件 --- 不能出现中文路径 2、在解压目录&#xff08;安装目录&#xff09;下&#xff1a; 1>.创建data文件夹 2>.创建配置文件my.txt 然后修改成ini格式 3、修改配置文件 basedirD:\\mysql\\mysql-5.7.28-winx64…

006:看图软件ACDSeePhotoStudio2019安装教程

摘要&#xff1a;本文主要介绍看图软件ACDSee Photo Studio2019的安装流程。 一、软件概述 ACDSee Photo Studio是ACDSee公司开发的一款面向摄影师和图像编辑者的专业软件。它提供了全面的图像处理、管理和发布功能&#xff0c;帮助用户高效地浏览、编辑、分类和分享数字照片。…

新160个crackme - 084-slayer_crackme1

运行分析 点击check&#xff0c;提示注册失败 PE分析 ASM程序&#xff0c;32位&#xff0c;无壳 静态分析&动态调试 ida搜索到关键字符串发现注册文件reg.key 通过动态调试&#xff0c;获得计算机名称为’CONCEALBEAR’通过计算得到int_2 接下来有一个剪贴板判断&#xff0…

从“摸黑”到“透视”:AORO A23热成像防爆手机如何改变工业检测?

在工业检测领域&#xff0c;传统的检测手段常因效率低下、精度不足和潜在的安全风险而受到诟病。随着科技的不断进步&#xff0c;一种新兴的检测技术——红外热成像技术&#xff0c;正逐渐在该领域崭露头角。近期&#xff0c;小编对一款集成红外热成像技术的AORO A23防爆手机进…

【Linux系统】Ubuntu的简单操作

什么是 Ubuntu&#xff1f; Ubuntu&#xff08;乌帮图&#xff09;是一个非洲词汇&#xff0c;它的意思是“人性对待他人”或“群在故我在”。Ubuntu发行版将Ubuntu精神带到软件世界之中。 目前已有大量各种各样基于GNU/Linux的操作系统&#xff0c;例如:Debian,SuSE,Gentoo,R…

【热门主题】000010 深入 Vue.js 组件开发

前言&#xff1a;哈喽&#xff0c;大家好&#xff0c;今天给大家分享一篇文章&#xff01;并提供具体代码帮助大家深入理解&#xff0c;彻底掌握&#xff01;创作不易&#xff0c;如果能帮助到大家或者给大家一些灵感和启发&#xff0c;欢迎收藏关注哦 &#x1f495; 目录 【热…

【HarmonyOS Next】原生沉浸式界面

背景 在实际项目中&#xff0c;为了软件使用整体色调看起来统一&#xff0c;一般顶部和底部的颜色需要铺满整个手机屏幕。因此&#xff0c;这篇帖子是介绍设置的方法&#xff0c;也是应用沉浸式效果。如下图&#xff1a;底部的绿色延伸到上面的状态栏和下面的导航栏 UI 在鸿蒙…

Android 判断手机放置的方向

#1024程序员节&#xff5c;征文# 文章目录 前言一、pandas是什么&#xff1f;二、使用步骤 1.引入库2.读入数据总结 需求 老板&#xff1a;我有个手持终端&#xff0c;不能让他倒了&#xff0c;当他倒或者倾斜的时候要发出报警&#xff1b; 程序猿&#xff1a;我这..... 老板…

断点续传技术是什么?大型文件传输的新模式!

随着科技的不断进步&#xff0c;文件传输已成为我们日常生活和工作中不可或缺的一部分。然而&#xff0c;传输大型文件时常常会遇到网络不稳定、传输中断等问题&#xff0c;导致传输失败或者重新传输。为解决这一问题&#xff0c;断点续传技术应运而生。 一、断点续传技术是什么…

Ovis: 多模态大语言模型的结构化嵌入对齐

论文题目&#xff1a;Ovis: Structural Embedding Alignment for Multimodal Large Language Model 论文地址&#xff1a;https://arxiv.org/pdf/2405.20797 github地址&#xff1a;https://github.com/AIDC-AI/Ovis/?tabreadme-ov-file 今天&#xff0c;我将分享一项重要的研…

猫头虎 分享:MySQL 中 TEXT 与 LONGTEXT 数据类型详解与使用场景分析

今天猫头虎带大家深入探讨一番&#xff0c;关于 MySQL 中 TEXT 和 LONGTEXT 数据类型的区别与具体使用场景问题。最近有粉丝私信我说&#xff1a;“猫哥&#xff0c;TEXT 和 LONGTEXT 到底应该怎么选择啊&#xff1f;” 我相信很多开发者在面对 MySQL 中的这两个数据类型时&…

Scrapy框架原理与使用流程

一.Scrapy框架特点 框架&#xff08;Framework&#xff09;是一种软件设计方法&#xff0c;它提供了一套预先定义的组件和约定&#xff0c;帮助开发者快速构建应用程序。框架通常包括一组库、工具和约定&#xff0c;它们共同工作以简化开发过程。scrapy框架是python写的 为了爬…

C++的相关习题(2)

初阶模板 下面有关C中为什么用模板类的原因&#xff0c;描述错误的是? ( &#xff09; A.可用来创建动态增长和减小的数据结构 B.它是类型无关的&#xff0c;因此具有很高的可复用性 C.它运行时检查数据类型&#xff0c;保证了类型安全 D.它是平台无关的&#xff0c;可移植…

局部变量和全局变量(Python)

引入例子拆解 源码 class A:def __init__(self):self.test 0def add(c, k):c.test c.test 1k k 1def main():Count A()k 0for i in range(0, 25):add(Count, k)print("Count.test", Count.test)print("k", k)main() 运行结果如下图 代码解析 这…

HTML+JavaScript案例分享: 打造经典俄罗斯方块,详解实现全过程

在本文中,我们将深入探讨如何使用 JavaScript 实现经典的俄罗斯方块游戏。俄罗斯方块是一款广为人知的益智游戏,通过操纵各种形状的方块,使其在游戏区域内排列整齐,以消除完整的行来获得分数。 效果图如下: 一、游戏界面与布局 我们首先使用 HTML 和 CSS 来创建游戏的界面…

Uni-App-03

登录功能开发 实现POST提交 HTTP协议规定请求消息内容类型(Content-Type)有哪些&#xff1f;—— 只有四种 text/plain 没有编码的普通数据 application/x-www-form-urlencoded 编码后的普通数据 multipart/form-data 请求主体中包含文件上传域 application/json 请求主体是 J…

微信小程序版本更新管理——实现自动更新

✅作者简介&#xff1a;2022年博客新星 第八。热爱国学的Java后端开发者&#xff0c;修心和技术同步精进。 &#x1f34e;个人主页&#xff1a;Java Fans的博客 &#x1f34a;个人信条&#xff1a;不迁怒&#xff0c;不贰过。小知识&#xff0c;大智慧。 &#x1f49e;当前专栏…

js构造函数和原型对象,ES6中的class,四种继承方式

一、构造函数 1.构造函数是一种特殊的函数&#xff0c;主要用来初始化对象 2.使用场景 常见的{...}语法允许创建一个对象。可以通过构造函数来快速创建多个类似的对象。 const Peppa {name: 佩奇,age: 6,sex: 女}const George {name: 乔治,age: 3,sex: 男}const Mum {nam…

1 vsCode安装与使用

1 下载地址 Visual Studio Code - Code Editing. Redefined 2 安装 3 安装插件 安装完要重启 chinese:中文插件 open in browser &#xff1a;快速打开浏览器插件 ----------------------------------------------------------------------------------------------------- 重…

嵌入式学习-网络-Day02

嵌入式学习-网络-Day02 1.优化代码&#xff1a; 网络问题&#xff1a; 2.1虚拟机网络修复 2.2 网络调试 ping netstat 3.UDP编程 3.1通信流程 3.2函数接口 1.优化代码&#xff1a; 1.端口和ip地址通过命令行传参到代码中。 2.设置客户端退出&#xff0c;服务器结束循环接收。 通…