ข้ามไปยังเนื้อหาหลัก

ใช้ Qiskit Code Assistant ในโหมด local

เรียนรู้วิธีติดตั้ง กำหนดค่า และใช้โมเดล Qiskit Code Assistant ใดก็ได้บนเครื่องของคุณ

หมายเหตุ
  • Qiskit Code Assistant อยู่ในสถานะ preview release และอาจมีการเปลี่ยนแปลง
  • หากคุณมีความคิดเห็นหรือต้องการติดต่อทีมนักพัฒนา ใช้ ช่อง Qiskit Slack Workspace หรือ public GitHub repositories ที่เกี่ยวข้อง

วิธีที่ง่ายที่สุดในการเริ่มต้นใช้ Qiskit Code Assistant ในโหมด local คือการใช้ script ตั้งค่าอัตโนมัติสำหรับ VS Code หรือ JupyterLab extension script เหล่านี้จะติดตั้ง Ollama เพื่อรัน LLM โดยอัตโนมัติ ดาวน์โหลดโมเดลที่แนะนำ และกำหนดค่า extension ให้คุณ

การตั้งค่า VS Code extension

รันคำสั่งต่อไปนี้ใน terminal ของคุณ:

bash <(curl -fsSL https://raw.githubusercontent.com/Qiskit/qiskit-code-assistant-vscode/main/setup_local.sh)

script นี้ดำเนินการขั้นตอนต่อไปนี้:

  • ติดตั้ง Ollama (หากยังไม่ได้ติดตั้ง)
  • ดาวน์โหลดและกำหนดค่าโมเดล Qiskit Code Assistant ที่แนะนำ
  • ตั้งค่า VS Code extension ให้ทำงานกับ local deployment ของคุณ

การตั้งค่า JupyterLab extension

รันคำสั่งต่อไปนี้ใน terminal ของคุณ:

bash <(curl -fsSL https://raw.githubusercontent.com/Qiskit/qiskit-code-assistant-jupyterlab/main/setup_local.sh)

script นี้จะ:

  • ติดตั้ง Ollama (หากยังไม่ได้ติดตั้ง)
  • ดาวน์โหลดและกำหนดค่าโมเดล Qiskit Code Assistant ที่แนะนำ
  • ตั้งค่า JupyterLab extension ให้ทำงานกับ local deployment ของคุณ

โมเดลที่ใช้ได้

โมเดลปัจจุบัน

เหล่านี้คือโมเดลล่าสุดที่แนะนำสำหรับใช้กับ Qiskit Code Assistant:

  1. Qiskit/mistral-small-3.2-24b-qiskit - เปิดตัว October 2025
  2. qiskit/qwen2.5-coder-14b-qiskit - เปิดตัว June 2025
  3. qiskit/granite-3.3-8b-qiskit - เปิดตัว June 2025
  4. qiskit/granite-3.2-8b-qiskit - เปิดตัว June 2025

โมเดลรูปแบบ GGUF ได้รับการปรับแต่งสำหรับการใช้งาน local และต้องใช้ทรัพยากรการประมวลผลน้อยกว่า:

  1. mistral-small-3.2-24b-qiskit-GGUF – เปิดตัว October 2025 ฝึกด้วยข้อมูล Qiskit จนถึงเวอร์ชัน 2.1

  2. qiskit/qwen2.5-coder-14b-qiskit-GGUF – เปิดตัว June 2025 ฝึกด้วยข้อมูล Qiskit จนถึงเวอร์ชัน 2.0

  3. qiskit/granite-3.3-8b-qiskit-GGUF – เปิดตัว June 2025 ฝึกด้วยข้อมูล Qiskit จนถึงเวอร์ชัน 2.0

  4. qiskit/granite-3.2-8b-qiskit-GGUF – เปิดตัว June 2025 ฝึกด้วยข้อมูล Qiskit จนถึงเวอร์ชัน 2.0

โมเดล Qiskit Code Assistant แบบ Open Source มีให้ในรูปแบบ safetensors หรือ GGUF file format และสามารถดาวน์โหลดได้จาก Hugging Face ตามที่อธิบายด้านล่าง

เวอร์ชัน Qiskit ที่ใช้ฝึกโมเดล

โมเดล     Benchmark Metrics    วันที่เปิดตัวฝึกบน Qiskit เวอร์ชัน
 QiskitHumanEval-HardQiskitHumanEvalHumanEvalASDivMathQASciQMBPPIFEvalCrowsPairs (English)TruthfulQA (MC1 acc)  
mistral-small-3.2-24b-qiskit32.4547.0277.493.7749.6897.5064.0048.4467.0839.41January 20262.2
qwen2.5-coder-14b-qiskit25.1749.0191.464.2153.9097.0077.6049.6465.1837.82June 20252.0
granite-3.3-8b-qiskit14.5727.1562.800.4838.6693.3052.4059.7159.7539.05June 20252.0
granite-3.2-8b-qiskit9.9324.5057.320.0941.4196.3051.8060.7966.7940.51June 20252.0
granite-8b-qiskit-rc-0.1015.8938.4159.76February 20251.3
granite-8b-qiskit17.8844.3753.66November 20241.2

หมายเหตุ: โมเดลทั้งหมดที่แสดงในตาราง benchmark ได้รับการประเมินโดยใช้ system prompt ของตน ซึ่งกำหนดไว้ในโมเดล Hugging Face

โมเดลที่ deprecated แล้ว

โมเดลเหล่านี้ไม่ได้รับการดูแลอย่างต่อเนื่องอีกต่อไป แต่ยังคงใช้งานได้:

  1. qiskit/granite-8b-qiskit-rc-0.10 - เปิดตัว February 2025 (deprecated)
  2. qiskit/granite-8b-qiskit - เปิดตัว November 2024 (deprecated)

การตั้งค่าขั้นสูง

หากคุณต้องการกำหนดค่า local setup ด้วยตนเองหรือต้องการควบคุมกระบวนการติดตั้งมากขึ้น ให้ขยาย section ด้านล่าง

ดาวน์โหลดจากเว็บไซต์ Hugging Face

ทำตามขั้นตอนเหล่านี้เพื่อดาวน์โหลดโมเดลที่เกี่ยวข้องกับ Qiskit Code Assistant จากเว็บไซต์ Hugging Face:

  1. ไปที่หน้าโมเดล Qiskit ที่ต้องการบน Hugging Face
  2. ไปที่แท็บ Files and Versions และดาวน์โหลดไฟล์โมเดล safetensors หรือ GGUF
ดาวน์โหลดโดยใช้ Hugging Face CLI

ในการดาวน์โหลดโมเดล Qiskit Code Assistant ที่ใช้ได้โดยใช้ Hugging Face CLI ให้ทำตามขั้นตอนเหล่านี้:

  1. ติดตั้ง Hugging Face CLI

  2. เข้าสู่ระบบ Hugging Face account ของคุณ

    huggingface-cli login
  3. ดาวน์โหลดโมเดลที่คุณต้องการจากรายการก่อนหน้า

    huggingface-cli download <HF REPO NAME> <MODEL PATH> --local-dir <LOCAL PATH>
Deploy โมเดล Qiskit Code Assistant ใน local ด้วย Ollama ด้วยตนเอง

มีหลายวิธีในการ deploy และโต้ตอบกับโมเดล Qiskit Code Assistant ที่ดาวน์โหลดมา คู่มือนี้แสดงการใช้ Ollama ดังนี้: ด้วย Ollama application โดยใช้ Hugging Face Hub integration หรือโมเดล local หรือด้วย แพ็กเกจ llama-cpp-python

การใช้ Ollama application

Ollama application ให้วิธีแก้ปัญหาที่ง่ายในการรัน LLM ใน local ง่ายต่อการใช้งาน พร้อม CLI ที่ทำให้กระบวนการตั้งค่าทั้งหมด การจัดการโมเดล และการโต้ตอบค่อนข้างตรงไปตรงมา เหมาะสำหรับการทดลองอย่างรวดเร็วและสำหรับผู้ใช้ที่ต้องการรายละเอียดทางเทคนิคน้อยกว่า

ติดตั้ง Ollama

  1. ดาวน์โหลด Ollama application

  2. ติดตั้งไฟล์ที่ดาวน์โหลด

  3. เปิดใช้งาน Ollama application ที่ติดตั้ง

    ข้อมูล
    application ทำงานสำเร็จเมื่อไอคอน Ollama ปรากฏใน desktop menu bar คุณยังสามารถตรวจสอบว่า service ทำงานอยู่โดยไปที่ http://localhost:11434/
  4. ลอง Ollama ใน terminal ของคุณและเริ่มรันโมเดล ตัวอย่าง:

    ollama run hf.co/Qiskit/Qwen2.5-Coder-14B-Qiskit

ตั้งค่า Ollama โดยใช้ Hugging Face Hub integration

Ollama/Hugging Face Hub integration ให้วิธีโต้ตอบกับโมเดลที่โฮสต์บน Hugging Face Hub โดยไม่จำเป็นต้องสร้าง modelfile ใหม่หรือดาวน์โหลดไฟล์ GGUF หรือ safetensors ด้วยตนเอง ไฟล์ template และ params เริ่มต้นรวมอยู่ในโมเดลบน Hugging Face Hub แล้ว

  1. ตรวจสอบให้แน่ใจว่า Ollama application ทำงานอยู่

  2. ไปที่หน้าโมเดลที่ต้องการ และคัดลอก URL ตัวอย่าง https://huggingface.co/Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF

  3. จาก terminal ของคุณ รันคำสั่ง:

    ollama run hf.co/Qiskit/Qwen2.5-Coder-14B-Qiskit

คุณสามารถใช้โมเดล hf.co/Qiskit/Qwen2.5-Coder-14B-Qiskit หรือโมเดล GGUF อย่างเป็นทางการที่แนะนำอื่น ๆ hf.co/Qiskit/mistral-small-3.2-24b-qiskit-GGUF หรือ hf.co/Qiskit/granite-3.3-8b-qiskit-GGUF

ตั้งค่า Ollama ด้วยโมเดล Qiskit Code Assistant GGUF ที่ดาวน์โหลดด้วยตนเอง

หากคุณดาวน์โหลดโมเดล GGUF ด้วยตนเอง เช่น https://huggingface.co/Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF และต้องการทดลองด้วย template และ parameter ต่างกัน คุณสามารถทำตามขั้นตอนเหล่านี้เพื่อโหลดเข้า Ollama application ใน local ของคุณ

  1. สร้าง Modelfile โดยป้อนเนื้อหาต่อไปนี้ และอย่าลืมอัปเดต <PATH-TO-GGUF-FILE> เป็นเส้นทางจริงของโมเดลที่ดาวน์โหลด

    FROM <PATH-TO-GGUF-FILE>
    TEMPLATE """{{ if .System }}
    System:
    {{ .System }}

    {{ end }}{{ if .Prompt }}Question:
    {{ .Prompt }}

    {{ end }}Answer:
    ```python{{ .Response }}
    """

    PARAMETER stop "Question:"
    PARAMETER stop "Answer:"
    PARAMETER stop "System:"
    PARAMETER stop "```"

    PARAMETER temperature 0
    PARAMETER top_k 1
  2. Run the following command to create a custom model instance based on the Modelfile.

    ollama create Qwen2.5-Coder-14B-Qiskit -f ./path-to-model-file
    หมายเหตุ
    This process may take some time for Ollama to read the model file, initialize the model instance, and configure it according to the specifications provided.

Run the Qiskit Code Assistant model manually downloaded in Ollama

After the Qwen2.5-Coder-14B-Qiskit model has been set up in Ollama, run the following command to launch the model and interact with it in the terminal (in chat mode).

ollama run Qwen2.5-Coder-14B-Qiskit

Some useful commands:

  • ollama list - List models on your computer
  • ollama rm Qwen2.5-Coder-14B-Qiskit - Delete the model
  • ollama show Qwen2.5-Coder-14B-Qiskit - Show model information
  • ollama stop Qwen2.5-Coder-14B-Qiskit - Stop a model that is currently running
  • ollama ps - List which models are currently loaded
Manually deploy the Qiskit Code Assistant models in local through the llama-cpp-python package

An alternative to the Ollama application is the llama-cpp-python package, which is a Python binding for llama.cpp. It gives you more control and flexibility to run the GGUF model locally, and is ideal for users who wish to integrate the local model in their workflows and Python applications.

  1. Install llama-cpp-python
  2. Interact with the model from within your application using llama_cpp. For example:
from llama_cpp import Llama

model_path = <PATH-TO-GGUF-FILE>

model = Llama(
model_path,
seed=17,
n_ctx=10000,
n_gpu_layers=37, # to offload in gpu, but put 0 if all in cpu
)

input = 'Generate a quantum circuit with 2 qubits'
raw_pred = model(input)["choices"][0]["text"]

You can also add text generation parameters to the model to customize the inference:

generation_kwargs = {
"max_tokens": 512,
"echo": False, # Echo the prompt in the output
"top_k": 1
}

raw_pred = model(input, **generation_kwargs)["choices"][0]["text"]
Manually deploy the Qiskit Code Assistant models in local through llama.cpp

Use the llama.cpp library

Another alternative is to use llama.cpp, an open-source library for performing LLM inference on a CPU with minimal setup. It provides low-level control over the model execution and is typically run from the command line, pointing to a local GGUF model file.

There are several ways to install llama.cpp on your machine:

Once installed, you can use llama.cpp to interact with GGUF models in conversation mode as follows:

# Use a local model file
llama-cli -m my_model.gguf -cnv

# Or download and run a model directly from Hugging Face
llama-cli -hf Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF -cnv

You can also launch an OpenAI-compatible API server for the model in the following way:

llama-server -hf Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF

Advanced parameters

With the llama-cli program, you can control the model generation using command-line options. For example, you can provide an initial “system” prompt using the -p/--prompt flag. In conversation mode (-cnv), this initial prompt acts as the system message. Otherwise, you can simply prepend any desired instruction to your prompt text. You can also adjust sampling parameters - for instance: temperature (--temp), top-k (--top-k), top-p (--top-p), repetition penalty (--repeat-penalty), and the seed to use (--seed). The following is an example invocation using these options:

llama-cli -hf Qiskit/Qwen2.5-Coder-14B-Qiskit-GGUF \
-p "You are a friendly assistant." -cnv \
--temp 0.7 \
--top-k 50 \
--top-p 0.95 \
--repeat-penalty 1.1 \
--seed 42

เพื่อให้โมเดล Qiskit ของเราทำงานได้อย่างถูกต้อง เราแนะนำให้ใช้ system prompt ที่ระบุใน HF GGUF repositories ของเรา: system prompt สำหรับ mistral-small-3.2-24b-qiskit-GGUF, Qwen2.5-Coder-14B-Qiskit-GGUF, granite-3.3-8b-qiskit-GGUF, และ granite-3.2-8b-qiskit-GGUF

เชื่อมต่อ extension กับ local deployment ด้วยตนเอง

ใช้ VS Code extension และ JupyterLab extension สำหรับ Qiskit Code Assistant เพื่อ prompt โมเดล Qiskit Code Assistant ที่ deploy ใน local เมื่อคุณตั้งค่า Ollama application กับโมเดล แล้ว คุณสามารถกำหนดค่า extension เพื่อเชื่อมต่อกับ local service ได้

เชื่อมต่อด้วย Qiskit Code Assistant VS Code extension

ด้วย Qiskit Code Assistant VS Code extension คุณสามารถโต้ตอบกับโมเดลและทำ code completion ขณะเขียนโค้ดได้ ซึ่งเหมาะสำหรับผู้ใช้ที่ต้องการความช่วยเหลือในการเขียนโค้ด Qiskit สำหรับ Python application ของตน

  1. ติดตั้ง Qiskit Code Assistant VS Code extension
  2. ใน VS Code ไปที่ User Settings และตั้งค่า Qiskit Code Assistant: Url เป็น URL ของ local Ollama deployment (ตัวอย่าง http://localhost:11434)
  3. โหลด VS Code ใหม่โดยไปที่ View > Command Palette... และเลือก Developer: Reload Window

โมเดล Qiskit Code Assistant ที่กำหนดค่าใน Ollama จะปรากฏใน status bar และพร้อมใช้งาน

เชื่อมต่อด้วย Qiskit Code Assistant JupyterLab extension

ด้วย Qiskit Code Assistant JupyterLab extension คุณสามารถโต้ตอบกับโมเดลและทำ code completion โดยตรงใน Jupyter Notebook ได้ ผู้ใช้ที่ทำงานกับ Jupyter Notebook เป็นหลักสามารถใช้ประโยชน์จาก extension นี้เพื่อเพิ่มประสิทธิภาพในการเขียนโค้ด Qiskit

  1. ติดตั้ง Qiskit Code Assistant JupyterLab extension
  2. ใน JupyterLab ไปที่ Settings Editor และตั้งค่า Qiskit Code Assistant Service API เป็น URL ของ local Ollama deployment (ตัวอย่าง http://localhost:11434)

โมเดล Qiskit Code Assistant ที่กำหนดค่าใน Ollama จะปรากฏใน status bar และพร้อมใช้งาน

Source: IBM Quantum docs — updated 24 เม.ย. 2569
English version on doQumentation — updated 7 พ.ค. 2569
This translation based on the English version of 11 มี.ค. 2569