赞
踩
摘要:
记录基于MindNLP和ChatGLM-6B实现聊天应用实验的过程和步骤。
安装要用的包和模块mindspore mindnlp mdtex2html
- %%capture captured_output
- # 实验环境已经预装了mindspore==2.2.14,如需更换mindspore版本,可更改下面mindspore的版本号
- !pip uninstall mindspore -y
- !pip install -i https://pypi.mirrors.ustc.edu.cn/simple mindspore==2.2.14
- !export HF_ENDPOINT=https://hf-mirror.com
- !pip install -i https://pypi.mirrors.ustc.edu.cn/simple mindnlp mdtex2html
输出:
- Looking in indexes: https://pypi.mirrors.ustc.edu.cn/simple
- Requirement already satisfied: mindnlp in /home/nginx/miniconda/envs/jupyter/lib/python3.9/site-packages (0.3.1)
- Collecting mdtex2html
- Downloading https://mirrors.bfsu.edu.cn/pypi/web/packages/ff/e8/c5fab9aa5d9254ad7c7e37d33a3c32fd49d82b4c6b54da337bbca378eb5c/mdtex2html-1.3.0-py3-none-any.whl (13 kB)
- Requirement already satisfied: mindspore in /home/nginx/miniconda/envs/jupyter/lib/python3.9/site-packages (from mindnlp) (2.2.14)
- Requirement already satisfied: tqdm in /home/nginx/miniconda/envs/jupyter/lib/python3.9/site-packages (from mindnlp) (4.66.4)
- ......
- Collecting markdown (from mdtex2html)
- Downloading https://mirrors.bfsu.edu.cn/pypi/web/packages/fc/b3/0c0c994fe49cd661084f8d5dc06562af53818cc0abefaca35bdc894577c3/Markdown-3.6-py3-none-any.whl (105 kB)
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 105.4/105.4 kB 11.4 MB/s eta 0:00:00
- Collecting latex2mathml (from mdtex2html)
- Downloading https://mirrors.bfsu.edu.cn/pypi/web/packages/f2/0a/181ed55562ce90179aedf33b09fcd79db31c868a5d480f3cb71a31d19692/latex2mathml-3.77.0-py3-none-any.whl (73 kB)
- ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 73.7/73.7 kB 24.0 MB/s eta 0:00:00
- Requirement already satisfied: filelock in /home/nginx/miniconda/envs/jupyter/lib/python3.9/site-packages (from datasets->mindnlp) (3.15.3)
- ......
- Requirement already satisfied: tzdata>=2022.7 in /home/nginx/miniconda/envs/jupyter/lib/python3.9/site-packages (from pandas->datasets->mindnlp) (2024.1)
- Installing collected packages: latex2mathml, markdown, mdtex2html
- Successfully installed latex2mathml-3.77.0 markdown-3.6 mdtex2html-1.3.0
- [notice] A new release of pip is available: 24.1 -> 24.1.2[notice] To update, run: python -m pip install --upgrade pip
- Note: you may need to restart the kernel to use updated packages.
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
- from mindnlp.transformers import AutoModelForSeq2SeqLM, AutoTokenizer
- import gradio as gr
- import mdtex2html
-
- model = AutoModelForSeq2SeqLM.from_pretrained('ZhipuAI/ChatGLM-6B', mirror="modelscope").half()
- model.set_train(False)
- tokenizer = AutoTokenizer.from_pretrained('ZhipuAI/ChatGLM-6B', mirror="modelscope")
输出:
- 100%━━━━━━━━━━ 773/773 [00:00<00:00, 51.7kB/s]
- 100%━━━━━━━━━━ 32.6k/32.6k [00:00<00:00, 2.75MB/s]
- Downloading shards: 100%
- 8/8 [16:38<00:00, 106.84s/it]
- 100%━━━━━━━━━━ 1.62G/1.62G [02:09<00:00, 13.6MB/s]
- 100%━━━━━━━━━━ 1.75G/1.75G [02:25<00:00, 7.59MB/s]
- 100%━━━━━━━━━━ 1.84G/1.84G [02:26<00:00, 16.6MB/s]
- 100%━━━━━━━━━━ 1.78G/1.78G [02:20<00:00, 15.5MB/s]
- 100%━━━━━━━━━━ 1.75G/1.75G [02:20<00:00, 10.8MB/s]
- 100%━━━━━━━━━━ 1.75G/1.75G [02:18<00:00, 12.0MB/s]
- 100%━━━━━━━━━━ 1.00G/1.00G [01:18<00:00, 21.7MB/s]
- 100%━━━━━━━━━━ 1.00G/1.00G [01:17<00:00, 14.1MB/s]
- Loading checkpoint shards: 100%
- 8/8 [00:46<00:00, 5.13s/it]
- 100%━━━━━━━━━━ 441/441 [00:00<00:00, 21.6kB/s]
- 100%━━━━━━━━━━ 2.58M/2.58M [00:00<00:00, 21.2MB/s]
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
- prompt = '你好'
- history = []
- response, _ = model.chat(tokenizer, prompt, history=history, max_length=20)
- response
输出:
'你好声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/852531
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。