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

做vi设计的国外网站外包服务商

做vi设计的国外网站,外包服务商,什么叫动漫设计与制作,wordpress单本小说开源地址#xff1a; GitHub - THUDM/ChatGLM3: ChatGLM3 series: Open Bilingual Chat LLMs | 开源双语对话语言模型 前言#xff1a;ChatGLM2与ChatGLM3区别 ChatGLM2与ChatGLM3模型架构是完全一致的#xff0c;ChatGLM与后继者结构不同。可见ChatGLM3相对于ChatGLM2没… 开源地址 GitHub - THUDM/ChatGLM3: ChatGLM3 series: Open Bilingual Chat LLMs | 开源双语对话语言模型 前言ChatGLM2与ChatGLM3区别 ChatGLM2与ChatGLM3模型架构是完全一致的ChatGLM与后继者结构不同。可见ChatGLM3相对于ChatGLM2没有模型架构上的改进。 相对于ChatGLMChatGLM2、ChatGLM3模型上的变化 词表的大小从ChatGLM的150528缩小为65024 一个直观的体验是ChatGLM2、3加载比ChatGLM快不少位置编码从每个GLMBlock一份提升为全局一份SelfAttention之后的前馈网络有不同。ChatGLM用GELUGaussian Error Linear Unit做激活ChatGLM用Swish-1做激活。而且ChatGLM2、3应该是修正了之前的一个bug因为GLUGated Linear Unit本质上一半的入参是用来做门控制的不需要输出到下层所以ChatGLM2、3看起来前后维度不一致27392-13696)反而是正确的。 ChatGLM2与ChatGLM区别  ChatGLM2-6B 是开源中英双语对话模型 ChatGLM-6B 的第二代版本在保留了初代模型对话流畅、部署门槛较低等众多优秀特性的基础之上ChatGLM2-6B 引入了如下新特性 更强大的性能基于 ChatGLM 初代模型的开发经验我们全面升级了 ChatGLM2-6B 的基座模型。ChatGLM2-6B 使用了 GLM 的混合目标函数经过了 1.4T 中英标识符的预训练与人类偏好对齐训练评测结果显示相比于初代模型ChatGLM2-6B 在 MMLU23%、CEval33%、GSM8K571% 、BBH60%等数据集上的性能取得了大幅度的提升在同尺寸开源模型中具有较强的竞争力。 更长的上下文基于 FlashAttention 技术我们将基座模型的上下文长度Context Length由 ChatGLM-6B 的 2K 扩展到了 32K并在对话阶段使用 8K 的上下文长度训练允许更多轮次的对话。但当前版本的 ChatGLM2-6B 对单轮超长文档的理解能力有限我们会在后续迭代升级中着重进行优化。 更高效的推理基于 Multi-Query Attention 技术ChatGLM2-6B 有更高效的推理速度和更低的显存占用在官方的模型实现下推理速度相比初代提升了 42%INT4 量化下6G 显存支持的对话长度由 1K 提升到了 8K。 更开放的协议ChatGLM2-6B 权重对学术研究完全开放在获得官方的书面许可后亦允许商业使用。 1、本机安装gpu驱动,cuda本文选定版本11.8 安装cuda toolkit     CUDA Toolkit Archive | NVIDIA Developer      安装cudnn     Log in | NVIDIA Developer (要注册帐号 2、Anaconda,下载后可以通过这个软件安装一个python3.10.11的版本 Free Download | Anacondahttps://www.anaconda.com/download或者下载一个pycharm ,用这个装个python环境 PyCharmJetBrains为专业开发者提供的Python IDEhttps://www.jetbrains.com.cn/pycharm/ 安装好Python后最好设定一下源  pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple 3pytorch window版本选cuda11.8 Start Locally | PyTorchStart Locallyhttps://pytorch.org/get-started/locally/ 选中后得到安装脚本 pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 运行如下图  4、环境安装 首先需要下载本仓库 git clone https://github.com/THUDM/ChatGLM3 cd ChatGLM3 然后使用 pip 安装依赖 pip install -r requirements.txt5、 下载模型有两种方法 方法1可以自定路径 git lfs install git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git 方法2使用python代码下载会下载到c盘C:\Users\用户名\.cache\modelscope\大约10多个G对于我C盘只有几十G剩余空间的贫困户来说不推荐。 from modelscope import snapshot_download model_dir snapshot_download(ZhipuAI/chatglm3-6b, revision v1.0.0) 加个参数local_dir./model_glm3-6b from modelscope import AutoTokenizer, AutoModel, snapshot_download model_dir snapshot_download(ZhipuAI/chatglm3-6b, revision v1.0.0,local_dir./model_glm3-6b) 运行模型 from modelscope import AutoTokenizer, AutoModel, snapshot_download model_dir snapshot_download(ZhipuAI/chatglm3-6b, revision v1.0.0,cache_dir./model_glm3-6b) tokenizer AutoTokenizer.from_pretrained(model_dir, trust_remote_codeTrue) model AutoModel.from_pretrained(model_dir, trust_remote_codeTrue).half().cuda() #model AutoModel.from_pretrained(model_dir, trust_remote_codeTrue).quantize(4).cuda() model model.eval() # response, history model.chat(tokenizer, 你好, history[]) # print(response) response, history model.chat(tokenizer, 晚上睡不着应该怎么办, history[]) print(response) 注意 .half() 方法 model.half() 将模型的参数类型转换为 16 位浮点数half-precision floating-point。这有助于减少模型在内存和显存中的占用空间同时在支持 GPU 的设备上提高模型推理速度。16 位浮点数的优势在于相较于 32 位浮点数它使用更少的内存并且在支持混合精度计算的 GPU 上可以提高计算速度。这样模型点用的显存为6B*2约等于12G .quantize(4) 方法 model.quantize(4) 是模型的量化操作。这将模型的权重和激活缩放到 4 位整数。量化是一种技术通过减少模型中参数的表示位数以减小模型的内存占用和提高推理速度。4 位整数的量化会带来更高的压缩比但可能会引入量化误差因为只有有限的整数可以表示模型的权重和激活。这样模型点用的显存为6B*0.5约等于3G 3.quantize(8) 这将模型的参数和激活值量化为 8 位整数。使用 8 位整数相对于 4 位整数来说具有更高的位宽因此可以表示更大的范围和更精细的数值减小了量化误差。8 位整数的量化通常仍然可以显著减小模型的尺寸同时保留较高的模型精度。 这样模型点用的显存为6B*1约等于6G 我在使用量化时报错Failed to load cpm_kernels:[WinError 267] 目录名称无效。: C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe  当使用quantize(4) 方法时会报错  blockDim (min(round_up(m, 32), 1024), 1, 1) NameError: name round_up is not defined 貌似代码实现有问题改成quantize(8)就可以了,反正我使用的1080ti用quantize(8)也勉强够用。 上代码可以运行的两种方式打开basic_demo目录 改进cli_demo.py 增加 os.environ[MODEL_PATH] rC:\Users\gpu\.cache\modelscope\hub\ZhipuAI\chatglm3-6b 整体代码 import os import platform from transformers import AutoTokenizer, AutoModel os.environ[MODEL_PATH] rC:\Users\gpu\.cache\modelscope\hub\ZhipuAI\chatglm3-6b MODEL_PATH os.environ.get(MODEL_PATH, THUDM/chatglm3-6b) TOKENIZER_PATH os.environ.get(TOKENIZER_PATH, MODEL_PATH)tokenizer AutoTokenizer.from_pretrained(TOKENIZER_PATH, trust_remote_codeTrue) #model AutoModel.from_pretrained(MODEL_PATH, trust_remote_codeTrue, device_mapauto).eval() model AutoModel.from_pretrained(MODEL_PATH, trust_remote_codeTrue ).quantize(8).cuda() os_name platform.system() clear_command cls if os_name Windows else clear stop_stream Falsewelcome_prompt 欢迎使用 ChatGLM3-6B 模型输入内容即可进行对话clear 清空对话历史stop 终止程序def build_prompt(history):prompt welcome_promptfor query, response in history:prompt f\n\n用户{query}prompt f\n\nChatGLM3-6B{response}return promptdef main():past_key_values, history None, []global stop_streamprint(welcome_prompt)while True:query input(\n用户)if query.strip() stop:breakif query.strip() clear:past_key_values, history None, []os.system(clear_command)print(welcome_prompt)continueprint(\nChatGLM, end)current_length 0for response, history, past_key_values in model.stream_chat(tokenizer, query, historyhistory, top_p1,temperature0.01,past_key_valuespast_key_values,return_past_key_valuesTrue):if stop_stream:stop_stream Falsebreakelse:print(response[current_length:], end, flushTrue)current_length len(response)print()if __name__ __main__:main() 运行 python cli_demo.py 就可以在命令行中愉快使用 打开basic_demo目录 改进web_demo_streamlit.py也是在头部增加了 os.environ[MODEL_PATH] rC:\Users\gpu\.cache\modelscope\hub\ZhipuAI\chatglm3-6b This script is a simple web demo based on Streamlit, showcasing the use of the ChatGLM3-6B model. For a more comprehensive web demo, it is recommended to use composite_demo.Usage: - Run the script using Streamlit: streamlit run web_demo_streamlit.py - Adjust the model parameters from the sidebar. - Enter questions in the chat input box and interact with the ChatGLM3-6B model.Note: Ensure streamlit and transformers libraries are installed and the required model checkpoints are available. import os import streamlit as st import torch from transformers import AutoModel, AutoTokenizer os.environ[MODEL_PATH] rD:\ChatGLM3\model_glm3-6b\ZhipuAI\chatglm3-6b MODEL_PATH os.environ.get(MODEL_PATH, THUDM/chatglm3-6b) TOKENIZER_PATH os.environ.get(TOKENIZER_PATH, MODEL_PATH)st.set_page_config(page_titleChatGLM3-6B Streamlit Simple Demo,page_icon:robot:,layoutwide )st.cache_resource def get_model():tokenizer AutoTokenizer.from_pretrained(TOKENIZER_PATH, trust_remote_codeTrue)#model AutoModel.from_pretrained(MODEL_PATH, trust_remote_codeTrue, device_mapauto).eval()model AutoModel.from_pretrained(MODEL_PATH, trust_remote_codeTrue).quantize(8).cuda()return tokenizer, model# 加载Chatglm3的model和tokenizer tokenizer, model get_model()if history not in st.session_state:st.session_state.history [] if past_key_values not in st.session_state:st.session_state.past_key_values Nonemax_length st.sidebar.slider(max_length, 0, 32768, 8192, step1) top_p st.sidebar.slider(top_p, 0.0, 1.0, 0.8, step0.01) temperature st.sidebar.slider(temperature, 0.0, 1.0, 0.6, step0.01)buttonClean st.sidebar.button(清理会话历史, keyclean) if buttonClean:st.session_state.history []st.session_state.past_key_values Noneif torch.cuda.is_available():torch.cuda.empty_cache()st.rerun()for i, message in enumerate(st.session_state.history):if message[role] user:with st.chat_message(nameuser, avataruser):st.markdown(message[content])else:with st.chat_message(nameassistant, avatarassistant):st.markdown(message[content])with st.chat_message(nameuser, avataruser):input_placeholder st.empty() with st.chat_message(nameassistant, avatarassistant):message_placeholder st.empty()prompt_text st.chat_input(请输入您的问题) if prompt_text:input_placeholder.markdown(prompt_text)history st.session_state.historypast_key_values st.session_state.past_key_valuesfor response, history, past_key_values in model.stream_chat(tokenizer,prompt_text,history,past_key_valuespast_key_values,max_lengthmax_length,top_ptop_p,temperaturetemperature,return_past_key_valuesTrue,):message_placeholder.markdown(response)st.session_state.history historyst.session_state.past_key_values past_key_values运行这个代码 streamlit run web_demo_streamlit.py (venv) PS D:\ChatGLM3 cd .\basic_demo\ (venv) PS D:\ChatGLM3\basic_demo streamlit run web_demo_streamlit.py You can now view your Streamlit app in your browser. Local URL: http://localhost:8501   Network URL: http://10.10.10.251:8501   会出现一个网页注代码中模型均已使用quantize(8).cuda()量化 另外一个web_demo_gradio.py运行起来有问题这里就不描述了运行方法同上 默认情况下模型以 FP16 精度加载运行上述代码需要大概 13GB 显存。如果你的 GPU 显存有限可以尝试以量化方式加载模型使用方法如下 model AutoModel.from_pretrained(THUDM/chatglm3-6b,trust_remote_codeTrue).quantize(4).cuda() 模型量化会带来一定的性能损失 CPU 部署 如果你没有 GPU 硬件的话也可以在 CPU 上进行推理但是推理速度会更慢。使用方法如下需要大概 32GB 内存 model AutoModel.from_pretrained(THUDM/chatglm3-6b, trust_remote_codeTrue).float() 下一步开始进行微调进入到 .\finetune_chatmodel_demo 目录 在windows下直接安装deepspeed会报错 改为 pip install deepspeed0.3.16 就没有问题了 原requirement.txt改为 由 transformers4.36.2 deepspeed datasets2.16.0 astunparse1.6.3 accelerate0.25.0 sentencepiece0.1.99 改为 transformers4.36.2 deepspeed0.3.16 datasets2.16.0 astunparse1.6.3 accelerate0.25.0 sentencepiece0.1.99 整体成功 参考文献 ChatGLM、ChatGLM2、ChatGLM3模型架构对比 - 知乎 (zhihu.com) ChatGLM2-6B、ChatGLM-6B 模型介绍及训练自己数据集,2080TI显卡全流程实战 - 知乎 (zhihu.com)
http://www.zqtcl.cn/news/444869/

相关文章:

  • h5商城网站怎么建立建设银行网站号
  • 养殖舍建设网站网站设计建设流程图
  • 麦包包的网站建设分析陕西城乡建设部网站
  • 网站测评必须做灯笼制作手工简单又漂亮
  • 购物网站建设的意义与目的wordpress 插件 加速
  • 大型html5浅蓝色网站设计公司dede模板网店怎么开店详细教程
  • 一个阿里云怎么做两个网站吗樱花16q808a
  • 如何利用服务器做网站网站建设朝阳
  • 比邻店网站开发企查查企业信息查询在线
  • 家乡网站建设策划案专业建设专题网站
  • 网站建设公司挣钱吗wordpress评论内容密码保护
  • 上海专业建站最低价网站程序模板
  • 蚌埠网站建设哪家好创客贴官网
  • php网站建设参考文献wordpress 头像 很慢
  • 大连seo网站推广phpcmsv9手机网站源码
  • 公司做推广做网站好还是俄文网站引擎
  • 上海市建设咨询协会网站asp网站源码
  • 大家都在哪些网站上做医药招商wordpress po文件
  • 国外主题网站兰州app
  • 建设项目自主验收公示网站dedecms英文外贸网站企业模板下载
  • 做网站要服务器吗前端企业网站开发
  • 用html写一个个人介绍多网站怎么做seo
  • 做网站打广告犯法吗中国建设投资集团 网站首页
  • 怎么免费申请个人网站职业技能培训有哪些
  • 小型的企业网站湖南备案网站建设方案书
  • 现在做网站公司seo怎么做教程
  • asp化妆品网站windows优化大师有必要安装吗
  • 网站流量分析系统制作图片网站
  • 做网站技术路线广州番禺发布公众号
  • 企业网站自己可以做吗服装网站建设的利益分析