Qwen
Tongyi Qianwen
Alibaba's open-source large language model. Excellent multilingual support and coding ability.
Tongyi Qianwen
Alibaba's open-source large language model. Excellent multilingual support and coding ability.
Qwen (Tongyi Qianwen) is a series of large language models developed by Alibaba Cloud. Since its first release in 2023, it has advanced rapidly, and in 2024 the Qwen2.5 series achieved top-tier performance among open-source LLMs. In particular, it supports 29 languages, including Chinese and English, and its strong understanding of Asian languages leads to excellent performance on Korean tasks as well.
The Qwen2.5 series is offered in various sizes (0.5B, 1.5B, 3B, 7B, 14B, 32B, 72B), so it can be deployed in diverse environments, from edge devices to data centers. In particular, Qwen2.5-Coder supports 92 programming languages and shows GPT-4-level performance in code generation and debugging. Qwen2.5-Math is specialized in solving math problems, and Qwen-VL is a multimodal model that processes images and text together.
Technically, Qwen2.5 uses Grouped Query Attention (GQA), the SwiGLU activation function, and RoPE positional encoding. It supports a default context length of 128K tokens, which can be extended up to 1M tokens using the YaRN technique. It is licensed under Apache 2.0, so commercial use is free, and the weights can be downloaded to run locally or fine-tune. It is easily accessible on Hugging Face, ModelScope, Ollama, and more.
Alibaba Cloud also offers Qwen models as a cloud service through the DashScope API. Its pricing is lower than OpenAI's (about 1/3 to 1/10), making it a good option for companies that need to comply with data regulations in China. It also provides the Qwen-Agent framework, which makes it easy to build AI agents capable of tool use, RAG, and code execution. In the global market, together with Llama and Mistral, it forms a three-way leading group of open-source LLMs.
Here are various ways to run Qwen models locally or call them via API:
# 1. Transformersλ‘ λ‘컬 μ€ν (GPU νμ)
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "Qwen/Qwen2.5-7B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
messages = [
{"role": "system", "content": "λΉμ μ μΉμ ν AI λΉμμ
λλ€."},
{"role": "user", "content": "νμ΄μ¬μΌλ‘ νΌλ³΄λμΉ μμ΄μ ꡬνν΄μ£ΌμΈμ."}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=512,
temperature=0.7,
do_sample=True
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
# 2. Ollamaλ‘ κ°νΈ μ€ν (μ€μΉ: ollama pull qwen2.5:7b)
import ollama
response = ollama.chat(
model='qwen2.5:7b',
messages=[
{'role': 'user', 'content': 'νκ΅μ μλλ μ΄λμΈκ°μ?'}
]
)
print(response['message']['content'])
# 3. DashScope API νΈμΆ (Alibaba Cloud)
import dashscope
from dashscope import Generation
dashscope.api_key = "your-api-key"
response = Generation.call(
model="qwen-max",
messages=[
{"role": "system", "content": "λΉμ μ μ λ¬Έ λ²μκ°μ
λλ€."},
{"role": "user", "content": "Translate to Korean: Hello, how are you?"}
],
result_format='message'
)
print(response.output.choices[0].message.content)
# 4. OpenAI νΈν API (vLLM μλ²)
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1", # vLLM μλ² μ£Όμ
api_key="not-needed"
)
response = client.chat.completions.create(
model="Qwen/Qwen2.5-7B-Instruct",
messages=[
{"role": "user", "content": "JSON νμμΌλ‘ νκ΅ λλμ 5κ°λ₯Ό μλ €μ£ΌμΈμ."}
],
response_format={"type": "json_object"}
)
print(response.choices[0].message.content)
# 5. Qwen-VL λ©ν°λͺ¨λ¬ (μ΄λ―Έμ§ + ν
μ€νΈ)
from transformers import Qwen2VLForConditionalGeneration, AutoProcessor
model = Qwen2VLForConditionalGeneration.from_pretrained(
"Qwen/Qwen2-VL-7B-Instruct",
torch_dtype="auto",
device_map="auto"
)
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-VL-7B-Instruct")
messages = [{
"role": "user",
"content": [
{"type": "image", "image": "https://example.com/image.jpg"},
{"type": "text", "text": "μ΄ μ΄λ―Έμ§λ₯Ό μ€λͺ
ν΄μ£ΌμΈμ."}
]
}]
# ... μ²λ¦¬ λ° μμ±
DashScope API Pricing (as of January 2025):
| Model | Input (1M tokens) | Output (1M tokens) | Context |
|---|---|---|---|
| Qwen-Max | $1.68 | $6.72 | 32K |
| Qwen-Plus | $0.42 | $1.26 | 128K |
| Qwen-Turbo | $0.0525 | $0.21 | 128K |
| Qwen-Long | $0.07 | $0.28 | 1M |
Self-Hosting GPU Requirements:
| Model Size | FP16 | INT8 | INT4 |
|---|---|---|---|
| Qwen2.5-7B | 16GB | 10GB | 6GB |
| Qwen2.5-14B | 32GB | 18GB | 10GB |
| Qwen2.5-72B | 160GB | 80GB | 48GB |
Tip: Compared with GPT-4o, Qwen-Plus offers similar performance at about 1/7 the price. In particular, it offers excellent cost-performance on Asian language tasks.
"Qwen2.5 is a good choice for a Korean chatbot. It has abundant Asian-language training data, so its understanding of Korean is higher than Llama's, and since it is Apache 2.0, there are no restrictions on commercial use. With a 7B model, you can serve it on a single RTX 4090."
"The strengths of Qwen2.5-Coder are its support for 92 programming languages and its fill-in-the-middle capability. On the HumanEval benchmark, the 7B model outperforms GPT-3.5-turbo, and the 32B comes close to GPT-4. It is well suited to code autocompletion and refactoring tools."
"Qwen's long-context handling is impressive. With YaRN it can be extended from 128K to 1M, and in needle-in-haystack tests it maintains high recall up to 700K. It is well suited to analyzing legal documents or entire codebases."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free