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

邯郸信息港征婚交友seo公司哪家

邯郸信息港征婚交友,seo公司哪家,小程序开发平台的设计是实现,宁波网站建设reference Github: https://github.com/InternLM/tutorial/blob/main/helloworld/hello_world.md 1- 环境配置 之前都是用科学上网在huggingFace进行的模型下载#xff0c;同时还需要进行一些配置 import os os.environ[CURL_CA_BUNDLE] 在本次的学习中发现可以设置镜像或…reference Github: https://github.com/InternLM/tutorial/blob/main/helloworld/hello_world.md 1- 环境配置 之前都是用科学上网在huggingFace进行的模型下载同时还需要进行一些配置 import os os.environ[CURL_CA_BUNDLE] 在本次的学习中发现可以设置镜像或者是通过modelscope(pip install modelscope)进行下载 # huggingface-下载 ## 安装依赖: pip install -U huggingface_hub ## 直接设置环境变量: export HF_ENDPOINThttps://hf-mirror.com import os from huggingface_hub import hf_hub_download hf_hub_download(repo_idinternlm/internlm-7b, filenameconfig.json)# modelscope 下载 import torch from modelscope import snapshot_download, AutoModel, AutoTokenizer import os model_dir snapshot_download(Shanghai_AI_Laboratory/internlm-chat-7b, cache_dir/root/model, revisionv1.0.3) 下载完之后可以直接用transformers 无缝衔接 import torch from transformers import AutoModelForCausalLM, AutoTokenizerdownload_dir xxx/internlm-chat-7bmodel (AutoModelForCausalLM.from_pretrained(download_dir, trust_remote_codeTrue).to(torch.bfloat16).cuda()) tokenizer AutoTokenizer.from_pretrained(download_dir, trust_remote_codeTrue)同时补齐了信息差知道了国内镜像合集网址:MirrorZ Help 2- InterLM-Chat-7B Demo尝试 主要的项目GitHub: https://github.com/InternLM/InternLM 2.1 终端demo 其实进行demo尝试相对比较简单主要是模型下载和GPU显存(20G : 1/4的A100-80G)的限制比较大。只用transformers.AutoModelForCausalLM加载进行尝试就行。 import torch from transformers import AutoTokenizer, AutoModelForCausalLMmodel_name_or_path /root/model/Shanghai_AI_Laboratory/internlm-chat-7b tokenizer AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_codeTrue) model AutoModelForCausalLM.from_pretrained(model_name_or_path, trust_remote_codeTrue, torch_dtypetorch.bfloat16, device_mapauto) model model.eval()system_prompt You are an AI assistant whose name is InternLM (书生·浦语). - InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless. - InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文. messages [(system_prompt, )]print(Welcome to InternLM chatbot, type exit to exit.)while True:input_text input(User )input_text input_text.replace( , )if input_text exit:breakresponse, history model.chat(tokenizer, input_text, historymessages)messages.append((input_text, response))print(frobot {response})2.2 web demo 进行web demo主要是对终端demo进行一层streamlit的封装同时通过ssh将端口映射到本地资源占用的时服务器的资源。 从教程中学习到了st.cache_resource装饰器的用法这个在笔者之前的streamlit项目中没有用到过, 后续可以在自己项目中尝试用在保持database的连接上。 st.cache_resource def load_model():model (AutoModelForCausalLM.from_pretrained(internlm/internlm-chat-7b, trust_remote_codeTrue).to(torch.bfloat16).cuda())tokenizer AutoTokenizer.from_pretrained(internlm/internlm-chat-7b, trust_remote_codeTrue)return model, tokenizer3- Lagent 智能体工具调用 Demo尝试 主要的项目GitHub: https://github.com/InternLM/lagent 在第一节中已经了解到大模型的局限性需要Agent去引导优化, 这次demo尝试加深了对这个句话的理解。 在本次Demo中调用lagent去解决数学问题 已知 2x310求x ,此时 InternLM-Chat-7B 模型理解题意生成解此题的 Python 代码Lagent 调度送入 Python 代码解释器求出该问题的解。 主要步骤如下 模型初始化init_model(基于选择的name) model HFTransformerCasualLM(/root/model/Shanghai_AI_Laboratory/internlm-chat-7b) 构建lagent initialize_chatbot chatbot ReAct(llmmodel, action_executorActionExecutor(actionsPythonInterpreter())) 用户输入调用chatbot agent_return chatbot.chat(user_input) 解析返回结果并展示最后保存历史信息 render_assistant(agent_return)action解析展示如下 def render_assistant(self, agent_return):with st.chat_message(assistant):for action in agent_return.actions:if (action):self.render_action(action)st.markdown(agent_return.response)def render_action(self, action):with st.expander(action.type, expandedTrue):st.markdown(p styletext-align: left;display:flex; span stylefont-size:14px;font-weight:600;width:70px;text-align-last: justify;插 件/spanspan stylewidth:14px;text-align:left;display:block;:/spanspan styleflex:1; # noqa E501 action.type /span/p,unsafe_allow_htmlTrue)st.markdown(p styletext-align: left;display:flex; span stylefont-size:14px;font-weight:600;width:70px;text-align-last: justify;思考步骤/spanspan stylewidth:14px;text-align:left;display:block;:/spanspan styleflex:1; # noqa E501 action.thought /span/p,unsafe_allow_htmlTrue)if (isinstance(action.args, dict) and text in action.args):st.markdown(p styletext-align: left;display:flex;span stylefont-size:14px;font-weight:600;width:70px;text-align-last: justify; 执行内容/spanspan stylewidth:14px;text-align:left;display:block;:/span/p, # noqa E501unsafe_allow_htmlTrue)st.markdown(action.args[text])self.render_action_results(action)def render_action_results(self, action):Render the results of action, including text, images, videos, andaudios.if (isinstance(action.result, dict)):st.markdown(p styletext-align: left;display:flex;span stylefont-size:14px;font-weight:600;width:70px;text-align-last: justify; 执行结果/spanspan stylewidth:14px;text-align:left;display:block;:/span/p, # noqa E501unsafe_allow_htmlTrue)if text in action.result:st.markdown(p styletext-align: left; action.result[text] /p,unsafe_allow_htmlTrue)if image in action.result:image_path action.result[image]image_data open(image_path, rb).read()st.image(image_data, captionGenerated Image)if video in action.result:video_data action.result[video]video_data open(video_data, rb).read()st.video(video_data)if audio in action.result:audio_data action.result[audio]audio_data open(audio_data, rb).read()st.audio(audio_data)简单的代码可以如下 from lagent.actions import ActionExecutor, GoogleSearch, PythonInterpreter from lagent.agents.react import ReAct from lagent.llms import GPTAPI from lagent.llms.huggingface import HFTransformerCasualLM# init_model model HFTransformerCasualLM(/root/model/Shanghai_AI_Laboratory/internlm-chat-7b)# initialize_chatbot chatbot ReAct(llmmodel, action_executorActionExecutor(actionsPythonInterpreter())) agent_return chatbot.chat(user_input)4- 浦语·灵笔图文理解创作 Demo尝试 主要的项目GitHub: https://github.com/InternLM/InternLM-XComposer 这里的模型也是不一样: InternLM-XComposer是基于InternLM研发的视觉-语言大模型 InternLM-XComposer是提供出色的图文理解和创作能力具有多项优势 图文交错创作: InternLM-XComposer可以为用户打造图文并貌的专属文章。这一能力由以下步骤实现 理解用户指令创作符合要求的长文章。智能分析文章自动规划插图的理想位置确定图像内容需求。多层次智能筛选从图库中锁定最完美的图片。 基于丰富多模态知识的图文理解: InternLM-XComposer设计了高效的训练策略为模型注入海量的多模态概念和知识数据赋予其强大的图文理解和对话能力。 杰出性能: InternLM-XComposer在多项视觉语言大模型的主流评测上均取得了最佳性能包括MME Benchmark (英文评测), MMBench (英文评测), Seed-Bench (英文评测), CCBench(中文评测), MMBench-CN (中文评测). 4.1 生成文章 模型和token初始化模型调用 快速使用的话可以直接llm_model.generate进行复杂的一些操作可以 llm_model.internlm_model.generate 细节看笔者简单修改的generate函数 核心示例code: import torch from transformers import StoppingCriteriaList, AutoTokenizer, AutoModel from examples.utils import auto_configure_device_mapclass StoppingCriteriaSub(StoppingCriteria):def __init__(self, stops[], encounters1):super().__init__()self.stops stopsdef __call__(self, input_ids: torch.LongTensor, scores: torch.FloatTensor):for stop in self.stops:if torch.all((stop input_ids[:, -len(stop):])).item():return Truereturn Falsefolder internlm/internlm-xcomposer-7b device cuda# 1- init model and tokenizer llm_model AutoModel.from_pretrained(folder, trust_remote_codeTrue).cuda().eval() if args.num_gpus 1:from accelerate import dispatch_modeldevice_map auto_configure_device_map(args.num_gpus)model dispatch_model(model, device_mapdevice_map)tokenizer AutoTokenizer.from_pretrained(folder, trust_remote_codeTrue) llm_model.internlm_tokenizer tokenizer llm_model.tokenizer tokenizer# 2 封装generate def generate(llm_model, text, random, beam, max_length, repetition, use_inputsFalse):生成文章封装llm_model: AutoModel.from_pretrained 加载的 internlm/internlm-xcomposer-7brandom: 采样beam: beam search 数量max_length: 文章最大长度repetition: repetition_penaltydevice cuda# stop critriastop_words_ids [torch.tensor([103027]).to(device), torch.tensor([103028]).to(device), ]stopping_criteria StoppingCriteriaList([StoppingCriteriaSub(stopsstop_words_ids)])# 输入tokensinput_tokens llm_model.internlm_tokenizer(text, return_tensorspt,add_special_tokensTrue).to(llm_model.device)# 输入生成图像的embedsimg_embeds llm_model.internlm_model.model.embed_tokens(input_tokens.input_ids)inputs input_tokens.input_ids if use_inputs else None# 模型推理with torch.no_grad():with llm_model.maybe_autocast():outputs llm_model.internlm_model.generate(inputsinputs,inputs_embedsimg_embeds, # 生成配图stopping_criteriastopping_criteria,do_samplerandom,num_beamsbeam,max_lengthmax_length,repetition_penaltyfloat(repetition),)# decode及输出output_text llm_model.internlm_tokenizer.decode(outputs[0][1:], add_special_tokensFalse)output_text output_text.split(TOKENS_UNUSED_1)[0]return output_text# 调用 ## 生成小文章 text 请介绍下爱因斯坦的生平 - 直接调用: response llm_model.generate(text) print(fUser: {text}) print(fBot: {response}) - 封装调用: generate(llm_model, text,randomFalse,beam3,max_length300,repetition5.,use_inputsTrue ) 4.2 多模态对话 主要用 gradio 搭建web(可以阅读【知乎 Gradio轻松实现AI算法可视化部署】) 模型和token初始化模型调用 快速使用的话可以直接llm_model.chat(texttext, imageimage, historyNone)进行复杂的一些操作可以 llm_model.internlm_model.generate 这部分embeding比较复杂(笔者梳理的chat_answer示意了主要流程但还是存在bug) import torch from transformers import StoppingCriteriaList, AutoTokenizer, AutoModel from examples.utils import auto_configure_device_map# 模型初始化同上 state CONV_VISION_7132_v2.copy() def chat_answer(llm_model, state, text, image):state: 起到history的作用text: 输入的提问内容image: 图片# image 需要读取# image gr.State()device cuda# stop critriastop_words_ids [torch.tensor([103027]).to(device), torch.tensor([103028]).to(device), ]stopping_criteria StoppingCriteriaList([StoppingCriteriaSub(stopsstop_words_ids)])# 输入处理img_list []state.append_message(state.roles[0], text)with torch.no_grad():image_pt llm_model.vis_processor(image).unsqueeze(0).to(0)image_emb llm_model.encode_img(image_pt)img_list.append(image_emb)# 生成内容的embeddingprompt state.get_prompt()prompt_segs prompt.split(ImgImageHere/Img)seg_tokens [llm_model.internlm_tokenizer(seg, return_tensorspt, add_special_tokensi 0).to(device).input_idsfor i, seg in enumerate(prompt_segs)]seg_embs [llm_model.internlm_model.model.embed_tokens(seg_t) for seg_t in seg_tokens]mixed_embs [emb for pair in zip(seg_embs[:-1], img_list) for emb in pair] [seg_embs[-1]]mixed_embs torch.cat(mixed_embs, dim1)embs mixed_embs# 模型推理outputs llm_model.internlm_model.generate(inputs_embedsembs,max_new_tokens300,stopping_criteriastopping_criteria,num_beams3,#temperaturefloat(temperature),do_sampleFalse,repetition_penaltyfloat(0.5),bos_token_idllm_model.internlm_tokenizer.bos_token_id,eos_token_idllm_model.internlm_tokenizer.eos_token_id,pad_token_idllm_model.internlm_tokenizer.pad_token_id,)# decode输出output_token outputs[0]if output_token[0] 0:output_token output_token[1:]output_text llm_model.internlm_tokenizer.decode(output_token, add_special_tokensFalse)print(output_text)output_text output_text.split(TOKENS_UNUSED_1)[0] # remove the stop sign ###output_text output_text.split(Assistant:)[-1].strip()output_text output_text.replace(s, )return output_text # 图文对话 ## 1st return image examples/images/aiyinsitan.jpg text 图片里面的是谁 - 直接调用: response, history llm_model.chat(texttext, imageimage, historyNone) print(fUser: {text}) print(fBot: {response}) - 封装调用: output_text chat_answer(llm_model, state, text, image)## 2nd turn text 他有哪些成就? - 直接调用: response, history llm_model.chat(texttext, imageNone, historyhistory) print(fUser: {text}) print(fBot: {response}) - 封装调用: output_text chat_answer(llm_model, state, text, image)
文章转载自:
http://www.morning.gqbtw.cn.gov.cn.gqbtw.cn
http://www.morning.sfnr.cn.gov.cn.sfnr.cn
http://www.morning.gmgnp.cn.gov.cn.gmgnp.cn
http://www.morning.nbsbn.cn.gov.cn.nbsbn.cn
http://www.morning.ryxgk.cn.gov.cn.ryxgk.cn
http://www.morning.xmwdt.cn.gov.cn.xmwdt.cn
http://www.morning.fhqdb.cn.gov.cn.fhqdb.cn
http://www.morning.zwzwn.cn.gov.cn.zwzwn.cn
http://www.morning.lqchz.cn.gov.cn.lqchz.cn
http://www.morning.kpnpd.cn.gov.cn.kpnpd.cn
http://www.morning.xkjrq.cn.gov.cn.xkjrq.cn
http://www.morning.kwnbd.cn.gov.cn.kwnbd.cn
http://www.morning.kwnnx.cn.gov.cn.kwnnx.cn
http://www.morning.fnlnp.cn.gov.cn.fnlnp.cn
http://www.morning.ntqgz.cn.gov.cn.ntqgz.cn
http://www.morning.pkrtz.cn.gov.cn.pkrtz.cn
http://www.morning.qshxh.cn.gov.cn.qshxh.cn
http://www.morning.rrcxs.cn.gov.cn.rrcxs.cn
http://www.morning.hrpmt.cn.gov.cn.hrpmt.cn
http://www.morning.sbwr.cn.gov.cn.sbwr.cn
http://www.morning.nxhjg.cn.gov.cn.nxhjg.cn
http://www.morning.sbwr.cn.gov.cn.sbwr.cn
http://www.morning.wrcgy.cn.gov.cn.wrcgy.cn
http://www.morning.lrylj.cn.gov.cn.lrylj.cn
http://www.morning.smmby.cn.gov.cn.smmby.cn
http://www.morning.pmptm.cn.gov.cn.pmptm.cn
http://www.morning.rxrw.cn.gov.cn.rxrw.cn
http://www.morning.drnfc.cn.gov.cn.drnfc.cn
http://www.morning.tpbhf.cn.gov.cn.tpbhf.cn
http://www.morning.hxljc.cn.gov.cn.hxljc.cn
http://www.morning.ppwdh.cn.gov.cn.ppwdh.cn
http://www.morning.zgnng.cn.gov.cn.zgnng.cn
http://www.morning.syynx.cn.gov.cn.syynx.cn
http://www.morning.swkzr.cn.gov.cn.swkzr.cn
http://www.morning.tqrjj.cn.gov.cn.tqrjj.cn
http://www.morning.fykrm.cn.gov.cn.fykrm.cn
http://www.morning.kjlia.com.gov.cn.kjlia.com
http://www.morning.kdtdh.cn.gov.cn.kdtdh.cn
http://www.morning.dpnhs.cn.gov.cn.dpnhs.cn
http://www.morning.jgcxh.cn.gov.cn.jgcxh.cn
http://www.morning.fhtbk.cn.gov.cn.fhtbk.cn
http://www.morning.klwxh.cn.gov.cn.klwxh.cn
http://www.morning.fgxr.cn.gov.cn.fgxr.cn
http://www.morning.fqcdh.cn.gov.cn.fqcdh.cn
http://www.morning.dfhkh.cn.gov.cn.dfhkh.cn
http://www.morning.nzhzt.cn.gov.cn.nzhzt.cn
http://www.morning.fmry.cn.gov.cn.fmry.cn
http://www.morning.jkcpl.cn.gov.cn.jkcpl.cn
http://www.morning.xrpwk.cn.gov.cn.xrpwk.cn
http://www.morning.wqnc.cn.gov.cn.wqnc.cn
http://www.morning.mdwb.cn.gov.cn.mdwb.cn
http://www.morning.rtmqy.cn.gov.cn.rtmqy.cn
http://www.morning.nsrlb.cn.gov.cn.nsrlb.cn
http://www.morning.mcbqq.cn.gov.cn.mcbqq.cn
http://www.morning.rcfwr.cn.gov.cn.rcfwr.cn
http://www.morning.kzcz.cn.gov.cn.kzcz.cn
http://www.morning.tlfmr.cn.gov.cn.tlfmr.cn
http://www.morning.kryn.cn.gov.cn.kryn.cn
http://www.morning.fqklt.cn.gov.cn.fqklt.cn
http://www.morning.zkqjz.cn.gov.cn.zkqjz.cn
http://www.morning.lrylj.cn.gov.cn.lrylj.cn
http://www.morning.qbxdt.cn.gov.cn.qbxdt.cn
http://www.morning.nyqzz.cn.gov.cn.nyqzz.cn
http://www.morning.bfrsr.cn.gov.cn.bfrsr.cn
http://www.morning.zrks.cn.gov.cn.zrks.cn
http://www.morning.jsrnf.cn.gov.cn.jsrnf.cn
http://www.morning.kkwbw.cn.gov.cn.kkwbw.cn
http://www.morning.shprz.cn.gov.cn.shprz.cn
http://www.morning.zcxjg.cn.gov.cn.zcxjg.cn
http://www.morning.rmpkn.cn.gov.cn.rmpkn.cn
http://www.morning.dbphz.cn.gov.cn.dbphz.cn
http://www.morning.nyhtf.cn.gov.cn.nyhtf.cn
http://www.morning.fpbj.cn.gov.cn.fpbj.cn
http://www.morning.srkzd.cn.gov.cn.srkzd.cn
http://www.morning.clpfd.cn.gov.cn.clpfd.cn
http://www.morning.bojkosvit.com.gov.cn.bojkosvit.com
http://www.morning.dyzbt.cn.gov.cn.dyzbt.cn
http://www.morning.kmcfw.cn.gov.cn.kmcfw.cn
http://www.morning.rgmls.cn.gov.cn.rgmls.cn
http://www.morning.zlnkq.cn.gov.cn.zlnkq.cn
http://www.tj-hxxt.cn/news/279145.html

相关文章:

  • 360元网站建设 网络服务seo排名优化表格工具
  • 网站里宣传视频怎么做房产网上查询系统
  • 深圳集团网站建设报价济南专业做网站公司
  • 门户网站后台管理系统模板营销网站建设hanyous
  • 英文建站系统顺德网站制作案例机构
  • phpcms律师网站模板企业微信开发公司
  • 曲阜做网站哪家好珠江新城网站建设
  • 网站怎么收费wordpress默认字体改黑色
  • 哪些网站可以发布免费招聘信息江门营销网站建设
  • 设计师喜欢的几个网站服务器屏蔽网站
  • 网站可以跳转备案吗做一个中型网站需要多少钱
  • wordpress网站上传到服务器成都建站价格
  • 大型网络建站公司wordpress 缩略图判断
  • 智能营销型网站网站开发 英语
  • 手机看网站建设公司网站
  • 重庆建网站培训机构局域网网站建设
  • 如何将百度收录网站wordpress能恢复数据库吗
  • 网页设计与网站建设作业怎么做保定网站搜索排名
  • 清湖网站建设事业单位网站建设计划
  • 哪个网站可以卖自己的设计容桂电子商务网站建设
  • 学院的网站建设的意义网络规划设计师大纲
  • 什么网站做海报建设微信网站设计制作
  • 泰安网站建设哪家快网络设计报告网络安全
  • 网站显示500错误怎么解决方法导航网站能个人备案
  • 宜兴市建设局网站宝塔建站系统
  • 已经有了网站源代码怎样搭建福田祥菱m1图片及报价
  • 12306网站是谁做的wordpress 自写插件
  • 淘宝联盟怎样做新增网站推广阿里云服务器wordpress部署方案
  • 南京机关建设网站贵阳网站制作系统
  • 网站上线如何做公司名字外包开发一个app多少钱