微信扫码
添加专属顾问
我要投稿
在人工智能领域的快速发展进程中,阿里通义千问的 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。
#模型下载from modelscope import snapshot_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
# 生成文本,设置最大新生成的标记数为 512
generated_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! Artificial Intelligence (AI) refers to the simulation of human intelligence in machines that are programmed to think, learn, and perform tasks that typically require human cognition. This includes activities such as visual perception, speech recognition, decision-making, and language translation.\n\nKey components of AI include:\n\n1. **Machine Learning**: A subset of AI where systems can automatically learn and improve from experience without being explicitly programmed.\n2. **Deep Learning**: A more advanced form of machine learning that uses neural networks with many layers to model and solve complex problems.\n3. **Natural Language Processing (NLP)**: The ability of computers to understand, interpret, and generate human language.\n4. **Computer Vision**: Enabling machines to interpret and understand the visual world, similar to how humans would.\n5. **Robotics**: Combining AI with robotics to create machines that can perform tasks autonomously or semi-autonomously.\n\nAI has numerous applications across various fields, including healthcare, finance, transportation, entertainment, and more. It continues to evolve rapidly, transforming industries and societies in profound ways.'
在模型部署方面,vLLM 部署和 ollama 部署犹如两颗璀璨的明星,为开发者照亮了前行的道路。它们以其便捷性和高效性,使得 Qwen2.5 能够在各种实际场景中得以顺利应用。无论是在企业的智能化生产中,还是在科研机构的创新研究里,亦或是在日常生活的智能服务中,Qwen2.5 都能借助这些优秀的部署方式发挥出巨大的价值。
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费场景POC验证,效果验证后签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2025-04-27
用AI做测试 - 介绍大模型LLaMa与Hugging Face
2025-04-27
不到100行代码,实现一个简易通用智能LLM Agent
2025-04-27
看不懂GitHub代码?刚刚这个AI工具让全球每个GitHub项目开口说话
2025-04-27
使用MCP构建?注意安全漏洞
2025-04-27
开源大模型工具全景图!Hugging Face、OlmOCR 、Dify,开发者必藏的核心工具选型指南
2025-04-27
LLaMA Factory 框架深度解析
2025-04-26
Spring AI Alibaba搭建机票助手(实战篇)
2025-04-26
我在通用Agent上的探索设计初稿
2024-07-25
2025-01-01
2025-01-21
2024-05-06
2024-09-20
2024-07-20
2024-07-11
2024-06-12
2024-08-13
2024-12-26
2025-04-21
2025-04-19
2025-04-17
2025-04-15
2025-04-13
2025-04-10
2025-04-07
2025-04-03