怎么免费做网站推广,百度竞价渠道代理商,企业发展法治宣传,python网站开发 django最近这一两周看到不少互联网公司都已经开始秋招提前批了。不同以往的是#xff0c;当前职场环境已不再是那个双向奔赴时代了。求职者在变多#xff0c;HC 在变少#xff0c;岗位要求还更高了。 
最近#xff0c;我们又陆续整理了很多大厂的面试题#xff0c;帮助一些球友解…最近这一两周看到不少互联网公司都已经开始秋招提前批了。不同以往的是当前职场环境已不再是那个双向奔赴时代了。求职者在变多HC 在变少岗位要求还更高了。 
最近我们又陆续整理了很多大厂的面试题帮助一些球友解惑答疑分享技术面试中的那些弯弯绕绕。 
《大模型面试宝典》(2024版) 发布 
《AIGC 面试宝典》圈粉无数 
喜欢本文记得收藏、关注、点赞。更多实战和面试交流欢迎交流 文章目录 模型推理模型微调模型部署Llama3.1 工具调用服务实战  近日Meta正式发布Llama 3.1包含8B、70B 和405B三个规模最大上下文提升到了128k。Llama系列模型是目前开源领域中用户最多、性能最强的大型模型系列之一。 
本次Llama 3.1的要点有 
1.共有8B、70B及405B三种版本其中405B版本是目前最大的开源模型之一 
2.该模型最大参数规模达到4050亿参数在性能上超越了现有的顶级AI模型 
3.模型引入了更长的上下文窗口最长可达128K tokens能够处理更复杂的任务和对话 
4. 支持多语言输入和输出增强了模型的通用性和适用范围 
5.提高了推理能力特别是在解决复杂数学问题和即时生成内容方面表现突出。 
为大家带来的一站式模型体验、下载、推理、微调、部署实战教程 
模型推理 
以Llama-3.1-8B-Instruct为例 
import transformers
import torch
from modelscope import snapshot_downloadmodel_id  snapshot_download(LLM-Research/Meta-Llama-3.1-8B-Instruct)pipeline  transformers.pipeline(text-generation,modelmodel_id,model_kwargs{torch_dtype: torch.bfloat16},device_mapauto,
)messages  [{role: system, content: You are a pirate chatbot who always responds in pirate speak!},{role: user, content: Who are you?},
]outputs  pipeline(messages,max_new_tokens256,
)
print(outputs[0][generated_text][-1])模型微调 
我们介绍使用ms-swift对llama3_1-8b-instruct进行古文翻译腔微调并对微调前后模型进行推理。swift是魔搭社区官方提供的LLM工具箱支持300大语言模型和50多模态大模型的微调、推理、量化、评估和部署。 
在开始微调之前请确保您的环境已正确安装 
# 安装ms-swift
git clone https://github.com/modelscope/swift.git
cd swift
pip install -e .[llm]微调脚本如果出现OOM请降低max_length 
# 实验环境: 3090/A10
# 显存占用: 24GB
CUDA_VISIBLE_DEVICES0 \
swift sft \--model_type llama3_1-8b-instruct \--sft_type lora \--output_dir output \--dataset classical-chinese-translate \--num_train_epochs 1 \--max_length 2048 \--gradient_checkpointing true \--batch_size 1 \--gradient_accumulation_steps 16 \--warmup_ratio 0.1 \--eval_steps 100 \--save_steps 100 \--save_total_limit -1 \--logging_steps 10# 实验环境: 4 * 3090/A10
# 显存占用: 4 * 24GB
# DDP  ZeRO2
nproc_per_node4NPROC_PER_NODE$nproc_per_node \
CUDA_VISIBLE_DEVICES0,1,2,3 \
swift sft \--model_type llama3_1-8b-instruct \--sft_type lora \--output_dir output \--dataset classical-chinese-translate \--num_train_epochs 1 \--max_length 2048 \--gradient_checkpointing true \--batch_size 1 \--gradient_accumulation_steps $(expr 16 / $nproc_per_node) \--warmup_ratio 0.1 \--eval_steps 100 \--save_steps 100 \--save_total_limit -1 \--logging_steps 10 \--deepspeed default-zero2微调显存消耗 微调过程的loss可视化 微调后推理脚本如下这里的ckpt_dir需要修改为训练生成的last checkpoint文件夹。我们可以使用vLLM对merge后的checkpoint进行推理加速。 
pip install vllm -U  # vllm0.5.3.post1# Experimental environment: A10, 3090, V100, ...
CUDA_VISIBLE_DEVICES0 swift export \--ckpt_dir output/llama3_1-8b-instruct/vx-xxx/checkpoint-xxx \--merge_lora true# 使用vLLM进行推理加速
CUDA_VISIBLE_DEVICES0 swift infer \--ckpt_dir output/llama3_1-8b-instruct/vx-xxx/checkpoint-xxx-merged \--infer_backend vllm --max_model_len 4096微调后模型对验证集进行推理的示例 模型部署 
使用vLLM部署Llama3.1-70B-Instruct 
部署Llama3.1-70B-Instruct需要至少2卡80GiB A100 GPU部署方式如下 
服务端 
# 请确保已经安装了git-lfs
git lfs installGIT_LFS_SKIP_SMUDGE1 git clone https://www.modelscope.cn/LLM-Research/Meta-Llama-3.1-70B-Instruct.git
cd Meta-Llama-3.1-70B-Instruct
git lfs pull# 实验环境2 * A100
# local_path传入本地路径
CUDA_VISIBLE_DEVICES0,1 vllm serve local_path \--dtype bfloat16 --served-model-name llama3_1-70b-instruct \--gpu_memory_utilization 0.96 --tensor_parallel_size 2 \--max_model_len 50000# or 实验环境4 * A100
CUDA_VISIBLE_DEVICES0,1,2,3 vllm serve local_path \--dtype bfloat16 --served-model-name llama3_1-70b-instruct \--tensor_parallel_size 4客户端 
curl http://localhost:8000/v1/chat/completions \
-H Content-Type: application/json \
-d {
model: llama3_1-70b-instruct,
messages: [{role: user, content: 晚上睡不着觉怎么办}],
max_tokens: 1024,
temperature: 0
}模型输出 
{id:chat-d1b12066eedf445bbee4257a8c3a1b30,object:chat.completion,created:1721809149,model:llama3_1-70b-instruct,choices:[{index:0,message:{role:assistant,content:答如果你晚上睡不着觉可以尝试以下方法1.  保持卧室安静、黑暗和凉爽。2.  避免在睡前使用电子设备。3.  不要在睡前饮用含有咖啡因的饮料。4.  尝试放松技巧如深呼吸、冥想或瑜伽。5.  如果问题持续可以咨询医生或睡眠专家。,tool_calls:[]},logprobs:null,finish_reason:stop,stop_reason:null}],usage:{prompt_tokens:19,total_tokens:128,completion_tokens:109}}Llama3.1 工具调用服务实战 
环境准备 
Llama3.1部署依赖vllm 最新补丁版本 0.5.3.post1 
# speed up if needed
# pip config set global.index-url https://mirrors.cloud.aliyuncs.com/pypi/simple
# pip config set install.trusted-host mirrors.cloud.aliyuncs.com
pip install https://github.com/vllm-project/vllm/releases/download/v0.5.3.post1/vllm-0.5.3.post1cu118-cp310-cp310-manylinux1_x86_64.whl依赖modelscope-agent项目下的modelscope-agent-server进行tool calling能力调用 
git clone https://github.com/modelscope/modelscope-agent.git
cd modelscope-agent服务调用 
利用modelscope-agent-server的能力允许用户在本地拉起一个支持openai SDK调用的chat/completions服务并且赋予该模型tool calling 的能力。这样子可以让原本仅支持prompt调用的模型可以通过modelscope的服务快速进行tool calling的调用。 
服务curl调用 
于此同时 服务启动以后可以通过以下方式curl 使用带有tool的信息调用服务。 
curl -X POST http://localhost:31512/v1/chat/completions \
-H Content-Type: application/json \
-d {tools: [{type: function,function: {name: amap_weather,description: amap weather tool,parameters: [{name: location,type: string,description: 城市/区具体名称如北京市海淀区请描述为海淀区,required: true}]}}],tool_choice: auto,model: meta-llama/Meta-Llama-3.1-8B-Instruct,messages: [{content: 海淀区天气, role: user}]
}返回如下结果 
{request_id: chatcmpl_84a66af2-4021-4ae6-822d-8e3f42ca9f43,message: ,output: null,id: chatcmpl_84a66af2-4021-4ae6-822d-8e3f42ca9f43,choices: [{index: 0,message: {role: assistant,content: 工具调用\nAction: amap_weather\nAction Input: {\location\: \北京市\}\n,tool_calls: [{type: function,function: {name: amap_weather,arguments: {\location\: \北京市\}}}]},finish_reason: tool_calls}],created: 1721803228,model: meta-llama/Meta-Llama-3.1-8B-Instruct,system_fingerprint: chatcmpl_84a66af2-4021-4ae6-822d-8e3f42ca9f43,object: chat.completion,usage: {prompt_tokens: -1,completion_tokens: -1,total_tokens: -1}
}
 文章转载自: http://www.morning.fqtdz.cn.gov.cn.fqtdz.cn http://www.morning.kvzvoew.cn.gov.cn.kvzvoew.cn http://www.morning.qnqt.cn.gov.cn.qnqt.cn http://www.morning.sxmbk.cn.gov.cn.sxmbk.cn http://www.morning.gcspr.cn.gov.cn.gcspr.cn http://www.morning.qyllw.cn.gov.cn.qyllw.cn http://www.morning.pghry.cn.gov.cn.pghry.cn http://www.morning.fslrx.cn.gov.cn.fslrx.cn http://www.morning.gmrxh.cn.gov.cn.gmrxh.cn http://www.morning.tqpds.cn.gov.cn.tqpds.cn http://www.morning.enjoinfo.cn.gov.cn.enjoinfo.cn http://www.morning.mkfhx.cn.gov.cn.mkfhx.cn http://www.morning.xfxlr.cn.gov.cn.xfxlr.cn http://www.morning.cjwkf.cn.gov.cn.cjwkf.cn http://www.morning.wjjxr.cn.gov.cn.wjjxr.cn http://www.morning.wsxxq.cn.gov.cn.wsxxq.cn http://www.morning.zyytn.cn.gov.cn.zyytn.cn http://www.morning.ghcfx.cn.gov.cn.ghcfx.cn http://www.morning.ylklr.cn.gov.cn.ylklr.cn http://www.morning.rwfp.cn.gov.cn.rwfp.cn http://www.morning.rgfx.cn.gov.cn.rgfx.cn http://www.morning.dpnhs.cn.gov.cn.dpnhs.cn http://www.morning.tgdys.cn.gov.cn.tgdys.cn http://www.morning.sacxbs.cn.gov.cn.sacxbs.cn http://www.morning.kxqfz.cn.gov.cn.kxqfz.cn http://www.morning.lmqw.cn.gov.cn.lmqw.cn http://www.morning.xxlz.cn.gov.cn.xxlz.cn http://www.morning.zbqry.cn.gov.cn.zbqry.cn http://www.morning.dblfl.cn.gov.cn.dblfl.cn http://www.morning.bpmnx.cn.gov.cn.bpmnx.cn http://www.morning.ljxxl.cn.gov.cn.ljxxl.cn http://www.morning.jrqbr.cn.gov.cn.jrqbr.cn http://www.morning.sqhlx.cn.gov.cn.sqhlx.cn http://www.morning.nclps.cn.gov.cn.nclps.cn http://www.morning.dbylp.cn.gov.cn.dbylp.cn http://www.morning.wbrf.cn.gov.cn.wbrf.cn http://www.morning.yrddl.cn.gov.cn.yrddl.cn http://www.morning.kzslk.cn.gov.cn.kzslk.cn http://www.morning.yjxfj.cn.gov.cn.yjxfj.cn http://www.morning.fglxh.cn.gov.cn.fglxh.cn http://www.morning.tnqk.cn.gov.cn.tnqk.cn http://www.morning.lxcwh.cn.gov.cn.lxcwh.cn http://www.morning.bqhlp.cn.gov.cn.bqhlp.cn http://www.morning.ttrdr.cn.gov.cn.ttrdr.cn http://www.morning.kfysh.com.gov.cn.kfysh.com http://www.morning.sjwws.cn.gov.cn.sjwws.cn http://www.morning.kmbgl.cn.gov.cn.kmbgl.cn http://www.morning.kxqwg.cn.gov.cn.kxqwg.cn http://www.morning.nmkfy.cn.gov.cn.nmkfy.cn http://www.morning.jcfdk.cn.gov.cn.jcfdk.cn http://www.morning.fllfz.cn.gov.cn.fllfz.cn http://www.morning.pffqh.cn.gov.cn.pffqh.cn http://www.morning.mqss.cn.gov.cn.mqss.cn http://www.morning.bfjtp.cn.gov.cn.bfjtp.cn http://www.morning.fpqsd.cn.gov.cn.fpqsd.cn http://www.morning.yrfxb.cn.gov.cn.yrfxb.cn http://www.morning.pwhjr.cn.gov.cn.pwhjr.cn http://www.morning.fnfxp.cn.gov.cn.fnfxp.cn http://www.morning.hxxzp.cn.gov.cn.hxxzp.cn http://www.morning.knrgb.cn.gov.cn.knrgb.cn http://www.morning.pynzj.cn.gov.cn.pynzj.cn http://www.morning.xqqcq.cn.gov.cn.xqqcq.cn http://www.morning.kwjyt.cn.gov.cn.kwjyt.cn http://www.morning.lqznq.cn.gov.cn.lqznq.cn http://www.morning.qmzhy.cn.gov.cn.qmzhy.cn http://www.morning.gjsjt.cn.gov.cn.gjsjt.cn http://www.morning.wgkz.cn.gov.cn.wgkz.cn http://www.morning.nkllb.cn.gov.cn.nkllb.cn http://www.morning.baohum.com.gov.cn.baohum.com http://www.morning.zxzgr.cn.gov.cn.zxzgr.cn http://www.morning.kjyfq.cn.gov.cn.kjyfq.cn http://www.morning.rgmls.cn.gov.cn.rgmls.cn http://www.morning.ljhnn.cn.gov.cn.ljhnn.cn http://www.morning.xflzm.cn.gov.cn.xflzm.cn http://www.morning.flqkp.cn.gov.cn.flqkp.cn http://www.morning.ybhjs.cn.gov.cn.ybhjs.cn http://www.morning.mtktn.cn.gov.cn.mtktn.cn http://www.morning.dskmq.cn.gov.cn.dskmq.cn http://www.morning.prsxj.cn.gov.cn.prsxj.cn http://www.morning.npcxk.cn.gov.cn.npcxk.cn