在人工智能领域的快速发展进程中,阿里通义千问的 Qwen2.5 模型以其强大的性能和广泛的应用潜力,成为了备受关注的焦点。2024 云栖大会上的发布,更是让 Qwen2.5 走进了更多开发者和研究者的视野。本文将深入探讨 Qwen2.5 的各项技术特点和优势。
1. 预训练数据优势:Qwen2.5 全系列模型在 18t tokens 数据上进行预训练,预训练数据量大幅度增长达到了 18 万亿 tokens,超过了 meta 最新开源 llama-3.1 的 15 万亿,成为目前训练数据最多的开源模型之一。大量的数据为模型提供了更丰富的知识和更准确的理解能力。
4. 强大的语言支持:Qwen2.5 支持高达 128k 的上下文长度,可生成最多 8k 内容,并且能够丝滑响应多样化的系统提示,实现角色扮演和聊天机器人等任务。它还支持中文、英文、法文、西班牙文、俄文、日文、越南文、阿拉伯文等 29 种以上语言,具有强大的多语言能力。
在魔搭社区,开发者可以通过多种方式体验和使用Qwen2.5系列模型。可以使用ModelScope CLI、Python SDK或者git clone的方式下载模型。Qwen2.5合集的体验链接为:https://modelscope.cn/studios/qwen/Qwen2.5。此外,还有小程序体验,如看图解数学题(Qwen2 - VL + Qwen2.5 - Math)的体验链接为:https://modelscope.cn/studios/qwen/Qwen2.5 - Math - demo。
#模型下载frommodelscopeimportsnapshot_downloadmodel_dir=snapshot_download('Qwen/Qwen2.5-7B-Instruct',cache_dir='/root/autodl-tmp',revision='master')from modelscope import AutoModelForCausalLM, AutoTokenizer# 指定要加载的模型名称model_name = "/root/autodl-tmp/Qwen/Qwen2___5-7B-Instruct"# 加载因果语言模型model = AutoModelForCausalLM.from_pretrained(model_name,torch_dtype="auto",# 自动确定 PyTorch 的数据类型device_map="auto"# 自动确定设备映射)# 加载分词器tokenizer = AutoTokenizer.from_pretrained(model_name)
加载如下:
# 设置提示文本prompt = "Give me a short introduction to artificial intelligence."# 构建包含系统角色和用户角色的消息列表messages = [{"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},{"role": "user", "content": prompt}]# 将消息列表应用聊天模板进行处理,不进行分词操作且添加生成提示text = tokenizer.apply_chat_template(messages,tokenize=False,add_generation_prompt=True)text
'<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n<|im_start|>user\nGive me a short introduction to artificial intelligence.<|im_end|>\n<|im_start|>assistant\n'
#将处理后的文本转换为模型输入张量,并移动到模型所在设备上model_inputs=tokenizer([text],return_tensors="pt").to(model.device)model_inputs
# 生成文本,设置最大新生成的标记数为 512generated_ids = model.generate(**model_inputs,max_new_tokens=512)# 从生成的标记中去除输入部分的标记generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]generated_ids
#将生成的标记解码为文本,并跳过特殊标记response=tokenizer.batch_decode(generated_ids,skip_special_tokens=True)[0]response
'Certainly!ArtificialIntelligence(AI)referstothesimulationofhumanintelligenceinmachinesthatareprogrammedtothink,learn,andperformtasksthattypicallyrequirehumancognition.Thisincludesactivitiessuchasvisualperception,speechrecognition,decision-making,andlanguagetranslation.\n\nKeycomponentsofAIinclude:\n\n1.**MachineLearning**:AsubsetofAIwheresystemscanautomaticallylearnandimprovefromexperiencewithoutbeingexplicitlyprogrammed.\n2.**DeepLearning**:Amoreadvancedformofmachinelearningthatusesneuralnetworkswithmanylayerstomodelandsolvecomplexproblems.\n3.**NaturalLanguageProcessing(NLP)**:Theabilityofcomputerstounderstand,interpret,andgeneratehumanlanguage.\n4.**ComputerVision**:Enablingmachinestointerpretandunderstandthevisualworld,similartohowhumanswould.\n5.**Robotics**:CombiningAIwithroboticstocreatemachinesthatcanperformtasksautonomouslyorsemi-autonomously.\n\nAIhasnumerousapplicationsacrossvariousfields,includinghealthcare,finance,transportation,entertainment,andmore.Itcontinuestoevolverapidly,transformingindustriesandsocietiesinprofoundways.'
在模型部署方面,vLLM 部署和 ollama 部署犹如两颗璀璨的明星,为开发者照亮了前行的道路。它们以其便捷性和高效性,使得 Qwen2.5 能够在各种实际场景中得以顺利应用。无论是在企业的智能化生产中,还是在科研机构的创新研究里,亦或是在日常生活的智能服务中,Qwen2.5 都能借助这些优秀的部署方式发挥出巨大的价值。
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |