Skip to content

Latest commit

 

History

History
682 lines (571 loc) · 30.6 KB

File metadata and controls

682 lines (571 loc) · 30.6 KB

ਕੰਟੇਨਰਾਈਜ਼ਡ ਕਲਾਉਡ ਡਿਪਲੌਇਮੈਂਟ - ਪ੍ਰੋਡਕਸ਼ਨ-ਪੱਧਰੀ ਹੱਲ

ਇਹ ਵਿਸਤ੍ਰਿਤ ਟਿਊਟੋਰਿਅਲ ਮਾਈਕਰੋਸਾਫਟ ਦੇ Phi-4-mini-instruct ਮਾਡਲ ਨੂੰ ਕੰਟੇਨਰਾਈਜ਼ਡ ਵਾਤਾਵਰਣਾਂ ਵਿੱਚ ਡਿਪਲੌਇ ਕਰਨ ਲਈ ਤਿੰਨ ਮੁੱਖ ਪਹੁੰਚਾਂ ਨੂੰ ਕਵਰ ਕਰਦਾ ਹੈ: vLLM, Ollama, ਅਤੇ SLM Engine ONNX Runtime ਨਾਲ। ਇਹ 3.8B ਪੈਰਾਮੀਟਰ ਮਾਡਲ ਤਰਕਸ਼ੀਲ ਕੰਮਾਂ ਲਈ ਇੱਕ ਵਧੀਆ ਚੋਣ ਹੈ, ਜਦੋਂ ਕਿ ਐਜ ਡਿਪਲੌਇਮੈਂਟ ਲਈ ਕੁਸ਼ਲਤਾ ਨੂੰ ਬਰਕਰਾਰ ਰੱਖਦਾ ਹੈ।

ਸਮੱਗਰੀ ਦੀ ਸੂਚੀ

  1. Phi-4-mini ਕੰਟੇਨਰ ਡਿਪਲੌਇਮੈਂਟ ਦਾ ਪਰਿਚਯ
  2. ਸਿੱਖਣ ਦੇ ਉਦੇਸ਼
  3. Phi-4-mini ਵਰਗੀਕਰਨ ਨੂੰ ਸਮਝਣਾ
  4. vLLM ਕੰਟੇਨਰ ਡਿਪਲੌਇਮੈਂਟ
  5. Ollama ਕੰਟੇਨਰ ਡਿਪਲੌਇਮੈਂਟ
  6. SLM Engine ONNX Runtime ਨਾਲ
  7. ਤੁਲਨਾਤਮਕ ਫਰੇਮਵਰਕ
  8. ਸਰਵੋਤਮ ਅਭਿਆਸ

Phi-4-mini ਕੰਟੇਨਰ ਡਿਪਲੌਇਮੈਂਟ ਦਾ ਪਰਿਚਯ

ਛੋਟੇ ਭਾਸ਼ਾ ਮਾਡਲ (SLMs) EdgeAI ਵਿੱਚ ਇੱਕ ਮਹੱਤਵਪੂਰਨ ਤਰੱਕੀ ਦਾ ਪ੍ਰਤੀਕ ਹਨ, ਜੋ ਸੰਸਾਧਨ-ਸੀਮਿਤ ਡਿਵਾਈਸਾਂ 'ਤੇ ਉੱਚ-ਸੁਧਾਰਤ ਕੁਦਰਤੀ ਭਾਸ਼ਾ ਪ੍ਰੋਸੈਸਿੰਗ ਸਮਰੱਥਾਵਾਂ ਨੂੰ ਯੋਗ ਬਣਾਉਂਦੇ ਹਨ। ਇਹ ਟਿਊਟੋਰਿਅਲ ਮਾਈਕਰੋਸਾਫਟ ਦੇ Phi-4-mini-instruct ਲਈ ਕੰਟੇਨਰਾਈਜ਼ਡ ਡਿਪਲੌਇਮੈਂਟ ਰਣਨੀਤੀਆਂ 'ਤੇ ਧਿਆਨ ਕੇਂਦਰਿਤ ਕਰਦਾ ਹੈ, ਜੋ ਸਮਰੱਥਾ ਅਤੇ ਕੁਸ਼ਲਤਾ ਦੇ ਸੰਤੁਲਨ ਨਾਲ ਇੱਕ ਅਧੁਨਿਕ ਤਰਕਸ਼ੀਲ ਮਾਡਲ ਹੈ।

ਫੀਚਰਡ ਮਾਡਲ: Phi-4-mini-instruct

Phi-4-mini-instruct (3.8B ਪੈਰਾਮੀਟਰ): ਮਾਈਕਰੋਸਾਫਟ ਦਾ ਨਵਾਂ ਹਲਕਾ-ਭਾਰ ਇੰਸਟ੍ਰਕਸ਼ਨ-ਟਿਊਨਡ ਮਾਡਲ, ਜੋ ਯਾਦ/ਗਣਨਾ-ਸੀਮਿਤ ਵਾਤਾਵਰਣਾਂ ਲਈ ਡਿਜ਼ਾਈਨ ਕੀਤਾ ਗਿਆ ਹੈ, ਜਿਸ ਵਿੱਚ ਸ਼ਾਨਦਾਰ ਸਮਰੱਥਾਵਾਂ ਹਨ:

  • ਗਣਿਤੀਕ ਤਰਕ ਅਤੇ ਜਟਿਲ ਗਣਨਾਵਾਂ
  • ਕੋਡ ਜਨਰੇਸ਼ਨ, ਡੀਬੱਗਿੰਗ, ਅਤੇ ਵਿਸ਼ਲੇਸ਼ਣ
  • ਤਰਕਸ਼ੀਲ ਸਮੱਸਿਆ ਹੱਲ ਅਤੇ ਕਦਮ-ਦਰ-ਕਦਮ ਤਰਕ
  • ਵਿਆਖਿਆਵਾਂ ਦੀ ਲੋੜ ਵਾਲੇ ਸਿੱਖਿਆਕ ਅਨੁਪ੍ਰਯੋਗ
  • ਫੰਕਸ਼ਨ ਕਾਲਿੰਗ ਅਤੇ ਟੂਲ ਇੰਟੀਗ੍ਰੇਸ਼ਨ

"ਛੋਟੇ SLMs" ਸ਼੍ਰੇਣੀ (1.5B - 13.9B ਪੈਰਾਮੀਟਰ) ਦਾ ਹਿੱਸਾ, Phi-4-mini ਤਰਕਸ਼ੀਲ ਸਮਰੱਥਾ ਅਤੇ ਸੰਸਾਧਨ ਕੁਸ਼ਲਤਾ ਦੇ ਵਿਚਕਾਰ ਇੱਕ ਵਧੀਆ ਸੰਤੁਲਨ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ।

Phi-4-mini ਕੰਟੇਨਰ ਡਿਪਲੌਇਮੈਂਟ ਦੇ ਫਾਇਦੇ

  • ਚਾਲੂ ਕੁਸ਼ਲਤਾ: ਘੱਟ ਗਣਨਾਤਮਕ ਜ਼ਰੂਰਤਾਂ ਨਾਲ ਤਰਕਸ਼ੀਲ ਕੰਮਾਂ ਲਈ ਤੇਜ਼ ਇੰਫਰੈਂਸ
  • ਡਿਪਲੌਇਮੈਂਟ ਲਚਕਤਾ: ਸਥਾਨਕ ਪ੍ਰੋਸੈਸਿੰਗ ਰਾਹੀਂ ਵਧੇਰੇ ਗੋਪਨੀਯਤਾ ਦੇ ਨਾਲ ਡਿਵਾਈਸ-ਅਧਾਰਿਤ AI ਸਮਰੱਥਾਵਾਂ
  • ਲਾਗਤ ਦੀ ਕੁਸ਼ਲਤਾ: ਵੱਡੇ ਮਾਡਲਾਂ ਦੇ ਮੁਕਾਬਲੇ ਘੱਟ ਚਾਲੂ ਲਾਗਤਾਂ, ਜਦੋਂ ਕਿ ਗੁਣਵੱਤਾ ਨੂੰ ਬਰਕਰਾਰ ਰੱਖਣਾ
  • ਅਲੱਗਵਾਸਤਾ: ਮਾਡਲ ਇੰਸਟੈਂਸਾਂ ਅਤੇ ਸੁਰੱਖਿਅਤ ਕਾਰਜਕਾਰੀ ਵਾਤਾਵਰਣਾਂ ਦੇ ਵਿਚਕਾਰ ਸਾਫ ਵੱਖਰਾ
  • ਸਕੇਲਬਿਲਟੀ: ਵਧੇਰੇ ਤਰਕਸ਼ੀਲ throughput ਲਈ ਆਸਾਨ ਹੋਰਿਜ਼ੋਂਟਲ ਸਕੇਲਿੰਗ

ਸਿੱਖਣ ਦੇ ਉਦੇਸ਼

ਇਸ ਟਿਊਟੋਰਿਅਲ ਦੇ ਅੰਤ ਤੱਕ, ਤੁਸੀਂ ਯੋਗ ਹੋਵੋਗੇ:

  • ਵੱਖ-ਵੱਖ ਕੰਟੇਨਰਾਈਜ਼ਡ ਵਾਤਾਵਰਣਾਂ ਵਿੱਚ Phi-4-mini-instruct ਨੂੰ ਡਿਪਲੌਇ ਅਤੇ ਔਪਟਿਮਾਈਜ਼ ਕਰਨਾ
  • ਵੱਖ-ਵੱਖ ਡਿਪਲੌਇਮੈਂਟ ਦ੍ਰਿਸ਼ਾਂ ਲਈ ਉੱਨਤ ਮਾਤਰਾ ਅਤੇ ਸੰਕੋਚਨ ਰਣਨੀਤੀਆਂ ਨੂੰ ਲਾਗੂ ਕਰਨਾ
  • ਤਰਕਸ਼ੀਲ ਵਰਕਲੋਡ ਲਈ ਪ੍ਰੋਡਕਸ਼ਨ-ਤਿਆਰ ਕੰਟੇਨਰ ਔਰਕੇਸਟ੍ਰੇਸ਼ਨ ਨੂੰ ਸੰਰਚਿਤ ਕਰਨਾ
  • ਵਿਸ਼ੇਸ਼ ਉਪਯੋਗ ਮਾਮਲੇ ਦੀਆਂ ਜ਼ਰੂਰਤਾਂ ਦੇ ਅਧਾਰ 'ਤੇ ਉਚਿਤ ਡਿਪਲੌਇਮੈਂਟ ਫਰੇਮਵਰਕ ਦੀ ਮੂਲਾਂਕਣ ਅਤੇ ਚੋਣ ਕਰਨਾ
  • ਕੰਟੇਨਰਾਈਜ਼ਡ SLM ਡਿਪਲੌਇਮੈਂਟ ਲਈ ਸੁਰੱਖਿਆ, ਨਿਗਰਾਨੀ, ਅਤੇ ਸਕੇਲਿੰਗ ਦੇ ਸਰਵੋਤਮ ਅਭਿਆਸ ਲਾਗੂ ਕਰਨਾ

Phi-4-mini ਵਰਗੀਕਰਨ ਨੂੰ ਸਮਝਣਾ

ਮਾਡਲ ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ

ਤਕਨੀਕੀ ਵੇਰਵੇ:

  • ਪੈਰਾਮੀਟਰ: 3.8 ਬਿਲੀਅਨ (ਛੋਟੇ SLM ਸ਼੍ਰੇਣੀ)
  • ਆਰਕੀਟੈਕਚਰ: ਡੈਂਸ ਡਿਕੋਡਰ-ਕੇਵਲ ਟ੍ਰਾਂਸਫਾਰਮਰ ਗਰੁੱਪਡ-ਕੁਐਰੀ ਅਟੈਂਸ਼ਨ ਨਾਲ
  • ਸੰਦੇਸ਼ ਦੀ ਲੰਬਾਈ: 128K ਟੋਕਨ (32K ਵਧੀਆ ਪ੍ਰਦਰਸ਼ਨ ਲਈ ਸਿਫਾਰਸ਼ੀ)
  • ਸ਼ਬਦਾਵਲੀ: 200K ਟੋਕਨ ਬਹੁਭਾਸ਼ਾਈ ਸਹਾਇਤਾ ਨਾਲ
  • ਟ੍ਰੇਨਿੰਗ ਡਾਟਾ: 5T ਟੋਕਨ ਉੱਚ-ਗੁਣਵੱਤਾ ਤਰਕਸ਼ੀਲ ਸਮੱਗਰੀ ਦੇ

ਸੰਸਾਧਨ ਜ਼ਰੂਰਤਾਂ

ਡਿਪਲੌਇਮੈਂਟ ਕਿਸਮ ਘੱਟੋ-ਘੱਟ RAM ਸਿਫਾਰਸ਼ੀ RAM VRAM (GPU) ਸਟੋਰੇਜ ਆਮ ਉਪਯੋਗ ਮਾਮਲੇ
ਡਿਵੈਲਪਮੈਂਟ 6GB 8GB - 8GB ਸਥਾਨਕ ਟੈਸਟਿੰਗ, ਪ੍ਰੋਟੋਟਾਈਪਿੰਗ
ਪ੍ਰੋਡਕਸ਼ਨ CPU 8GB 12GB - 10GB ਐਜ ਸਰਵਰ, ਲਾਗਤ-ਕੁਸ਼ਲ ਡਿਪਲੌਇਮੈਂਟ
ਪ੍ਰੋਡਕਸ਼ਨ GPU 6GB 8GB 4-6GB 8GB ਉੱਚ throughput ਤਰਕਸ਼ੀਲ ਸੇਵਾਵਾਂ
ਐਜ ਔਪਟਿਮਾਈਜ਼ਡ 4GB 6GB - 6GB ਮਾਤਰਾ ਡਿਪਲੌਇਮੈਂਟ, IoT ਗੇਟਵੇ

Phi-4-mini ਸਮਰੱਥਾਵਾਂ

  • ਗਣਿਤੀਕ ਸ਼ਾਨਦਾਰਤਾ: ਉੱਚ-ਪੱਧਰੀ ਅੰਕਗਣਿਤ, ਬੀਜਗਣਿਤ, ਅਤੇ ਕੈਲਕੁਲਸ ਸਮੱਸਿਆ ਹੱਲ
  • ਕੋਡ ਇੰਟੈਲੀਜੈਂਸ: Python, JavaScript, ਅਤੇ ਬਹੁ-ਭਾਸ਼ਾ ਕੋਡ ਜਨਰੇਸ਼ਨ ਡੀਬੱਗਿੰਗ ਦੇ ਨਾਲ
  • ਤਰਕਸ਼ੀਲ ਤਰਕ: ਸਮੱਸਿਆ ਨੂੰ ਕਦਮ-ਦਰ-ਕਦਮ ਵਿਖੰਡਨ ਅਤੇ ਹੱਲ ਬਣਾਉਣਾ
  • ਸਿੱਖਿਆਕ ਸਹਾਇਤਾ: ਸਿੱਖਣ ਅਤੇ ਸਿਖਾਉਣ ਦੇ ਦ੍ਰਿਸ਼ਾਂ ਲਈ ਵਿਸਤ੍ਰਿਤ ਵਿਆਖਿਆਵਾਂ
  • ਫੰਕਸ਼ਨ ਕਾਲਿੰਗ: ਟੂਲ ਇੰਟੀਗ੍ਰੇਸ਼ਨ ਅਤੇ API ਇੰਟਰੈਕਸ਼ਨ ਲਈ ਮੂਲ ਸਹਾਇਤਾ

vLLM ਕੰਟੇਨਰ ਡਿਪਲੌਇਮੈਂਟ

vLLM Phi-4-mini-instruct ਲਈ ਸ਼ਾਨਦਾਰ ਸਹਾਇਤਾ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ, ਜਿਸ ਵਿੱਚ ਉੱਨਤ ਇੰਫਰੈਂਸ ਪ੍ਰਦਰਸ਼ਨ ਅਤੇ OpenAI-ਅਨੁਕੂਲ APIs ਹਨ, ਜੋ ਪ੍ਰੋਡਕਸ਼ਨ ਤਰਕਸ਼ੀਲ ਸੇਵਾਵਾਂ ਲਈ ਆਦਰਸ਼ ਹੈ।

ਤੁਰੰਤ ਸ਼ੁਰੂਆਤ ਉਦਾਹਰਨਾਂ

ਬੁਨਿਆਦੀ CPU ਡਿਪਲੌਇਮੈਂਟ (ਡਿਵੈਲਪਮੈਂਟ)

# CPU-optimized deployment for development and testing
docker run --name phi4-mini-dev \
  -e HUGGING_FACE_HUB_TOKEN=${HF_TOKEN} \
  -p 8000:8000 \
  --memory="8g" --cpus="4" \
  vllm/vllm-openai:latest \
  --model microsoft/Phi-4-mini-instruct \
  --max-model-len 4096 \
  --max-num-seqs 4 \
  --trust-remote-code

GPU-ਤੁਰੰਤ ਪ੍ਰੋਡਕਸ਼ਨ ਡਿਪਲੌਇਮੈਂਟ

# GPU deployment for high-performance reasoning
docker run --runtime nvidia --gpus all \
  --name phi4-mini-prod \
  -e HUGGING_FACE_HUB_TOKEN=${HF_TOKEN} \
  -p 8000:8000 \
  vllm/vllm-openai:latest \
  --model microsoft/Phi-4-mini-instruct \
  --max-model-len 8192 \
  --gpu-memory-utilization 0.8 \
  --enable-auto-tool-choice \
  --trust-remote-code

ਪ੍ਰੋਡਕਸ਼ਨ ਸੰਰਚਨਾ

version: '3.8'
services:
  phi4-mini-reasoning:
    image: vllm/vllm-openai:latest
    container_name: phi4-mini-production
    ports:
      - "8000:8000"
    volumes:
      - ~/.cache/huggingface:/root/.cache/huggingface
      - ./logs:/app/logs
    environment:
      - HUGGING_FACE_HUB_TOKEN=${HF_TOKEN}
      - CUDA_VISIBLE_DEVICES=0
    command: >
      --model microsoft/Phi-4-mini-instruct
      --host 0.0.0.0
      --port 8000
      --max-model-len 4096
      --max-num-seqs 8
      --gpu-memory-utilization 0.8
      --trust-remote-code
      --enable-auto-tool-choice
      --quantization awq
    deploy:
      resources:
        limits:
          memory: 12G
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3

Phi-4-mini ਤਰਕਸ਼ੀਲ ਸਮਰੱਥਾਵਾਂ ਦੀ ਜਾਂਚ

# Test mathematical reasoning
curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "microsoft/Phi-4-mini-instruct",
    "messages": [
      {"role": "system", "content": "You are a mathematical reasoning assistant. Show your work step by step."},
      {"role": "user", "content": "A train travels 240 km in 3 hours. If it increases its speed by 20 km/h, how long would the same journey take?"}
    ],
    "max_tokens": 200,
    "temperature": 0.3
  }'

# Test code generation
curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "microsoft/Phi-4-mini-instruct",
    "messages": [
      {"role": "user", "content": "Write a Python function to calculate the Fibonacci sequence using dynamic programming. Include comments explaining the approach."}
    ],
    "max_tokens": 300,
    "temperature": 0.5
  }'

# Test function calling capability
curl http://localhost:8000/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "microsoft/Phi-4-mini-instruct",
    "messages": [
      {"role": "user", "content": "Calculate the area of a circle with radius 5 units"}
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "calculate_circle_area",
          "description": "Calculate the area of a circle given its radius",
          "parameters": {
            "type": "object",
            "properties": {
              "radius": {"type": "number", "description": "The radius of the circle"}
            },
            "required": ["radius"]
          }
        }
      }
    ],
    "tool_choice": "auto"
  }'

Ollama ਕੰਟੇਨਰ ਡਿਪਲੌਇਮੈਂਟ

Ollama Phi-4-mini-instruct ਲਈ ਸ਼ਾਨਦਾਰ ਸਹਾਇਤਾ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ, ਜਿਸ ਵਿੱਚ ਸਧਾਰਨ ਡਿਪਲੌਇਮੈਂਟ ਅਤੇ ਪ੍ਰਬੰਧਨ ਹੈ, ਜੋ ਡਿਵੈਲਪਮੈਂਟ ਅਤੇ ਸੰਤੁਲਿਤ ਪ੍ਰੋਡਕਸ਼ਨ ਡਿਪਲੌਇਮੈਂਟ ਲਈ ਆਦਰਸ਼ ਹੈ।

ਤੁਰੰਤ ਸੈਟਅਪ

# Deploy Ollama container with GPU support
docker run -d \
  --name ollama-phi4 \
  --gpus all \
  -v ollama-data:/root/.ollama \
  -p 11434:11434 \
  --restart unless-stopped \
  ollama/ollama:latest

# Pull Phi-4-mini-instruct model
docker exec ollama-phi4 ollama pull phi4-mini

# Test mathematical reasoning
docker exec ollama-phi4 ollama run phi4-mini \
  "Solve this step by step: If compound interest on $5000 at 6% annually for 3 years, what is the final amount?"

# Test code generation
docker exec ollama-phi4 ollama run phi4-mini \
  "Write a Python function to implement binary search with detailed comments"

ਪ੍ਰੋਡਕਸ਼ਨ ਸੰਰਚਨਾ

version: '3.8'
services:
  ollama-phi4:
    image: ollama/ollama:latest
    container_name: ollama-phi4-production
    ports:
      - "11434:11434"
    volumes:
      - ollama-data:/root/.ollama
      - ./modelfiles:/modelfiles
    environment:
      - OLLAMA_HOST=0.0.0.0
      - OLLAMA_NUM_PARALLEL=4
      - OLLAMA_MAX_LOADED_MODELS=1
      - OLLAMA_FLASH_ATTENTION=1
    deploy:
      resources:
        limits:
          memory: 12G
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:11434/api/tags"]
      interval: 30s
      timeout: 10s
      retries: 3

  # Web UI for interactive reasoning tasks
  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    container_name: phi4-webui
    ports:
      - "3000:8080"
    environment:
      - OLLAMA_BASE_URL=http://ollama-phi4:11434
      - DEFAULT_MODELS=phi4-mini
    depends_on:
      - ollama-phi4
    volumes:
      - open-webui-data:/app/backend/data

volumes:
  ollama-data:
  open-webui-data:

ਮਾਡਲ ਔਪਟਿਮਾਈਜ਼ੇਸ਼ਨ ਅਤੇ ਵੈਰੀਐਂਟ

# Create reasoning-optimized variant
cat > /tmp/phi4-reasoning << EOF
FROM phi4-mini
PARAMETER temperature 0.3
PARAMETER top_p 0.8
SYSTEM """You are an expert reasoning assistant specialized in mathematics, logic, and code analysis. 
Always think step by step and show your work clearly. 
For mathematical problems, break down each calculation.
For coding problems, explain your approach and include comments."""
EOF

docker exec ollama-phi4 ollama create phi4-mini-reasoning -f /tmp/phi4-reasoning

# Create code-focused variant
cat > /tmp/phi4-coder << EOF
FROM phi4-mini
PARAMETER temperature 0.5
PARAMETER top_p 0.9
SYSTEM """You are a coding assistant specialized in writing clean, efficient, and well-documented code.
Always include detailed comments explaining your approach.
Follow best practices for the target programming language.
Provide examples and test cases when helpful."""
EOF

docker exec ollama-phi4 ollama create phi4-mini-coder -f /tmp/phi4-coder

API ਉਪਯੋਗ ਉਦਾਹਰਨਾਂ

# Mathematical reasoning via API
curl http://localhost:11434/api/generate -d '{
  "model": "phi4-mini-reasoning",
  "prompt": "A rectangle has length 15cm and width 8cm. If we increase both dimensions by 20%, what is the percentage increase in area?",
  "stream": false,
  "options": {
    "temperature": 0.3,
    "top_p": 0.8,
    "num_ctx": 4096
  }
}'

# Code generation via API
curl http://localhost:11434/api/generate -d '{
  "model": "phi4-mini-coder",
  "prompt": "Create a Python class for a binary tree with methods for insertion, deletion, and in-order traversal. Include comprehensive docstrings.",
  "stream": false,
  "options": {
    "temperature": 0.5,
    "top_p": 0.9,
    "num_ctx": 4096
  }
}'

SLM Engine ONNX Runtime ਨਾਲ

ONNX Runtime Phi-4-mini-instruct ਦੇ ਐਜ ਡਿਪਲੌਇਮੈਂਟ ਲਈ ਉੱਨਤ ਔਪਟਿਮਾਈਜ਼ੇਸ਼ਨ ਅਤੇ ਕ੍ਰਾਸ-ਪਲੇਟਫਾਰਮ ਅਨੁਕੂਲਤਾ ਨਾਲ ਸ਼ਾਨਦਾਰ ਪ੍ਰਦਰਸ਼ਨ ਪ੍ਰਦਾਨ ਕਰਦਾ ਹੈ।

ਬੁਨਿਆਦੀ ਸੈਟਅਪ

# Dockerfile for ONNX-optimized Phi-4-mini
FROM python:3.11-slim

RUN pip install --no-cache-dir \
    onnxruntime-gpu \
    optimum[onnxruntime] \
    transformers \
    fastapi \
    uvicorn

COPY app/ /app/
WORKDIR /app
EXPOSE 8080
CMD ["python", "server.py"]

ਸਧਾਰਨ ਸਰਵਰ ਅਮਲ

# app/server.py - Optimized for Phi-4-mini reasoning tasks
import os
import time
import onnxruntime as ort
from transformers import AutoTokenizer
from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI(title="Phi-4-mini ONNX Engine")

class ReasoningRequest(BaseModel):
    prompt: str
    task_type: str = "reasoning"  # reasoning, coding, math
    max_length: int = 200
    temperature: float = 0.3

class Phi4MiniEngine:
    def __init__(self):
        self.model = None
        self.tokenizer = None
        self.load_model()
    
    def load_model(self):
        model_path = "/app/models/phi4-mini-instruct.onnx"
        if os.path.exists(model_path):
            # Optimized providers for reasoning tasks
            providers = [
                ('CUDAExecutionProvider', {
                    'arena_extend_strategy': 'kSameAsRequested',
                    'cudnn_conv_algo_search': 'HEURISTIC',
                }),
                ('CPUExecutionProvider', {
                    'intra_op_num_threads': 4,
                    'inter_op_num_threads': 2,
                })
            ]
            
            self.model = ort.InferenceSession(model_path, providers=providers)
            self.tokenizer = AutoTokenizer.from_pretrained("microsoft/Phi-4-mini-instruct")
            print("✓ Phi-4-mini model loaded successfully")
        else:
            print("✗ Model file not found. Please convert the model first.")
    
    def generate_reasoning(self, request: ReasoningRequest):
        if not self.model:
            raise ValueError("Model not loaded")
        
        # Task-specific prompting for better reasoning
        task_prompts = {
            "reasoning": "Think step by step and show your reasoning clearly:",
            "math": "Solve this mathematical problem step by step:",
            "coding": "Write clean, well-commented code for this task:"
        }
        
        system_prompt = task_prompts.get(request.task_type, "")
        full_prompt = f"{system_prompt}\n{request.prompt}"
        
        # Tokenize and run inference
        inputs = self.tokenizer.encode(full_prompt, return_tensors="np", max_length=2048, truncation=True)
        
        start_time = time.time()
        outputs = self.model.run(None, {"input_ids": inputs})
        inference_time = time.time() - start_time
        
        # Decode response
        generated_text = self.tokenizer.decode(outputs[0][0], skip_special_tokens=True)
        
        return {
            "generated_text": generated_text,
            "task_type": request.task_type,
            "inference_time": inference_time,
            "model": "phi4-mini-instruct-onnx"
        }

# Initialize engine
engine = Phi4MiniEngine()

@app.post("/reasoning")
async def generate_reasoning(request: ReasoningRequest):
    try:
        return engine.generate_reasoning(request)
    except Exception as e:
        return {"error": str(e)}

@app.get("/health")
async def health():
    return {
        "status": "healthy" if engine.model else "model_not_loaded",
        "model": "phi4-mini-instruct",
        "capabilities": ["reasoning", "math", "coding"]
    }

@app.get("/")
async def root():
    return {
        "name": "Phi-4-mini ONNX Engine",
        "model": "microsoft/Phi-4-mini-instruct",
        "endpoints": ["/reasoning", "/health"],
        "capabilities": ["mathematical reasoning", "code generation", "logical problem solving"]
    }

ਮਾਡਲ ਕਨਵਰਜ਼ਨ ਸਕ੍ਰਿਪਟ

# convert_phi4_mini.py - Convert Phi-4-mini to optimized ONNX
import os
from pathlib import Path
from optimum.onnxruntime import ORTModelForCausalLM, ORTOptimizer, ORTQuantizer
from optimum.onnxruntime.configuration import AutoQuantizationConfig, AutoOptimizationConfig
from transformers import AutoTokenizer

def convert_phi4_mini():
    print("Converting Phi-4-mini-instruct to optimized ONNX...")
    
    model_name = "microsoft/Phi-4-mini-instruct"
    output_dir = Path("./models/phi4-mini-onnx")
    output_dir.mkdir(parents=True, exist_ok=True)
    
    # Step 1: Convert to ONNX
    print("Step 1: Converting to ONNX format...")
    model = ORTModelForCausalLM.from_pretrained(
        model_name,
        export=True,
        provider="CPUExecutionProvider",
        use_cache=True
    )
    
    # Step 2: Apply optimizations for reasoning tasks
    print("Step 2: Applying reasoning-specific optimizations...")
    optimization_config = AutoOptimizationConfig.with_optimization_level(
        optimization_level="O3",
        optimize_for_gpu=True,
        fp16=True
    )
    
    optimizer = ORTOptimizer.from_pretrained(model)
    optimizer.optimize(save_dir=output_dir, optimization_config=optimization_config)
    
    # Step 3: Apply quantization for edge deployment
    print("Step 3: Applying quantization...")
    quantization_config = AutoQuantizationConfig.avx512_vnni(
        is_static=False,
        per_channel=True
    )
    
    quantizer = ORTQuantizer.from_pretrained(output_dir)
    quantizer.quantize(
        save_dir=output_dir / "quantized",
        quantization_config=quantization_config
    )
    
    # Step 4: Save tokenizer
    tokenizer = AutoTokenizer.from_pretrained(model_name)
    tokenizer.save_pretrained(output_dir)
    
    # Step 5: Create final optimized model
    final_model_path = Path("./models/phi4-mini-instruct.onnx")
    quantized_files = list((output_dir / "quantized").glob("*.onnx"))
    if quantized_files:
        import shutil
        shutil.copy2(quantized_files[0], final_model_path)
        print(f"✓ Phi-4-mini converted and optimized: {final_model_path}")
    
    return final_model_path

if __name__ == "__main__":
    convert_phi4_mini()

ਪ੍ਰੋਡਕਸ਼ਨ ਸੰਰਚਨਾ

version: '3.8'
services:
  # Model conversion service (run once)
  phi4-converter:
    build: .
    container_name: phi4-converter
    volumes:
      - ./models:/app/models
      - ~/.cache/huggingface:/root/.cache/huggingface
    environment:
      - HUGGING_FACE_HUB_TOKEN=${HF_TOKEN}
    command: python convert_phi4_mini.py
    profiles: ["convert"]

  # Main reasoning engine
  phi4-onnx:
    build: .
    container_name: phi4-onnx-engine
    ports:
      - "8080:8080"
    volumes:
      - ./models:/app/models:ro
    environment:
      - LOG_LEVEL=INFO
    deploy:
      resources:
        limits:
          memory: 8G
          cpus: '4'
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
      interval: 30s
      timeout: 10s
      retries: 3

ONNX ਡਿਪਲੌਇਮੈਂਟ ਦੀ ਜਾਂਚ

# Test mathematical reasoning
curl -X POST http://localhost:8080/reasoning \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "If a car travels at 60 mph for 2.5 hours, then at 80 mph for 1.5 hours, what is the total distance traveled?",
    "task_type": "math",
    "max_length": 150,
    "temperature": 0.3
  }'

# Test code generation
curl -X POST http://localhost:8080/reasoning \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Create a Python function to find the greatest common divisor of two numbers using the Euclidean algorithm",
    "task_type": "coding",
    "max_length": 250,
    "temperature": 0.5
  }'

# Test logical reasoning
curl -X POST http://localhost:8080/reasoning \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "All cats are mammals. Some mammals are carnivores. Can we conclude that some cats are carnivores?",
    "task_type": "reasoning",
    "max_length": 200,
    "temperature": 0.3
  }'

ਤੁਲਨਾਤਮਕ ਫਰੇਮਵਰਕ

Phi-4-mini ਲਈ ਫਰੇਮਵਰਕ ਦੀ ਤੁਲਨਾ

ਫੀਚਰ vLLM Ollama ONNX Runtime
ਸੈਟਅਪ ਜਟਿਲਤਾ ਮਧ्यम ਆਸਾਨ ਜਟਿਲ
ਪ੍ਰਦਰਸ਼ਨ (GPU) ਸ਼ਾਨਦਾਰ (~25 tok/s) ਬਹੁਤ ਵਧੀਆ (~20 tok/s) ਵਧੀਆ (~15 tok/s)
ਪ੍ਰਦਰਸ਼ਨ (CPU) ਵਧੀਆ (~8 tok/s) ਬਹੁਤ ਵਧੀਆ (~12 tok/s) ਸ਼ਾਨਦਾਰ (~15 tok/s)
ਯਾਦ ਦੀ ਵਰਤੋਂ 8-12GB 6-10GB 4-8GB
API ਅਨੁਕੂਲਤਾ OpenAI ਅਨੁਕੂਲ ਕਸਟਮ REST ਕਸਟਮ FastAPI
ਫੰਕਸ਼ਨ ਕਾਲਿੰਗ ✅ ਮੂਲ ✅ ਸਹਾਇਤ ⚠️ ਕਸਟਮ ਅਮਲ
ਮਾਤਰਾ ਸਹਾਇਤਾ AWQ, GPTQ Q4_0, Q5_1, Q8_0 ONNX ਮਾਤਰਾ
ਪ੍ਰੋਡਕਸ਼ਨ ਤਿਆਰ ✅ ਸ਼ਾਨਦਾਰ ✅ ਬਹੁਤ ਵਧੀਆ ✅ ਵਧੀਆ
ਐਜ ਡਿਪਲੌਇਮੈਂਟ ਵਧੀਆ ਸ਼ਾਨਦਾਰ ਸ਼ਾਨਦਾਰ

ਵਾਧੂ ਸਰੋਤ

ਅਧਿਕਾਰਤ ਦਸਤਾਵੇਜ਼

  • ਮਾਈਕਰੋਸਾਫਟ Phi-4 ਮਾਡਲ ਕਾਰਡ: ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ ਅਤੇ ਉਪਯੋਗਤਾ ਦਿਸ਼ਾ-ਨਿਰਦੇਸ਼
  • vLLM ਦਸਤਾਵੇਜ਼: ਉੱਨਤ ਸੰਰਚਨਾ ਅਤੇ ਔਪਟਿਮਾਈਜ਼ੇਸ਼ਨ ਵਿਕਲਪ
  • Ollama ਮਾਡਲ ਲਾਇਬ੍ਰੇਰੀ: ਕਮਿਊਨਿਟੀ ਮਾਡਲ ਅਤੇ ਕਸਟਮਾਈਜ਼ੇਸ਼ਨ ਉਦਾਹਰਨਾਂ
  • ONNX Runtime ਗਾਈਡ: ਪ੍ਰਦਰਸ਼ਨ ਔਪਟਿਮਾਈਜ਼ੇਸ਼ਨ ਅਤੇ ਡਿਪਲੌਇਮੈਂਟ ਰਣਨੀਤੀਆਂ

ਡਿਵੈਲਪਮੈਂਟ ਟੂਲ

  • Hugging Face Transformers: ਮਾਡਲ ਇੰਟਰੈਕਸ਼ਨ ਅਤੇ ਕਸਟਮਾਈਜ਼ੇਸ਼ਨ ਲਈ
  • OpenAI API ਵਿਸ਼ੇਸ਼ਤਾਵਾਂ: vLLM ਅਨੁਕੂਲਤਾ ਟੈਸਟਿੰਗ ਲਈ
  • Docker ਸਰਵੋਤਮ ਅਭਿਆਸ: ਕੰਟੇਨਰ ਸੁਰੱਖਿਆ ਅਤੇ ਔਪਟਿਮਾਈਜ਼ੇਸ਼ਨ ਦਿਸ਼ਾ-ਨਿਰਦੇਸ਼
  • Kubernetes ਡਿਪਲੌਇਮੈਂਟ: ਪ੍ਰੋਡਕਸ਼ਨ ਸਕੇਲਿੰਗ ਲਈ ਔਰਕੇਸਟ੍ਰੇਸ਼ਨ ਪੈਟਰਨ

ਸਿੱਖਣ ਦੇ ਸਰੋਤ

  • SLM ਪ੍ਰਦਰਸ਼ਨ ਬੈਂਚਮਾਰਕਿੰਗ: ਤੁਲਨਾਤਮਕ ਵਿਸ਼ਲੇਸ਼ਣ ਵਿਧੀਆਂ
  • ਐਜ AI ਡਿਪਲੌਇਮੈਂਟ: ਸੰਸਾਧਨ-ਸੀਮਿਤ ਵਾਤਾਵਰਣਾਂ ਲਈ ਸਰਵੋਤਮ ਅਭਿਆਸ
  • ਤਰਕਸ਼ੀਲ ਕੰਮ ਔਪਟਿਮਾਈਜ਼ੇਸ਼ਨ: ਗਣਿਤੀਕ ਅਤੇ ਤਰਕਸ਼ੀਲ ਸਮੱਸਿਆਵਾਂ ਲਈ ਪ੍ਰੋਮਪਟਿੰਗ ਰਣਨੀਤੀਆਂ
  • ਕੰਟੇਨਰ ਸੁਰੱਖਿਆ: AI ਮਾਡਲ ਡਿਪਲੌਇਮੈਂਟ ਲਈ ਸਖ਼ਤੀ ਦੇ ਅਭਿਆਸ

ਸਿੱਖਣ ਦੇ ਨਤੀਜੇ

ਇਸ ਮੌਡਿਊਲ ਨੂੰ ਪੂਰਾ ਕਰਨ ਤੋਂ ਬਾਅਦ, ਤੁਸੀਂ ਯੋਗ ਹੋਵੋਗੇ:

  1. ਵੱਖ-ਵੱਖ ਫਰੇਮਵਰਕਾਂ ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਕੰਟੇਨਰਾਈਜ਼ਡ ਵਾਤਾਵਰਣਾਂ ਵਿੱਚ Phi-4-mini-instruct ਮਾਡਲ ਨੂੰ ਡਿਪਲੌਇ ਕਰਨਾ
  2. ਵੱਖ-ਵੱਖ ਹਾਰਡਵੇਅਰ ਵਾਤਾਵਰਣਾਂ ਲਈ SLM ਡਿਪਲੌਇਮੈਂਟ ਨੂੰ ਸੰਰਚਿਤ ਅਤੇ ਔਪਟਿਮਾਈਜ਼ ਕਰਨਾ
  3. ਕੰਟੇਨਰਾਈਜ਼ਡ AI ਡਿਪਲੌਇਮੈਂਟ ਲਈ ਸੁਰੱਖਿਆ ਦੇ ਸਰਵੋਤਮ ਅਭਿਆਸ ਲਾਗੂ ਕਰਨਾ
  4. ਵਿਸ਼ੇਸ਼ ਉਪਯੋਗ ਮਾਮਲੇ ਦੀਆਂ ਜ਼ਰੂਰਤਾਂ ਦੇ ਅਧਾਰ 'ਤੇ ਉਚਿਤ ਡਿਪਲੌਇਮੈਂਟ ਫਰੇਮਵਰਕ ਦੀ ਤੁਲਨਾ ਅਤੇ ਚੋਣ ਕਰਨਾ
  5. ਪ੍ਰੋਡਕਸ਼ਨ-ਪੱਧਰੀ SLM ਸੇਵਾਵਾਂ ਲਈ ਨਿਗਰਾਨੀ ਅਤੇ ਸਕੇਲਿੰਗ ਰਣਨੀਤੀਆਂ ਲਾਗੂ ਕਰਨਾ

ਅਗਲਾ ਕੀ ਹੈ

  • Module 1 'ਤੇ ਵਾਪਸ ਜਾਓ
  • Module 2 'ਤੇ ਵਾਪਸ ਜਾਓ

ਅਸਵੀਕਤੀ:
ਇਹ ਦਸਤਾਵੇਜ਼ AI ਅਨੁਵਾਦ ਸੇਵਾ Co-op Translator ਦੀ ਵਰਤੋਂ ਕਰਕੇ ਅਨੁਵਾਦ ਕੀਤਾ ਗਿਆ ਹੈ। ਜਦੋਂ ਕਿ ਅਸੀਂ ਸਹੀ ਹੋਣ ਦੀ ਕੋਸ਼ਿਸ਼ ਕਰਦੇ ਹਾਂ, ਕਿਰਪਾ ਕਰਕੇ ਧਿਆਨ ਦਿਓ ਕਿ ਸਵੈਚਾਲਿਤ ਅਨੁਵਾਦਾਂ ਵਿੱਚ ਗਲਤੀਆਂ ਜਾਂ ਅਸੁਚਤਤਾਵਾਂ ਹੋ ਸਕਦੀਆਂ ਹਨ। ਮੂਲ ਦਸਤਾਵੇਜ਼ ਨੂੰ ਇਸਦੀ ਮੂਲ ਭਾਸ਼ਾ ਵਿੱਚ ਅਧਿਕਾਰਤ ਸਰੋਤ ਮੰਨਿਆ ਜਾਣਾ ਚਾਹੀਦਾ ਹੈ। ਮਹੱਤਵਪੂਰਨ ਜਾਣਕਾਰੀ ਲਈ, ਪੇਸ਼ੇਵਰ ਮਨੁੱਖੀ ਅਨੁਵਾਦ ਦੀ ਸਿਫਾਰਸ਼ ਕੀਤੀ ਜਾਂਦੀ ਹੈ। ਇਸ ਅਨੁਵਾਦ ਦੀ ਵਰਤੋਂ ਤੋਂ ਪੈਦਾ ਹੋਣ ਵਾਲੇ ਕਿਸੇ ਵੀ ਗਲਤਫਹਿਮੀ ਜਾਂ ਗਲਤ ਵਿਆਖਿਆ ਲਈ ਅਸੀਂ ਜ਼ਿੰਮੇਵਾਰ ਨਹੀਂ ਹਾਂ।