Menyesuaikan model terbuka

Halaman ini menjelaskan cara melakukan penyesuaian terawasi pada model terbuka seperti Llama 3.1.

Mode penyesuaian yang didukung

  • Penyesuaian penuh

  • Low-Rank Adaptation (LoRA): LoRA adalah mode penyesuaian yang efisien secara parameter yang hanya menyesuaikan subset parameter. Hal ini lebih hemat biaya dan memerlukan lebih sedikit data pelatihan dibandingkan penyesuaian penuh. Di sisi lain, penyesuaian menyeluruh memiliki potensi kualitas yang lebih tinggi dengan menyesuaikan semua parameter.

Model yang didukung

  • Gemma 3 1B IT (google/gemma3@gemma-3-1b-it)
  • Gemma 3 4B IT (google/gemma3@gemma-3-4b-it)
  • Gemma 3 12B IT (google/gemma3@gemma-3-12b-it)
  • Gemma 3 27B IT (google/gemma3@gemma-3-27b-it)
  • Llama 3.1 8B (meta/llama3_1@llama-3.1-8b)
  • Llama 3.1 8B Instruct (meta/llama3_1@llama-3.1-8b-instruct)
  • Llama 3.2 1B Instruct (meta/llama3-2@llama-3.2-1b-instruct)
  • Llama 3.2 3B Instruct (meta/llama3-2@llama-3.2-3b-instruct)
  • Llama 3.3 70B Instruct (meta/llama3-3@llama-3.3-70b-instruct)
  • Qwen 3 4B (qwen/qwen3@qwen3-4b)
  • Qwen 3 8B (qwen/qwen3@qwen3-8b)
  • Qwen 3 14B (qwen/qwen3@qwen3-14b)
  • Qwen 3 32B (qwen/qwen3@qwen3-32b)
  • Llama 4 Scout 17B 16E Instruct (meta/llama4@llama-4-scout-17b-16e-instruct)

Region yang didukung

  • Iowa (us-central1)
  • Belanda (europe-west4)
  • Oregon (us-west1)
  • Columbus (us-east5)
  • Singapura (asia-southeast1)

Batasan

Model Spesifikasi Nilai
Gemma 3 1B IT Mode penyetelan Penyesuaian penuh
Panjang urutan maksimum 8192
Modalities Teks
Gemma 3 4B IT Mode penyetelan Penyesuaian penuh
Panjang urutan maksimum 8192
Modalities Teks
Gemma 3 12B IT Mode penyetelan Penyesuaian penuh
Panjang urutan maksimum 8192
Modalities Teks
Gemma 3 27B IT Mode penyetelan Parameter-efficient fine-tuning
Fine-tuning penuh
Panjang urutan maksimum 8192
Modalities Teks
Llama 3.1 8B Mode penyetelan Parameter-efficient fine-tuning
Fine-tuning penuh
Panjang urutan maksimum 8192
Modalities Teks
Llama 3.1 8B Instruct Mode penyetelan Parameter-efficient fine-tuning
Fine-tuning penuh
Panjang urutan maksimum 8192
Modalities Teks
Llama 3.2 1B Instruct Mode penyetelan Penyesuaian penuh
Panjang urutan maksimum 8192
Modalities Teks
Llama 3.2 3B Instruct Mode penyetelan Penyesuaian penuh
Panjang urutan maksimum 8192
Modalities Teks
Llama 3.3 70B Instruct Mode penyetelan Parameter-efficient fine-tuning
Fine-tuning penuh
Panjang urutan maksimum 8192
Modalities Teks
Llama 4 Scout 17B 16E Instruct Mode penyetelan Parameter-efficient fine-tuning
Panjang urutan maksimum 2048
Modalities Teks
Gambar*

*Set data campuran yang berisi contoh teks saja dan gambar tidak didukung. Jika ada minimal satu contoh gambar dalam set data, semua contoh khusus teks akan difilter.
Qwen 3 4B Mode penyetelan Penyesuaian penuh
Panjang urutan maksimum 8192
Modalities Teks
Qwen 3 8B Mode penyetelan Penyesuaian penuh
Panjang urutan maksimum 8192
Modalities Teks
Qwen 3 14B Mode penyetelan Penyesuaian penuh
Panjang urutan maksimum 8192
Modalities Teks
Qwen 3 32B Mode penyetelan Parameter-efficient fine-tuning
Fine-tuning penuh
Panjang urutan maksimum 8192
Modalities Teks

Sebelum memulai

  1. Login ke akun Google Cloud Anda. Jika Anda baru menggunakan Google Cloud, buat akun untuk mengevaluasi performa produk kami dalam skenario dunia nyata. Pelanggan baru juga mendapatkan kredit gratis senilai $300 untuk menjalankan, menguji, dan men-deploy workload.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI and Cloud Storage APIs.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the APIs

  8. Menginstal dan melakukan inisialisasi Vertex AI SDK untuk Python
  9. Impor library berikut:
    import os
    import time
    import uuid
    import vertexai
    
    vertexai.init(project=PROJECT_ID, location=REGION)
    
    from google.cloud import aiplatform
    from vertexai.tuning import sft, SourceModel
    

Menyiapkan set data untuk penyesuaian

Set data pelatihan diperlukan untuk penyesuaian. Sebaiknya siapkan set data validasi opsional jika Anda ingin mengevaluasi performa model yang telah disesuaikan.

Set data Anda harus dalam salah satu format JSON Lines (JSONL) yang didukung berikut, dengan setiap baris berisi satu contoh penyesuaian.

Upload file JSONL Anda ke Cloud Storage.

Set data hanya teks

Penyelesaian perintah

{"prompt": "<prompt text>", "completion": "<ideal generated text>"}

Format chat berbasis giliran

{"messages": [
  {"content": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles.",
    "role": "system"},
  {"content": "Summarize the paper in one paragraph.",
    "role": "user"},
  {"content": " Here is a one paragraph summary of the paper:\n\nThe paper describes PaLM, ...",
    "role": "assistant"}
]}

GenerateContent

{
"systemInstruction": {
  "parts": [{ "text": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles." }]},
"contents": [
  {"role": "user",
    "parts": [{ "text": "Summarize the paper in one paragraph." }]},
  {"role": "assistant",
    "parts": [{ "text": "Here is a one paragraph summary of the paper:\n\nThe paper describes PaLM, ..." }]}
]}

Set data multimodal

Format chat berbasis giliran

{"messages": [
  {"role": "user", "content": [
    {"type": "text", "text": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles."},
    {"type": "image_url", "image_url": {
      "url": "gs://your-gcs-bucket/your-image.jpeg",
      "detail": "low"}}]
  },
  {"role": "assistant", "content": [
    {"type": "text", "text": "Here is a one paragraph summary of the paper:\n\nThe paper describes PaLM, ..."}]
  },
  {"role": "user", "content": [
    {"type": "text", "text": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles."},
    {"type": "image_url", "image_url": {
      "url": "data:image/jpeg;base64,<base64 image>",
      "detail": "low"}}]
  },
  {"role": "assistant", "content": [
    {"type": "text", "text": "Here is a one paragraph summary of the paper:\n\nThe paper describes PaLM, ..."}]
  },
]}

GenerateContent

{
"systemInstruction": {
  "parts": [{ "text": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles." }]},
"contents": [
  {"role": "user",
    "parts": [
      {"text": "You are a chatbot that helps with scientific literature and generates state-of-the-art abstracts from articles." },
      {"file_data": {
        "mime_type": "image/jpeg", "file_uri": "gs://your-gcs-bucket/your-image.jpeg"}}]
  },
  {"role": "assistant",
    "parts": [{ "text": "Here is a one paragraph summary of the paper:\n\nThe paper describes PaLM, ..." }]}
]}

Format yang didukung mencakup JPEG, PNG, WEBP, dan gambar berenkode Base64.

Perhatikan bahwa jika gambar Anda disimpan di bucket Cloud Storage yang berbeda dari file JSONL, pastikan Anda telah memberikan peran IAM Pengguna Objek Penyimpanan (roles/storage.objectUser) di kedua bucket untuk dua akun layanan ini:

  • service-PROJECT_NUMBER@gcp-sa-vertex-moss-ft.iam.gserviceaccount.com
  • service-PROJECT_NUMBER@gcp-sa-aiplatform.iam.gserviceaccount.com

Buat tugas penyesuaian

Anda dapat menyesuaikan dari:

  • Model dasar yang didukung, seperti Llama 3.1
  • Model yang memiliki arsitektur yang sama dengan salah satu model dasar yang didukung. Ini bisa berupa checkpoint model kustom dari repositori seperti Hugging Face atau model yang sebelumnya disesuaikan dari tugas penyesuaian Vertex AI. Dengan begitu, Anda dapat terus menyesuaikan model yang telah disesuaikan.

Cloud Console

  1. Anda dapat memulai penyesuaian halus dengan cara berikut:

    • Buka kartu model, klik Sesuaikan, lalu pilih Penyesuaian terkelola.

    Buka kartu model Llama 3.1

    atau

    • Buka halaman Penyesuaian, lalu klik Buat model yang disesuaikan.

    Buka Penyesuaian

  2. Isi parameter, lalu klik Mulai penyesuaian.

Tindakan ini akan memulai tugas penyesuaian, yang dapat Anda lihat di halaman Penyesuaian pada tab Penyesuaian terkelola.

Setelah tugas tuning selesai, Anda dapat melihat informasi tentang model yang di-tuning di tab Detail.

Vertex AI SDK for Python

Ganti nilai parameter dengan nilai Anda sendiri, lalu jalankan kode berikut untuk membuat tugas penyesuaian:

sft_tuning_job = sft.train(
    source_model=SourceModel(
      base_model="meta/llama3_1@llama-3.1-8b",
      # Optional, folder that is either a custom model checkpoint or previously tuned model
      custom_base_model="gs://{STORAGE-URI}",
    ),
    tuning_mode="FULL", # FULL or PEFT_ADAPTER
    epochs=3,
    train_dataset="gs://{STORAGE-URI}", # JSONL file
    validation_dataset="gs://{STORAGE-URI}", # JSONL file
    output_uri="gs://{STORAGE-URI}",
)

Artefak model yang disesuaikan

Setelah tugas penyesuaian selesai, artefak model untuk model yang disesuaikan akan disimpan di direktori output Cloud Storage Anda.

gs://<output_dir>/postprocess/node-0/checkpoints/
    # Final checkpoint
    -> final/
        -> model-00001-of-000xx.safetensors
        -> model-000yy-of-000xx.safetensors

    # Intermediate checkpoints
    -> checkpoint-M/
        -> model-00001-of-000xx.safetensors
        -> model-000yy-of-000xx.safetensors
        -> checkpoint-N/
        -> model-00001-of-000xx.safetensors
        -> model-000yy-of-000xx.safetensors
  • Maksimum 10 titik pemeriksaan disimpan.
  • Jika jumlah epoch (E) kurang dari 10, maka tepatnya E titik pemeriksaan akan disimpan (satu untuk setiap epoch).
  • Pos pemeriksaan menengah dari rentang M hingga N diurutkan. Perhatikan bahwa titik pemeriksaan perantara tidak selalu diberi nomor secara berurutan. Misalnya, pos pemeriksaan dapat diberi nomor 1, 3, 5, 10, bukan 1, 2, 3, 4.

Men-deploy model yang disesuaikan

Anda dapat men-deploy model yang disesuaikan ke endpoint Vertex AI. Anda juga dapat mengekspor model yang di-tune dari Cloud Storage dan men-deploy-nya di tempat lain.

Untuk men-deploy model yang disesuaikan ke endpoint Vertex AI:

Cloud Console

  1. Buka halaman Model Garden, lalu klik Deploy model with custom weights.

Buka Model Garden

  1. Isi parameter, lalu klik Deploy.

Vertex AI SDK for Python

Men-deploy G2 machine menggunakan container bawaan:

from vertexai.preview import model_garden

MODEL_ARTIFACTS_STORAGE_URI = "gs://{STORAGE-URI}/postprocess/node-0/checkpoints/final"

model = model_garden.CustomModel(
    gcs_uri=MODEL_ARTIFACTS_STORAGE_URI,
)

# deploy the model to an endpoint using GPUs. Cost will incur for the deployment
endpoint = model.deploy(
  machine_type="g2-standard-12",
  accelerator_type="NVIDIA_L4",
  accelerator_count=1,
)

Mendapatkan inferensi

Setelah deployment berhasil, Anda dapat mengirim permintaan ke endpoint dengan perintah teks. Perhatikan bahwa beberapa perintah pertama akan memerlukan waktu lebih lama untuk dieksekusi.

# Loads the deployed endpoint
endpoint = aiplatform.Endpoint("projects/{PROJECT_ID}/locations/{REGION}/endpoints/{endpoint_name}")

prompt = "Summarize the following article. Article: Preparing a perfect risotto requires patience and attention to detail. Begin by heating butter in a large, heavy-bottomed pot over medium heat. Add finely chopped onions and minced garlic to the pot, and cook until they're soft and translucent, about 5 minutes. Next, add Arborio rice to the pot and cook, stirring constantly, until the grains are coated with the butter and begin to toast slightly. Pour in a splash of white wine and cook until it's absorbed. From there, gradually add hot chicken or vegetable broth to the rice, stirring frequently, until the risotto is creamy and the rice is tender with a slight bite.. Summary:"

# Define input to the prediction call
instances = [
    {
        "prompt": "What is a car?",
        "max_tokens": 200,
        "temperature": 1.0,
        "top_p": 1.0,
        "top_k": 1,
        "raw_response": True,
    },
]

# Request the prediction
response = endpoint.predict(
    instances=instances
)

for prediction in response.predictions:
    print(prediction)

Untuk mengetahui detail selengkapnya tentang mendapatkan inferensi dari model yang di-deploy, lihat Mendapatkan inferensi online.

Perhatikan bahwa model terbuka terkelola menggunakan metode chat.completions, bukan metode predict yang digunakan oleh model yang di-deploy. Untuk mengetahui informasi selengkapnya tentang cara mendapatkan inferensi dari model terkelola, lihat Melakukan panggilan ke model Llama.

Batas dan kuota

Kuota diterapkan pada jumlah tugas penyesuaian serentak. Setiap project dilengkapi dengan kuota default untuk menjalankan setidaknya satu tugas penyesuaian. Ini adalah kuota global, yang dibagikan di semua region yang tersedia dan model yang didukung. Jika ingin menjalankan lebih banyak tugas secara bersamaan, Anda harus meminta kuota tambahan untuk Global concurrent managed OSS model fine-tuning jobs per project.

Harga

Anda akan ditagih untuk penyesuaian berdasarkan harga untuk Penyesuaian model. Jumlah token pelatihan dihitung dengan mengalikan jumlah token dalam set data pelatihan dengan jumlah epoch.

Anda juga ditagih untuk layanan terkait, seperti Cloud Storage dan Prediksi Vertex AI.

Pelajari harga Vertex AI, harga Cloud Storage, dan gunakan Kalkulator Harga untuk membuat perkiraan biaya berdasarkan penggunaan yang Anda proyeksikan.

Langkah berikutnya