全部产品
Search
文档中心

MaxCompute:Fungsi AI MaxFrame

更新时间:Dec 12, 2025

Topik ini menjelaskan cara menggunakan Fungsi AI MaxFrame di MaxCompute dan menyediakan kasus penggunaan untuk membantu Anda memulai aplikasi inferensi offline model besar.

Ikhtisar fungsi

Fungsi AI MaxFrame adalah solusi end-to-end pada platform Alibaba Cloud MaxCompute untuk inferensi offline model besar. Fungsi ini mengintegrasikan pemrosesan data dengan kemampuan AI secara mulus, sehingga kecerdasan model besar dapat diakses di platform data besar. Integrasi ini menyederhanakan alur kerja pemrosesan data, meningkatkan kualitas hasil, menurunkan hambatan penggunaan AI dalam analitik data, serta menyederhanakan pengembangan aplikasi model besar tingkat enterprise.

  • Filosofi desain: "Data sebagai input, data sebagai output." Anda dapat menggunakan framework pengembangan Python MaxFrame dan API bergaya Pandas untuk menyelesaikan seluruh alur kerja dalam ekosistem MaxCompute, mencakup persiapan data, pemrosesan data, inferensi model, dan penyimpanan hasil.

  • Fitur inti:

    • Pemrosesan data skala besar: Memproses volume besar data terstruktur, seperti log untuk analisis atau data perilaku pengguna, serta data tidak terstruktur, seperti teks untuk terjemahan atau ringkasan dokumen. Anda dapat memproses data petabyte dalam satu task.

    • Latensi rendah dan penskalaan linear: Mencapai latensi rendah dan penskalaan linear melalui arsitektur komputasi terdistribusi.

    • Integrasi model besar: MaxFrame menyediakan dukungan out-of-the-box untuk rangkaian model besar seperti Qwen 3, Qwen 2.5, dan Deepseek-R1-Distill-Qwen. Model-model tersebut di-hosting secara offline di dalam platform MaxCompute, sehingga Anda tidak perlu khawatir tentang unduhan model, distribusi, atau batas konkurensi panggilan API. Anda dapat memanggil model menggunakan API, memungkinkan pemanfaatan penuh sumber daya komputasi besar MaxCompute untuk menyelesaikan tugas pemrosesan teks dengan throughput token dan konkurensi keseluruhan yang tinggi.

  • Skenario aplikasi: Anda dapat menggunakannya untuk berbagai tugas, seperti mengekstraksi informasi terstruktur dari teks, meringkas konten, menghasilkan abstrak, menerjemahkan bahasa, menilai kualitas teks, dan mengklasifikasikan sentimen. Hal ini sangat menyederhanakan alur kerja pemrosesan data model besar dan meningkatkan kualitas hasil.

  • Rangkuman keunggulan:

    Dimensi

    Fungsi AI MaxFrame

    Kemudahan penggunaan

    API Python yang familiar, pustaka model out-of-the-box, dan biaya deployment nol.

    Ekstensibilitas

    Mengandalkan sumber daya komputasi CU dan GU MaxCompute untuk mendukung pemrosesan paralel skala besar dan meningkatkan throughput token keseluruhan.

    Integrasi data dan AI

    Membaca data, memproses data, melakukan inferensi AI, dan menyimpan hasil pada satu platform terpadu. Hal ini mengurangi biaya migrasi data dan meningkatkan efisiensi pengembangan.

    Cakupan skenario

    Mencakup lebih dari sepuluh skenario frekuensi tinggi, seperti terjemahan, ekstraksi terstruktur, dan vektorisasi.

  • Arsitektur keseluruhan

    Fungsi AI MaxFrame menyediakan antarmuka fleksibel generate, memungkinkan Anda memilih jenis model dan menggunakan tabel MaxCompute serta Prompts sebagai parameter input.

    Saat antarmuka dieksekusi, MaxFrame pertama-tama membagi data tabel menjadi chunk. Kemudian, sistem menetapkan tingkat konkurensi yang sesuai berdasarkan volume data dan memulai grup pekerja untuk menjalankan tugas komputasi. Setiap pekerja menggunakan parameter prompt yang Anda berikan sebagai templat. Sistem merender baris data input untuk membangun input model. Hasil inferensi dan status keberhasilan kemudian ditulis ke MaxCompute.

    Gambar berikut menunjukkan arsitektur dan proses keseluruhan.

    image

Lingkup

  • Wilayah yang didukung:

    Tiongkok (Hangzhou), Tiongkok (Shanghai), Tiongkok (Beijing), Tiongkok (Ulanqab), Tiongkok (Shenzhen), Tiongkok (Chengdu), Tiongkok (Hong Kong), Cloud Keuangan Tiongkok (Hangzhou), Cloud Keuangan Tiongkok (Shenzhen), Singapura, dan Indonesia (Jakarta).

  • Versi Python yang didukung: Python 3.11.

  • Versi SDK yang didukung: MaxFrame SDK V2.3.0 atau yang lebih baru. Anda dapat menjalankan perintah berikut untuk memeriksa versi Anda:

    // Windows
    pip list | findstr maxframe
    
    // Linux
    pip list | grep maxframe

    Jika versi Anda lebih lama dari yang disyaratkan, jalankan perintah berikut untuk menginstal versi terbaru: pip install --upgrade maxframe

  • Anda telah menginstal klien MaxFrame terbaru.

Sistem pendukung model

MaxFrame menawarkan dukungan out-of-the-box untuk rangkaian model besar seperti Qwen 3, Qwen 2.5, dan Deepseek-R1-Distill-Qwen. Semua model di-hosting secara offline di dalam platform MaxCompute. Anda tidak perlu khawatir tentang unduhan model, distribusi, atau batas konkurensi panggilan API. Anda dapat memanggil model menggunakan API untuk menjalankan tugas inferensi offline pada model besar, memungkinkan pemanfaatan penuh sumber daya komputasi besar MaxCompute guna mencapai throughput token dan konkurensi keseluruhan yang tinggi.

  • Rangkaian Qwen 3: Versi yang dioptimalkan untuk inferensi berdasarkan model Qwen 3. Mendukung terjemahan multibahasa, generasi teks kompleks, dan tugas generasi kode. Cocok untuk skenario yang membutuhkan output presisi tinggi.

  • Model Qwen Embedding: Dirancang untuk tugas vektorisasi. Mendukung konversi teks ke vektor secara efisien dan cocok untuk skenario seperti pencarian semantik dan pencocokan kemiripan.

  • Rangkaian Deepseek-R1-Distill-Qwen: Model ringan yang dikompresi menggunakan penyulingan pengetahuan. Cocok untuk inferensi cepat di lingkungan dengan sumber daya terbatas.

Mulailah dengan model yang lebih kecil. Jika output tidak memenuhi ekspektasi Anda, beralihlah ke model yang lebih besar. Model yang lebih besar mengonsumsi lebih banyak sumber daya dan memerlukan waktu pemrosesan lebih lama. Mengutamakan model yang lebih kecil dapat meningkatkan efisiensi dan mengurangi biaya sekaligus tetap memenuhi kebutuhan output Anda.

Model yang Didukung (Terus Diperbarui)

Tipe Model

Nama Model

Jenis resource yang didukung

Model rangkaian Qwen 3

  • Qwen3-0.6B

  • Qwen3-1.7B

  • Qwen3-4B

  • Qwen3-8B

  • Qwen3-14B

CU

  • Qwen3-4B-Instruct-2507-FP8

  • Qwen3-30B-A3B-Instruct-2507-FP8

GU

Model Qwen Embedding

  • Qwen3-Embedding-8B

CU

  • Qwen3-Embedding-0.6

GU

Model seri teks Qwen 2.5

  • Qwen2.5-0.5B-instruct

  • Qwen2.5-1.5B-instruct

  • Qwen2.5-3B-instruct

  • Qwen2.5-7B-instruct

CU

Model seri Deepseek-R1-Distill-Qwen

  • DeepSeek-R1-Distill-Qwen-1.5B

  • DeepSeek-R1-Distill-Qwen-7B

  • DeepSeek-R1-Distill-Qwen-14B

CU

Model Deepseek-R1-0528-Qwen3

  • DeepSeek-R1-0528-Qwen3-8B

CU

Deskripsi antarmuka

Fungsi AI MaxFrame menyediakan keseimbangan antara fleksibilitas dan kemudahan penggunaan melalui antarmuka ganda generate dan Task:

Antarmuka tujuan umum: generate

Antarmuka ini mendukung templat prompt kustom dan pengaturan parameter. Cocok untuk skenario yang memerlukan kontrol tingkat tinggi terhadap logika inferensi. Contohnya:

from maxframe.learn.contrib.llm.models.managed import ManagedTextLLM

llm = ManagedTextLLM(name="<model_name>")

# Templat prompt
messages = [
  {"role": "system", "content": "system_messages"},
  {"role": "user", "content": "user_messages"},
]

result_df = llm.generate(<df> , prompt_template=messages)
print(result_df.execute())

Parameter:

  • model_name: Wajib. Nama model.

  • df: Wajib. Teks atau data yang akan dianalisis, dibungkus dalam DataFrame.

  • prompt_template: Wajib. Daftar pesan yang kompatibel dengan format Chat OpenAI. Di dalam konten, Anda dapat menggunakan f-string untuk mereferensikan konten kolom tabel.

Antarmuka spesifik skenario: Task - Hanya didukung oleh sumber daya komputasi GU

Antarmuka ini menyediakan antarmuka task standar yang telah ditentukan untuk menyederhanakan pengembangan pada skenario umum. Antarmuka task yang saat ini didukung termasuk translate dan extract.

from maxframe.learn.contrib.llm.models.managed import ManagedTextLLM

llm = ManagedTextLLM(name="<model_name>")

# Terjemahan teks
translated_df = llm.translate(  
    df["english_column"],  
    source_language="english",
    target_language="Chinese",
    examples=[("Hello", "你好"), ("Goodbye", "再见")],
)  

translated_df.execute()

Contoh

Jika ini pertama kalinya Anda menggunakan MaxFrame untuk pemrosesan data, lihat Memulai dengan MaxFrame untuk mempelajari fitur-fiturnya.

Contoh ini dijalankan dalam mode lokal. Kode berikut menunjukkan skrip lengkap dan deskripsinya:

import os
from maxframe import new_session
from odps import ODPS
import pandas as pd
import maxframe.dataframe as md
from maxframe.learn.contrib.llm.models.managed import ManagedTextLLM

o = ODPS(
    os.getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'),
    os.getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
    project='<maxcompute_project_name>',
    endpoint='https://service.cn-hangzhou.maxcompute.aliyun.com/api',
)

# 1. Buat sesi menggunakan SDK MaxFrame.
session = new_session(odps_entry=o)

# Jangan potong teks kolom agar menampilkan konten lengkap.
pd.set_option("display.max_colwidth", None)
# Tampilkan semua kolom untuk mencegah kolom tengah dihilangkan.
pd.set_option("display.max_columns", None)

# 2. Impor DataFrame dan buat lima pertanyaan.
query_list = [
    "What is the average distance between Earth and the sun?",
    "In what year did the American Revolutionary War begin?",
    "What is the boiling point of water?",
    "How can I quickly relieve a headache?",
    "Who is the protagonist of the Harry Potter series?",
]
df = md.DataFrame({"query": query_list})

# 3. Buat objek ManagedTextLLM dan tentukan qwen3-14b sebagai model yang digunakan.
llm = ManagedTextLLM(name="qwen3-14b")

# 4. Definisikan templat prompt yang mencakup pesan sistem dan pesan pengguna.
# Di pesan pengguna, simpan variabel {query} dalam format f-string. Placeholder ini akan diganti dengan konten dari kolom query DataFrame. Placeholder mendukung penggunaan beberapa kolom dari DataFrame, semuanya direferensikan dengan nama kolom yang sesuai.
messages = [
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Please answer the following question: {query}"},
]

# 5. Panggil metode generate pada objek LLM. Berikan DataFrame dan templat prompt untuk mendapatkan jawaban untuk setiap pertanyaan.
result_df = llm.generate(df, prompt_template=messages)

# 6. Gunakan execute untuk memicu perhitungan pada DataFrame hasil.
#   Semua perhitungan akan terjadi di kluster MaxCompute. DataFrame input akan secara otomatis di-shard dan diproses secara paralel berdasarkan skala komputasi.
print(result_df.execute())

Hasil berikut dikembalikan:

Nomor baris

response_json

success

0

{"id": "chatcmpl-1765181488", "object": "chat.completion", "created": 1765181488, "model": "qwen3-14b", "choices": [{"index": 0, "message": {"role": "assistant", "content": "The average distance between Earth and the sun is approximately **149.6 million kilometers** (or **1.496 × 10⁸ km**). This distance is defined as **1 astronomical unit (AU)**. \n\nEarth's orbit is an ellipse, so the actual distance varies slightly depending on its position: \n- **Perihelion** (when Earth is closest to the sun): about **147.1 million km** (about 1.471 AU) \n- **Aphelion** (when Earth is farthest from the sun): about **152.1 million km** (about 1.521 AU) \n\nThe average distance uses the **semi-major axis** of the orbit (half of the long axis of the ellipse), which is the standard way to calculate planetary orbits in astronomy.", "reasoning_content": "Okay, the user is asking for the average distance between Earth and the sun. This seems like a basic question, but I need to confirm the exact number. First, I remember that Earth's orbit around the sun is elliptical, so the average distance probably refers to the semi-major axis, which is the astronomical unit. But what is the specific value? Is it about 150 million kilometers? Or, to be more precise, should I use scientific notation?\n\nRight, the astronomical unit (AU) is usually defined as the average distance from Earth to the sun, and 1 AU is about 149.6 million kilometers, which is 1.496 × 10^8 km. Sometimes it's rounded to 150 million km, or a more precise value might have a few decimal places. For example, the exact value is about 149.59787 million km, but in general, using 150 million km or 149.6 million km is acceptable.\n\nI also need to consider if the unit needs to be converted to other forms, like kilometers or meters, but the user's question doesn't specify, so kilometers should be appropriate. Also, should I mention the definition of this distance, like it's based on the semi-major axis of the orbit, not the distance at perihelion or aphelion? Because Earth's orbit is an ellipse, the average distance should be calculated using the semi-major axis, not a simple arithmetic mean, although the values are close.\n\nI should also consider the user's potential background. If they are a student or a general reader, they might need a concise and clear answer without getting too deep into astronomical jargon. However, if necessary, I can briefly explain why it's this value, for example, based on the semi-major axis of an elliptical orbit. This way, the user not only gets the data but also understands the principle behind it."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 32, "completion_tokens": 621, "total_tokens": 653}}

True

1

{"id": "chatcmpl-1765181584", "object": "chat.completion", "created": 1765181584, "model": "qwen3-14b", "choices": [{"index": 0, "message": {"role": "assistant", "content": "The American Revolutionary War began in **1775**. \nThe specific landmark event was the **Battles of Lexington and Concord** on **April 19, 1775** (also known as the 'shot heard 'round the world'), which was the first major military conflict between Great Britain and the 13 North American colonies, marking the official start of the Revolutionary War. \n\nAlthough the Declaration of Independence was issued on July 4, 1776, military actions of the war had already been in full swing since 1775.", "reasoning_content": "Okay, the user is asking when the American Revolutionary War began. I need to confirm this date. First, I remember the start of the American Revolutionary War is marked by the Battles of Lexington and Concord, the so-called 'shot heard 'round the world.' That was on April 19, 1775. However, people might sometimes refer to earlier events, like the Boston Tea Party, but the official start of the war should be in 1775.\n\nHowever, the user might want a more precise date, or if there are other possible years. For example, some might think the war started in 1776 because the Declaration of Independence was issued that year, but the war actually started before that. It's necessary to distinguish between the start of the war and the formal declaration of independence.\n\nI also need to be careful that the user isn't confusing the years with other wars, like the American Civil War or other events. But the question clearly mentions the Revolutionary War, so that should be fine. Checking historical sources, the Battles of Lexington and Concord are indeed the start of the American Revolutionary War, so the correct answer should be 1775."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 33, "completion_tokens": 349, "total_tokens": 382}}

True

2

{"id": "chatcmpl-1765181766", "object": "chat.completion", "created": 1765181766, "model": "qwen3-14b", "choices": [{"index": 0, "message": {"role": "assistant", "content": "The boiling point of water is the temperature at which water changes from a liquid to a gas (water vapor) under standard atmospheric pressure (1 atmosphere, or about 101.325 kilopascals). Under standard conditions, **the boiling point of water is 100 degrees Celsius (°C)**.\n\nNote:\n1. **Effect of atmospheric pressure**: The boiling point changes with atmospheric pressure. For example, at high altitudes (where the pressure is lower), the boiling point of water is below 100°C. In a high-pressure environment (like a pressure cooker), the boiling point increases.\n2. **Effect of impurities**: If water contains solutes (like salt), its boiling point will be slightly higher (boiling point elevation).\n3. **Unit conversion**: 100°C is equivalent to 212 degrees Fahrenheit (°F).\n\nThis phenomenon is the key temperature point at which water molecules gain enough energy to overcome intermolecular forces in the liquid state and escape as gas.", "reasoning_content": "Okay, the user is asking 'What is the boiling point of water?'. First, I need to determine what the user needs. Maybe they are doing science homework, or they encountered a problem while cooking, like the temperature at which water boils. But generally, the boiling point is a basic physical concept, so the user might be a student or just starting to learn about it.\n\nNext, I need to ensure the answer is accurate. The boiling point of water is 100 degrees Celsius at standard atmospheric pressure, but I might need to add an explanation of what standard atmospheric pressure is, which is 1 atmosphere, approximately 101.325 kilopascals. Also, the boiling point changes with atmospheric pressure. For example, at high altitudes where the pressure is lower, the boiling point is also lower, which can affect cooking, like boiling an egg takes longer.\n\nI should also consider whether to mention other factors, like dissolved substances in water can affect the boiling point. For example, saltwater has a higher boiling point than pure water. But the user's question is quite basic, so I might not need to go too deep, but briefly mentioning these can make the answer more comprehensive.\n\nAlso, the user might have questions about units, like whether to use Fahrenheit or other units. Although the question is in Chinese, I might need to point out the situation with different units. But in a Chinese context, Celsius is more commonly used, so I can primarily answer in Celsius and briefly mention other units.\n\nFinally, I need to ensure the answer is clear and concise, avoiding overly technical terms so that all readers can understand. I might need to list points for standard conditions, influencing factors, etc., but keep it conversational and not too formal."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 30, "completion_tokens": 513, "total_tokens": 543}}

True

3

{"id": "chatcmpl-1765182120", "object": "chat.completion", "created": 1765182120, "model": "qwen3-14b", "choices": [{"index": 0, "message": {"role": "assistant", "content": "Methods to quickly relieve a headache can vary depending on the type and cause of the headache. Here are some common and effective measures:\n\n---\n\n### **1. Basic Relief Methods**\n- **Rest and Relaxation** \n - Find a quiet, softly lit environment and rest with your eyes closed for 10-15 minutes. Avoid continuous eye strain or mental tension. \n - **Deep Breathing**: Inhale slowly for 4 seconds, hold your breath for 4 seconds, then exhale slowly for 6 seconds. Repeat 5-10 times to help relieve tension headaches.\n\n- **Hydration** \n - Dehydration is a common cause of headaches. Drink a glass of warm water or light salt water and see if it helps.\n\n- **Cold or Hot Compress** \n - **Migraine**: Apply a cold pack to your forehead or the back of your neck (for 10-15 minutes at a time) to constrict blood vessels and reduce pain. \n - **Tension Headache**: Apply a hot pack to your neck or shoulders to promote blood circulation and relax muscles.\n\n- **Gentle Massage** \n - Use your fingertips to gently press from the center of your forehead to the sides, or massage your temples and the back of your neck (Fengchi acupoint) to relieve local muscle tension.\n\n---\n\n### **2. Medication for Relief (Short-term use)**\n- **Over-the-counter medication**: Such as ibuprofen or acetaminophen. Take as directed on the label (be careful not to overdose). \n- **Migraine-specific medication**: Such as triptans (requires a doctor's guidance; not recommended for long-term self-use).\n\n---\n\n### **3. Environmental Adjustments**\n- **Avoid Stimuli**: Stay away from factors that may trigger headaches, such as bright lights, loud noises, and smoke. \n- **Adjust Posture**: Maintain correct posture and avoid looking down or holding your head in an improper position for long periods.\n\n---\n\n### **4. Preventive Measures**\n- **Regular Schedule**: Ensure adequate sleep and avoid staying up late. \n- **Diet Management**: Avoid excessive caffeine, alcohol, chocolate, cheese, and other foods that may trigger headaches. \n- **Stress Management**: Relieve stress through meditation, yoga, exercise, etc.\n\n---\n\n### **5. When to See a Doctor?**\nSeek medical attention if your headache has the following characteristics: \n- A sudden, severe headache (like a 'thunderclap headache'); \n- Accompanied by fever, vomiting, confusion, vision changes, etc.; \n- The frequency or duration of headaches increases; \n- The headache is caused by trauma, infection, or other diseases.\n\n---\n\n**Tip**: If headaches occur frequently (e.g., several times a week), consult a doctor to rule out underlying causes (such as high blood pressure, abnormal intracranial pressure, cervical spondylosis, etc.).", "reasoning_content": "Okay, the user is asking how to quickly relieve a headache, so I need to provide practical advice. First, I should consider common causes of headaches, like tension headaches, migraines, or dehydration. The user probably wants simple, effective methods that don't require complex steps.\n\nNext, I need to ensure the information is accurate and not harmful. For example, I can suggest rest, cold or hot compresses, but I should specify which situation they apply to. For instance, cold compresses are suitable for migraines, while hot compresses are for tension headaches. The user might not know these differences, so I need to be clear.\n\nI should also consider potential issues the user might not have mentioned, like whether they should see a doctor. If the headache is frequent or severe, professional help might be needed, and I should mention this to prevent the user from ignoring a serious condition.\n\nAlso, the user probably wants methods that work quickly, so I need to list several common fast-acting methods, like deep breathing, drinking water, and massage, in order of priority, so the user can try them quickly. At the same time, I should avoid recommending potentially harmful methods, like overusing medication, unless necessary.\n\nI should also use concise language and a clear structure, using bullet points for easy reading. The user requested no Markdown, so I'll use natural paragraphs.\n\nFinally, I'll check if I've missed any important points, like avoiding triggers such as caffeine and stress, which is also an important part of preventing headaches. But the user is asking for relief, so the focus should be on relief methods, with prevention as a supplementary suggestion."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 29, "completion_tokens": 828, "total_tokens": 857}}

True

4

{"id": "chatcmpl-1765182284", "object": "chat.completion", "created": 1765182284, "model": "qwen3-14b", "choices": [{"index": 0, "message": {"role": "assistant", "content": "The protagonist of the Harry Potter series is **Harry Potter**. He is the central character of the fantasy novel series created by J.K. Rowling. The story revolves around his growth from an ordinary orphan into a hero who fights against the evil wizard Voldemort. Harry is given the title 'The Chosen One' because his destiny has been intertwined with Voldemort's since birth, and he ultimately becomes the key figure in saving the wizarding world.\n\nAlthough Hermione Granger and Ron Weasley are Harry's closest friends and play important roles in the series, Harry is always the central character of the story.", "reasoning_content": "Okay, the user is asking who the protagonist of the Harry Potter series is. First, I need to confirm which version the user is referring to, as there could be movies, novels, or other derivative works. But generally, people usually refer to the original novels written by J.K. Rowling, or the corresponding movie series.\n\nFirst, the name Harry Potter is the core of the series, and the entire story revolves around his development. However, sometimes users might confuse other important characters, like Hermione Granger or Ron Weasley, who, while important, are not the protagonists. But some might consider them as protagonists too, especially in certain analyses, but usually, the protagonist is Harry.\n\nAlso, I need to confirm if there are other possible protagonists, like in the subsequent stage play 'The Cursed Child,' where Harry's son, Albus Severus Potter, is a main character. But the user's question should refer to the entire series, not just the stage play part.\n\nThe user's question might be simple, but as a respondent, I need to clearly state that Harry Potter is the protagonist and can add some information, like his identity, his role in the story, and why he is the protagonist, such as his confrontation with Voldemort and his status as 'The Chosen One.'\n\nI also need to consider whether to mention other possible protagonists, for example, in some derivative works, but based on common questions, I should focus on the original books and movies. Also, I need to ensure the answer is accurate and avoid errors, like confirming that Harry is indeed the protagonist and not another character.\n\nTo sum up, the answer should be Harry Potter, and I can briefly explain his role and importance in the story to ensure the user gets a clear and accurate answer."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 35, "completion_tokens": 463, "total_tokens": 498}}

True

Skenario aplikasi 1: Terjemahan bahasa

Deskripsi skenario: Perusahaan multinasional perlu menerjemahkan 100.000 kontrak bahasa Inggris ke bahasa Mandarin dan menganotasi klausa utama.

Berikut adalah kode contoh:

  1. Data sampel

    CREATE TABLE IF NOT EXISTS raw_contracts (
        id BIGINT,
        en STRING
    );
    
    -- Masukkan data sampel.
    INSERT INTO raw_contracts VALUES
    (1, 'This Agreement is made and entered into as of the Effective Date by and between Party A and Party B.'),
    (2, 'The Contractor shall perform the Services in accordance with the terms and conditions set forth herein.'),
    (3, 'All payments shall be made in US Dollars within thirty (30) days of receipt of invoice.'),
    (4, 'Either party may terminate this Agreement upon thirty (30) days written notice to the other party.'),
    (5, 'Confidential Information shall not be disclosed to any third party without prior written consent.');
  2. Panggil model

    from maxframe.learn.contrib.llm.models.managed import ManagedTextLLM
    
    # 1. Gunakan model Qwen3 1.7B. 
    llm = ManagedTextLLM(name="Qwen3-1.7B")
    
    # 2. Siapkan data. Anda harus terlebih dahulu membuat tabel MaxCompute raw_contracts dan menyiapkan data yang akan diterjemahkan.
    df = md.read_odps_table("raw_contracts") 
    
    # 3. Definisikan templat prompt.
    messages = [
        {
            "role": "system",
            "content": "You are a document translation expert who can fluently translate the English text provided by the user into Chinese.",
        },
        {
            "role": "user",
            "content": "Please translate the following English text into Chinese. Output only the translated text and nothing else.\n\n For example:\nInput: Hi\nOutput: Hello.\n\n Here is the text to process:\n\n{en}",
        },
    ]
    
    # 4. Gunakan antarmuka `generate` secara langsung, definisikan prompt, dan referensikan kolom data yang sesuai.
    result_df = llm.generate(
        df,
        prompt_template=messages,
        params={
            "temperature": 0.7,
            "top_p": 0.8,
        },
    ).execute()
    
    # 5. Tulis data hasil ke tabel MaxCompute.
    result_df.to_odps_table("raw_contracts_result").execute()
  3. Hasil berikut dikembalikan:

    +------------+------------+---------+
    | index      | response   | success | 
    +------------+------------+---------+
    | 0          | {"id": "chatcmpl-1765195462", "object": "chat.completion", "created": 1765195462, "model": "qwen3-1.7b", "choices": [{"index": 0, "message": {"role": "assistant", "content": "This agreement is made and entered into by and between Party A and Party B as of the effective date.", "reasoning_content": "Okay, I need to translate the English sentence provided by the user into Chinese. First, let's look at the sentence structure: 'This Agreement is made and entered into as of the Effective Date by and between Party A and Party B.'\n\nFirst, 'This Agreement' translates to '本协议' (this agreement), which is appropriate. 'is made and entered into' has two verbs. 'made' usually refers to making an agreement, while 'entered into' might mean formal signing. But according to legal terminology, '签订' (to sign) or '达成协议' (to reach an agreement) might be more common. However, 'entered into' is often used in legal documents for formal signing, so an adjustment might be needed. For example, '本协议经双方于有效日期签订' (This agreement is signed by both parties on the effective date).\n\nThen, 'as of the Effective Date' translates to '自生效日期起' (from the effective date) or '自有效日期起' (from the valid date). Here, 'Effective Date' is usually translated as '生效日期' (effective date), so the whole sentence structure might need adjustment, like '本协议由双方于生效日期签订' (This agreement is signed by both parties on the effective date).\n\nFinally, 'by and between Party A and Party B' translates to '由当事人A和B之间签订' (signed between Party A and Party B) or '由当事人A和B签署' (signed by Party A and Party B). According to legal terminology, '由当事人A和B签署' or '由A和B之间签订' might be more common.\n\nPutting it all together, a possible translation is: '本协议由当事人A和B于生效日期签署。' (This agreement is signed by Party A and Party B on the effective date.) or '本协议由双方于生效日期签订。' (This agreement is signed by both parties on the effective date.) But I need to ensure the verb usage is correct. For example, 'entered into' might be more accurately '签订' (to sign) rather than '进入' (to enter), so an adjustment might be needed.\n\nLet's double-check. The user's example is 'Hi' translated to '你好' (hello), so a direct translation is fine. It might be necessary to maintain formal legal terminology, like '签订' (to sign) instead of '进入' (to enter)."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 90, "completion_tokens": 356, "total_tokens": 446}} | true    | 
    | 1          | {"id": "chatcmpl-1765195487", "object": "chat.completion", "created": 1765195487, "model": "qwen3-1.7b", "choices": [{"index": 0, "message": {"role": "assistant", "content": "The Contractor shall provide the services in accordance with the terms and conditions set forth in this agreement.", "reasoning_content": "Okay, I need to translate the English sentence provided by the user into Chinese. First, let's look at the sentence structure. The original sentence is: 'The Contractor shall perform the Services in accordance with the terms and conditions set forth herein.'\n\nFirst, let's identify the proper nouns. 'Contractor' here should be translated as '承包商' (contractor) or '承包人' (contractor), and a more specific term might be needed depending on the context, but '承包商' is probably more appropriate here. 'Services' is '服务' (services) or '工作' (work), but a more accurate translation might be needed depending on the context, like '服务' or '工作'. 'in accordance with' translates to '按照' (according to) or '依照' (in accordance with). 'terms and conditions' is '条款和条件'. 'set forth herein' is '此处列出' (listed here) or '此处规定' (stipulated here).\n\nSo the general meaning of the sentence is: 'The contractor shall provide the services in accordance with the terms and conditions listed in this agreement.'\n\nI need to check if there's a more natural way to express this. For example, in 'perform the Services,' 'Services' might refer to specific tasks or work, so '提供服务' (provide services) is appropriate. Also, 'set forth herein' might be more naturally translated as '此处列明' (listed here) or '此处规定' (stipulated here).\n\nPutting it all together, the translation should be: '承包商应按照本协议中列明的条款和条件提供服务。' (The contractor shall provide the services in accordance with the terms and conditions listed in this agreement.)\n\nI'll confirm there are no omissions or mistranslations and ensure the professional terms are accurate, for example, whether 'Contractor' needs a more specific job title, but based on common usage, '承包商' is fine here. Finally, I'll keep the sentence concise and fluent."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 86, "completion_tokens": 325, "total_tokens": 411}} | true    | 
    | 2          | {"id": "chatcmpl-1765195505", "object": "chat.completion", "created": 1765195505, "model": "qwen3-1.7b", "choices": [{"index": 0, "message": {"role": "assistant", "content": "All payments shall be made in US dollars within 30 days of receipt of the invoice.", "reasoning_content": "Okay, I need to translate the English sentence provided by the user into Chinese. First, let's look at the sentence structure: 'All payments shall be made in US Dollars within thirty (30) days of receipt of invoice.'\n\nFirst, 'All payments' translates to '所有付款' (all payments), which is appropriate. 'shall be made' is '将被作出' (will be made) or '将被支付' (will be paid), where '将被支付' might be more formal. 'in US Dollars' is '以美元计付' (paid in US dollars) or '以美元支付' (paid in US dollars), but 'US Dollars' is usually translated as '美元' (dollars), so '以' (in) is not needed. 'within thirty (30) days' is '在收到发票后的30天内' (within 30 days of receiving the invoice). 'of receipt of invoice' is '收到发票之日' (the day the invoice is received).\n\nSo the whole sentence can be translated as: '所有付款应在收到发票后30天内以美元支付。' (All payments shall be made in US dollars within 30 days of receipt of the invoice.)\n\nI need to check if there's a more natural expression, for example, if '收到发票后30天内' (within 30 days after receiving the invoice) is accurate, or if the word order needs to be adjusted. For example, 'within thirty days of receipt of invoice' might be more naturally expressed as '收到发票后30天内'.\n\nAfter confirming there are no errors, I'll output the translation directly."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 89, "completion_tokens": 256, "total_tokens": 345}} | true    | 
    | 3          | {"id": "chatcmpl-1765195538", "object": "chat.completion", "created": 1765195538, "model": "qwen3-1.7b", "choices": [{"index": 0, "message": {"role": "assistant", "content": "Either party has the right to terminate this Agreement upon thirty days' written notice.", "reasoning_content": "Okay, I need to translate the English sentence provided by the user into Chinese. First, let's look at the sentence structure: 'Either party may terminate this Agreement upon thirty (30) days written notice to the other party.'\n\nFirst, let's break down the sentence components. 'Either party' refers to any party, 'may terminate' means can terminate, 'this Agreement' is this agreement, 'upon thirty (30) days written notice' is thirty days' written notice, and 'to the other party' is to notify the other party.\n\nWhen translating, I need to be accurate with legal terms. For example, 'Either party' is usually translated as '任何一方' (any party) or '任一方' (either party). 'may terminate' is '有权终止' (has the right to terminate) or '可以终止' (can terminate). 'this Agreement' is '本协议' (this agreement). 'upon thirty (30) days written notice' needs to accurately express 'thirty days' written notice'. 'to the other party' is '通知另一方' (notify the other party).\n\nThen, I'll consider the fluency of the sentence. The original sentence is a compound sentence, so I need to ensure the Chinese translation has a reasonable structure. For example, 'Either party may terminate this Agreement upon thirty (30) days written notice to the other party.' can be translated as '任何一方有权在书面通知另一方三十天后终止本协议。' (Either party has the right to terminate this agreement thirty days after written notice to the other party.) or more concisely '任何一方有权在三十天书面通知后终止本协议。' (Either party has the right to terminate this agreement after thirty days' written notice.)\n\nLet's check for a more natural expression. For example, 'upon' here might be better translated as '在……之后' (after...). Also, 'written notice' is '书面通知' (written notice), and 'days' is '天数' (number of days).\n\nFinally, I'll settle on the translation: '任何一方有权在三十天书面通知后终止本协议。' (Either party has the right to terminate this agreement after thirty days' written notice.) or more concisely '任何一方有权在三十天书面通知后终止本协议。' I need to ensure no information is lost, for example, 'terminate' is '终止' (terminate) and not '终止或解除' (terminate or rescind).\n\nAfter confirming it's correct, I'll output the translation directly."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 89, "completion_tokens": 394, "total_tokens": 483}} | true    | 
    | 4          | {"id": "chatcmpl-1765195574", "object": "chat.completion", "created": 1765195574, "model": "qwen3-1.7b", "choices": [{"index": 0, "message": {"role": "assistant", "content": "Confidential Information shall not be disclosed to any third party without prior written consent.", "reasoning_content": "Okay, the user wants me to translate a piece of English into Chinese and output it directly without any other content. First, I need to confirm what the English sentence provided by the user is. The example sentence given by the user is 'Confidential Information shall not be disclosed to any third party without prior written consent.', and the user's example is input 'Hi' output '你好' (hello). Now the text provided by the user is 'Confidential Information shall not be disclosed to any third party without prior written consent.', which needs to be translated into Chinese.\n\nFirst, I need to accurately understand the meaning of this sentence. 'Confidential Information' should be '机密信息' (confidential information) or '保密信息' (secret information). 'shall not be disclosed' is '不得泄露' (shall not be disclosed). 'to any third party' is '任何第三方' (any third party). 'without prior written consent' is '未经事先书面同意' (without prior written consent). So the Chinese translation of the whole sentence should be '机密信息不得以任何第三方未经事先书面同意而泄露。' (Confidential information shall not be disclosed by any third party without prior written consent.)\n\nHowever, the user might want a more formal translation, like an expression commonly used in legal documents. For example, '机密信息不得向任何第三方披露,除非获得事先书面同意。' (Confidential information shall not be disclosed to any third party unless prior written consent is obtained.) This is more in line with legal terminology. But the user didn't specify, so I might need to stick to a direct translation but ensure accuracy.\n\nAlso, I need to pay attention to the sentence structure. 'shall not be disclosed' in the original sentence is '不得被披露' (shall not be disclosed), so I need to ensure the tense and voice of the verb are correct in the translation. At the same time, translating 'to any third party' as '任何第三方' (any third party) is correct, but sometimes '任何第三方' might need adjustment, for example, '任何第三方或任何其他个人' (any third party or any other individual)? But the example sentence provided by the user is '任何第三方', so I should probably keep it as is.\n\nLet's check for a more natural expression. For example, '机密信息不得未经事先书面同意向任何第三方披露' (Confidential information shall not be disclosed to any third party without prior written consent) might be more in line with Chinese expression habits. But the user might want a direct translation, so I need to weigh that. However, the example sentence given by the user is '机密信息不得向任何第三方泄露,除非获得事先书面同意。' (Confidential information shall not be disclosed to any third party unless prior written consent is obtained.), so I might need to maintain a similar structure.\n\nFinally, I'll ensure the translated sentence is fluent, conforms to Chinese grammar, and has no missing information. After confirming it's correct, I'll output the translation directly."}, "finish_reason": "stop"}], "usage": {"prompt_tokens": 85, "completion_tokens": 454, "total_tokens": 539}} | true    | 
    +------------+------------+---------+

Skenario aplikasi 2: Ekstraksi kata kunci

Deskripsi skenario: Skenario ini menunjukkan kemampuan Fungsi AI MaxFrame untuk memproses data tidak terstruktur. Teks dan citra, yang merupakan bagian besar dari data tidak terstruktur, menimbulkan tantangan signifikan bagi analitik data besar. Contoh berikut menunjukkan cara menggunakan Fungsi AI untuk menyederhanakan proses ini.

Kode berikut menunjukkan cara menggunakan Fungsi AI untuk mengambil pengalaman kerja kandidat dari resume dengan teks yang dihasilkan secara acak.

Berikut adalah kode contoh:

  1. Data sampel

    CREATE TABLE IF NOT EXISTS traditional_chinese_medicine (
        index BIGINT,
        text STRING
    );
    
    -- Masukkan data sampel.
    INSERT INTO traditional_chinese_medicine VALUES
    (1, 'Patient Zhang, male, 45 years old. Chief complaint: recurrent cough for 2 weeks. Current symptoms: cough with abundant white and sticky phlegm, chest tightness, shortness of breath, poor appetite, and loose stools. Tongue: white and greasy coating. Pulse: slippery. Diagnosis: Phlegm-dampness obstructing the lungs. Treatment principle: Dry dampness, resolve phlegm, regulate qi, and stop coughing. Prescription: Modified Erchen Tang.'),
    (2, 'Patient Li, female, 32 years old. Visited for "insomnia and excessive dreaming for 1 month." Accompanied by heart palpitations, forgetfulness, mental fatigue, and a sallow complexion. Tongue: pale with a thin white coating. Pulse: thin and weak. Diagnosis: Heart and spleen deficiency syndrome. Prescription: Modified Guipi Tang, one dose daily, decocted in water.'),
    (3, 'Patient Wang, 68 years old. Chief complaint: lower back and knee soreness, frequent nocturia for half a year. Accompanied by aversion to cold, cold limbs, tinnitus like cicadas, and listlessness. Tongue: pale, swollen with teeth marks, and a white, slippery coating. Pulse: deep and thin. TCM diagnosis: Kidney yang deficiency syndrome. Treatment: Warm and supplement kidney yang. Prescription: Modified Jinkui Shenqi Wan.'),
    (4, 'Patient Zhao, 5 years old. Fever for 3 days, highest temperature 39.5°C, slight aversion to wind and cold, nasal congestion with turbid discharge, red and swollen painful throat. Tongue: red tip with a thin yellow coating. Pulse: floating and rapid. Diagnosis: Wind-heat invading the lungs syndrome. Treatment principle: Dispel wind, clear heat, diffuse the lungs, and stop coughing. Prescription: Modified Yinqiao San.'),
    (5, 'Patient Liu, male, 50 years old. Recurrent epigastric bloating and pain for 3 years, worsened for 1 week. Symptoms: epigastric fullness, frequent belching, symptoms worsen with emotional fluctuations, and irregular bowel movements. Tongue: red with a thin yellow coating. Pulse: wiry. Diagnosis: Liver-stomach disharmony syndrome. Treatment principle: Soothe the liver, harmonize the stomach, regulate qi, and relieve pain. Prescription: Modified Chaihu Shugan San combined with Zuojin Wan.');
  2. Panggil model

    from maxframe.learn.contrib.llm.models.managed import ManagedTextLLM
    from pydantic import BaseModel
    from typing import List, Optional
    
    # 1. Gunakan model Qwen3-4B-Instruct-2507-FP8. 
    llm = ManagedTextLLM(name="Qwen3-4B-Instruct-2507-FP8")
    
    df = md.read_odps_table("traditional_chinese_medicine", index_col="index")
    
    # Empat partisi konkuren
    parallel_partitions = 4
    df = df.mf.rebalance(num_partitions=parallel_partitions)
    
    
    class MedicalRecord(BaseModel):
      """
        Skema terstruktur untuk catatan konsultasi pengobatan tradisional Tiongkok
      """
      patient_name: Optional[str] = None          # Nama pasien (misalnya, "Zhang")
      age: Optional[int] = None                   # Usia
      gender: Optional[str] = None                # Jenis kelamin ("Male"/"Female")
      chief_complaint: str                        # Keluhan utama
      symptoms: List[str]                         # Daftar gejala
      tongue: str                                 # Diagnosis lidah (misalnya, "Pale tongue with a white, greasy coating")
      pulse: str                                  # Diagnosis denyut nadi (misalnya, "Wiry and slippery pulse")
      diagnosis: str                              # Diagnosis sindrom TCM
      treatment_principle: str                    # Prinsip pengobatan
      prescription: str                           # Nama resep
    
    # Gunakan antarmuka task preset extract.  
    result_df = llm.extract(
      df["text"],
      description="Please extract structured data from the following consultation record in order. Return the result in a strict JSON format according to the schema.",
      schema=MedicalRecord
    )
    result_df.execute()
    
    result_df.to_odps_table("result").execute()

Manajemen resource dan optimasi kinerja

Kebijakan penjadwalan resource heterogen

MaxFrame mendukung dua jenis resource:

  • CU (Compute Unit): Resource komputasi CPU tujuan umum, cocok untuk model kecil dan tugas inferensi data skala kecil.

  • GU (GPU Unit): Resource komputasi GPU, dioptimalkan untuk inferensi model besar dan mendukung ukuran model yang lebih besar.

Untuk model besar, seperti 8B dan lebih besar, inferensi CPU kurang efisien. Anda dapat beralih ke resource komputasi GU untuk menjalankan inferensi.

Anda dapat memilih resource secara dinamis dengan mengonfigurasi session:

# Konfigurasikan penggunaan resource CU/GU.

# Gunakan resource komputasi CU.
options.session.quota_name = "mf_cpu_quota"

# Gunakan resource komputasi GU.
options.session.gu_quota_name = "mf_gpu_quota"

Inferensi paralel

MaxFrame menggunakan mekanisme komputasi paralel untuk melakukan inferensi offline pada data skala besar:

  1. Pemotongan data: Anda dapat menggunakan antarmuka rebalance untuk mendistribusikan data tabel input secara merata ke beberapa node pekerja berdasarkan jumlah partisi yang ditentukan (num_partitions).

  2. Pemuatan model paralel: Setiap pekerja memuat dan melakukan pra-ambil model secara independen untuk menghindari latensi cold start akibat pemuatan model.

  3. Agregasi hasil: Hasil output ditulis ke tabel MaxCompute berdasarkan partisi, mendukung analitik data selanjutnya.

Untuk pekerjaan inferensi data skala besar, Anda dapat menggunakan antarmuka rebalance untuk memotong data terlebih dahulu demi konkurensi. Hal ini memungkinkan pemrosesan data secara paralel.