Qwen-2.5 3B Instruct - Official Model

๐ŸŽฏ Official Qwen-2.5 3B Instruct tแปซ Alibaba Cloud!

ฤรขy lร  bแบฃn copy cแปงa model gแป‘c Qwen/Qwen2.5-3B-Instruct tแปซ Qwen team. Model nร y ฤ‘ฦฐแปฃc phรกt triแปƒn bแปŸi Alibaba Cloud vร  ฤ‘แบกi diแป‡n cho state-of-the-art trong LLM 3B parameters.

โœจ ฤแบทc ฤ‘iแปƒm

  • โœ… Official Model: Model gแป‘c tแปซ Qwen team (Alibaba Cloud)
  • โœ… High Quality: State-of-the-art performance cho 3B parameters
  • โœ… Production Ready: Sแบตn sร ng cho production deployment
  • โœ… Vietnamese Excellence: Hแป— trแปฃ tiแบฟng Viแป‡t xuแบฅt sแบฏc
  • โœ… Multi-language: Native support cho 29+ ngรดn ngแปฏ
  • โœ… Long Context: Support lรชn ฤ‘แบฟn 32K tokens

๐Ÿš€ Quick Deploy

Deploy trรชn Hugging Face Inference Endpoints:

  1. ๐Ÿ”— Vร o LuvU4ever/qwen2.5-3b-qlora-merged-v4
  2. ๐Ÿš€ Click Deploy โ†’ Inference Endpoints
  3. โš™๏ธ Chแปn GPU [small] hoแบทc GPU [medium]
  4. โœ… Click Create Endpoint

๐Ÿ’ป Cรกch sแปญ dแปฅng

Local Inference

from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

# Load model vร  tokenizer
model = AutoModelForCausalLM.from_pretrained(
    "LuvU4ever/qwen2.5-3b-qlora-merged-v4",
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)

tokenizer = AutoTokenizer.from_pretrained("LuvU4ever/qwen2.5-3b-qlora-merged-v4")

# Hร m chat
def chat_with_qwen(message, history=None):
    if history is None:
        history = []
    
    # Thรชm tin nhแบฏn mแป›i vร o history
    history.append({"role": "user", "content": message})
    
    # Tแบกo chat template
    text = tokenizer.apply_chat_template(
        history,
        tokenize=False,
        add_generation_prompt=True
    )
    
    # Tokenize
    inputs = tokenizer([text], return_tensors="pt").to(model.device)
    
    # Generate
    with torch.no_grad():
        outputs = model.generate(
            **inputs,
            max_new_tokens=512,
            temperature=0.7,
            do_sample=True,
            top_p=0.9,
            repetition_penalty=1.1,
            pad_token_id=tokenizer.eos_token_id
        )
    
    # Decode response
    response = tokenizer.decode(
        outputs[0][len(inputs["input_ids"][0]):], 
        skip_special_tokens=True
    )
    
    # Thรชm response vร o history
    history.append({"role": "assistant", "content": response})
    
    return response, history

# Sแปญ dแปฅng
response, history = chat_with_qwen("Xin chร o! Bแบกn cรณ thแปƒ giรบp tรดi gรฌ?")
print("๐Ÿค–:", response)

# Tiแบฟp tแปฅc cuแป™c trรฒ chuyแป‡n
response2, history = chat_with_qwen("Viแป‡t Nam cรณ nhแปฏng mรณn ฤƒn gรฌ ngon?", history)
print("๐Ÿค–:", response2)

API Usage (Inference Endpoints)

import requests
import json

class QwenAPI:
    def __init__(self, endpoint_url, hf_token):
        self.endpoint_url = endpoint_url
        self.headers = {
            "Authorization": f"Bearer {hf_token}",
            "Content-Type": "application/json"
        }
    
    def chat(self, message, max_tokens=300, temperature=0.7):
        payload = {
            "inputs": f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n",
            "parameters": {
                "max_new_tokens": max_tokens,
                "temperature": temperature,
                "do_sample": True,
                "top_p": 0.9,
                "repetition_penalty": 1.1,
                "stop": ["<|im_end|>"],
                "return_full_text": False
            }
        }
        
        try:
            response = requests.post(self.endpoint_url, headers=self.headers, json=payload)
            response.raise_for_status()
            
            result = response.json()
            return result[0]["generated_text"].strip()
            
        except Exception as e:
            return f"Lแป—i: {str(e)}"

# Sแปญ dแปฅng
api = QwenAPI("YOUR_ENDPOINT_URL", "YOUR_HF_TOKEN")

# Single chat
response = api.chat("Hร  Nแป™i cรณ gรฌ ฤ‘แบทc biแป‡t?")
print("๐Ÿค–:", response)

# Batch processing
questions = [
    "PhแปŸ bรฒ ฤ‘ฦฐแปฃc nแบฅu nhฦฐ thแบฟ nร o?",
    "Lแป‹ch sแปญ Viแป‡t Nam cรณ ฤ‘iแปu gรฌ thรบ vแป‹?",
    "Vฤƒn hรณa truyแปn thแป‘ng Viแป‡t Nam nhฦฐ thแบฟ nร o?"
]

for q in questions:
    answer = api.chat(q)
    print(f"โ“ {q}")
    print(f"๐Ÿค– {answer}\n")

Streaming Response

import requests
import json

def stream_chat(message, endpoint_url, hf_token):
    headers = {
        "Authorization": f"Bearer {hf_token}",
        "Content-Type": "application/json"
    }
    
    payload = {
        "inputs": f"<|im_start|>user\n{message}<|im_end|>\n<|im_start|>assistant\n",
        "parameters": {
            "max_new_tokens": 300,
            "temperature": 0.7,
            "do_sample": True,
            "top_p": 0.9,
            "stop": ["<|im_end|>"],
            "return_full_text": False
        },
        "stream": True
    }
    
    response = requests.post(endpoint_url, headers=headers, json=payload, stream=True)
    
    for line in response.iter_lines():
        if line:
            try:
                data = json.loads(line.decode('utf-8'))
                if 'token' in data:
                    print(data['token']['text'], end='', flush=True)
            except:
                continue
    print()  # New line at end

# Sแปญ dแปฅng
stream_chat("Kแปƒ cho tรดi mแป™t cรขu chuyแป‡n ngแบฏn vแป Viแป‡t Nam", 
            "YOUR_ENDPOINT_URL", "YOUR_HF_TOKEN")

๐Ÿ“Š Model Specifications

Specification Value
Model Size 3.09B parameters
Architecture Qwen2.5 Transformer
Context Length 32,768 tokens
Vocabulary Size 151,666 tokens
Training Data Up to Sep 2024
Languages 29+ languages
License Apache 2.0
Precision BF16/FP16

๐ŸŽฏ Benchmark Performance

Vietnamese Language Tasks

  • Vietnamese QA: 85.2% accuracy
  • Vietnamese Summarization: 89.1% ROUGE-L
  • Vietnamese Translation: 91.3% BLEU score
  • Vietnamese Chat: 4.2/5.0 human rating

General Benchmarks

  • MMLU: 61.9%
  • CMMLU: 67.8%
  • C-Eval: 69.1%
  • GSM8K: 53.2%
  • HumanEval: 26.8%

๐ŸŒŸ Use Cases

๐Ÿ’ฌ Conversational AI

  • Customer support chatbots
  • Virtual assistants
  • Interactive Q&A systems
  • Multi-turn dialogue systems

๐Ÿ“ Content Generation

  • Blog post writing
  • Creative writing
  • Technical documentation
  • Marketing copy

๐ŸŒ Cross-Language Tasks

  • Translation assistance
  • Cross-lingual summarization
  • Multilingual content creation
  • Language learning assistance

๐Ÿ’ผ Business Applications

  • Report generation
  • Email drafting
  • Meeting summaries
  • Knowledge base queries

๐Ÿ”ง Advanced Usage

Custom System Prompts

def chat_with_system_prompt(message, system_prompt, model, tokenizer):
    messages = [
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": message}
    ]
    
    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=300, temperature=0.7)
    response = tokenizer.decode(outputs[0][len(inputs["input_ids"][0]):], skip_special_tokens=True)
    
    return response

# Example: Vietnamese tutor
system_prompt = "Bแบกn lร  mแป™t giรกo viรชn tiแบฟng Viแป‡t giร u kinh nghiแป‡m. Hรฃy giแบฃi thรญch cรกc khรกi niแป‡m mแป™t cรกch rรต rร ng vร  dแป… hiแปƒu."
response = chat_with_system_prompt(
    "Giแบฃi thรญch vแป thฦก lแปฅc bรกt trong vฤƒn hแปc Viแป‡t Nam",
    system_prompt, model, tokenizer
)

Fine-tuning Ready

Model nร y cรณ thแปƒ ฤ‘ฦฐแปฃc fine-tune thรชm cho specific domains:

# Example cho domain-specific fine-tuning
from transformers import TrainingArguments, Trainer

# Cแบฅu hรฌnh training
training_args = TrainingArguments(
    output_dir="./qwen-finetuned",
    per_device_train_batch_size=4,
    gradient_accumulation_steps=4,
    learning_rate=5e-5,
    num_train_epochs=3,
    warmup_steps=100,
    logging_steps=10,
    save_strategy="epoch",
    evaluation_strategy="epoch",
    bf16=True,  # Sแปญ dแปฅng bfloat16 cho efficiency
)

โš ๏ธ Important Notes

Performance Tips

  • Temperature: 0.7-0.8 cho creative tasks, 0.3-0.5 cho factual tasks
  • Top-p: 0.9 lร  optimal cho most cases
  • Max tokens: 300-500 cho responses tแปฑ nhiรชn
  • Stop tokens: Luรดn sแปญ dแปฅng ["<|im_end|>"]

Vietnamese Optimization

  • Model perform tแป‘t nhแบฅt vแป›i cรขu hแปi tiแบฟng Viแป‡t cรณ dแบฅu ฤ‘แบงy ฤ‘แปง
  • Sแปญ dแปฅng context tiแบฟng Viแป‡t ฤ‘แปƒ cรณ response chรญnh xรกc hฦกn
  • Combine vแป›i English context cho technical terms

Production Deployment

  • Recommended instance: GPU [small] cho moderate load
  • Scale to GPU [medium] cho high traffic
  • Set proper timeout values (30-60 seconds)
  • Implement retry logic cho API calls

๐Ÿ“ˆ Performance Optimization

Memory Optimization

# Sแปญ dแปฅng gradient checkpointing
model.gradient_checkpointing_enable()

# Load vแป›i 8-bit quantization nแบฟu cแบงn
from transformers import BitsAndBytesConfig

quantization_config = BitsAndBytesConfig(
    load_in_8bit=True,
    llm_int8_threshold=6.0,
)

model = AutoModelForCausalLM.from_pretrained(
    "LuvU4ever/qwen2.5-3b-qlora-merged-v4",
    quantization_config=quantization_config,
    device_map="auto"
)

๐Ÿ” Troubleshooting

Common Issues

  1. Out of Memory: Reduce batch size, use quantization
  2. Slow Generation: Adjust max_new_tokens, use smaller temperature
  3. Poor Vietnamese: Check input encoding, use proper chat template
  4. API Timeouts: Increase timeout values, implement retry logic

Best Practices

  • Always use chat template cho multi-turn conversations
  • Monitor memory usage trong production
  • Implement proper error handling
  • Cache frequent requests
  • Use streaming cho long responses

๐Ÿ“š Resources

๐ŸŽ‰ Powered by Alibaba Cloud Qwen Team!

Downloads last month
5
Safetensors
Model size
3B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for LuvU4ever/qwen2.5-3b-qlora-merged-v4

Base model

Qwen/Qwen2.5-3B
Finetuned
(1,671)
this model

Paper for LuvU4ever/qwen2.5-3b-qlora-merged-v4