This topic describes how to use the MaxFrame AI Function in Alibaba Cloud MaxCompute and provides use cases to help you get started with offline inference applications for large models.
Function overview
The MaxFrame AI Function is an end-to-end solution on the Alibaba Cloud MaxCompute platform for large model offline inference. It seamlessly integrates data processing with AI capabilities, making large model intelligence accessible on big data platforms. This integration simplifies data processing workflows, improves result quality, lowers the barrier for using AI in data analytics, and streamlines the development of enterprise-level large model applications.
Design philosophy: "Data as input, data as output." You can use the MaxFrame Python development framework and Pandas-style APIs to complete the entire workflow within the MaxCompute ecosystem. This workflow includes data preparation, data processing, model inference, and result storage.
Core features:
Massive data processing: Process large volumes of structured data, such as logs for analysis or user behavior data, and unstructured data, such as text for translation or document summaries. You can process petabytes of data in a single task.
Low latency and linear scaling: Achieves low latency and linear scaling through a distributed computing architecture.
Large model integration: MaxFrame provides out-of-the-box support for large model series such as
Qwen 3,Qwen 2.5, andDeepseek-R1-Distill-Qwen. The models are hosted offline within the MaxCompute platform, so you do not need to worry about model downloads, distribution, or API call concurrency limits. You can call the models using an API. This lets you fully use the massive computing resources of MaxCompute to complete text processing tasks with high overall token throughput and concurrency.
Application scenarios: You can use it for various tasks, such as extracting structured information from text, summarizing content, generating abstracts, translating languages, assessing text quality, and classifying sentiment. This greatly simplifies large model data processing workflows and improves the quality of the results.
Summary of advantages:
Dimension
MaxFrame AI Function
Ease of use
Familiar Python APIs, an out-of-the-box model library, and zero deployment costs.
Extensibility
Relies on MaxCompute CU and GU compute resources to support massively parallel processing and improve overall token throughput.
Data and AI integration
Read data, process data, perform AI inference, and store results on a unified platform. This reduces data migration costs and improves development efficiency.
Scenario coverage
Covers more than ten high-frequency scenarios, such as translation, structured extraction, and vectorization.
Overall architecture
The MaxFrame AI Function provides flexible
generateinterfaces, allowing you to select a model type and use MaxCompute tables and Prompts as input parameters.When the interface is executed, MaxFrame first chunks the table data. It then sets an appropriate level of concurrency based on the data volume and starts a worker group to run the computing tasks. Each worker uses the prompt parameters you provide as a template. It renders the input data rows to build the model input. The inference results and success status are then written to MaxCompute.
The following figure shows the overall architecture and process.

Scope
Supported regions:
China (Hangzhou), China (Shanghai), China (Beijing), China (Ulanqab), China (Shenzhen), China (Chengdu), China (Hong Kong), China (Hangzhou) Finance Cloud, China (Shenzhen) Finance Cloud, Singapore, and Indonesia (Jakarta).
Supported Python version: Python 3.11.
Supported SDK version: MaxFrame SDK V2.3.0 or later. You can run the following command to check your version:
// Windows pip list | findstr maxframe // Linux pip list | grep maxframeIf your version is earlier than required, run the following command to install the latest version:
pip install --upgrade maxframeYou have installed the latest MaxFrame client.
Model support system
MaxFrame offers out-of-the-box support for large model series such as Qwen 3, Qwen 2.5, and Deepseek-R1-Distill-Qwen. All models are hosted offline within the MaxCompute platform. You do not need to worry about model downloads, distribution, or API call concurrency limits. You can call the models using an API to run offline inference tasks on large models. This lets you fully use the massive computing resources of MaxCompute for high overall token throughput and concurrency.
Qwen 3 series: An inference-optimized version based on the Qwen 3 model. It supports multilingual translation, complex text generation, and code generation tasks. It is suitable for scenarios that require high-precision output.
Qwen Embedding model: Designed for vectorization tasks. It supports efficient conversion of text to vectors and is suitable for scenarios such as semantic search and similarity matching.
Deepseek-R1-Distill-Qwen series: A lightweight model compressed using knowledge distillation. It is suitable for fast inference in resource-constrained environments.
Start with a smaller model. If the output does not meet your expectations, switch to a larger model. Larger models consume more resources and require longer processing times. Prioritizing smaller models can improve efficiency and reduce costs while still meeting your output requirements.
Supported Models (Continuously Updated)
Model type | Model name | Supported resource type |
Qwen 3 series models |
| CU |
| GU | |
Qwen Embedding models |
| CU |
| GU | |
Qwen 2.5 text series models |
| CU |
Deepseek-R1-Distill-Qwen series models |
| CU |
Deepseek-R1-0528-Qwen3 model |
| CU |
Interface description
The MaxFrame AI Function provides a balance of flexibility and ease of use through its generate and Task dual interfaces:
General-purpose interface: generate
This interface supports custom prompt templates and parameter settings. It is suitable for scenarios that require a high degree of control over the inference logic. For example:
from maxframe.learn.contrib.llm.models.managed import ManagedTextLLM
llm = ManagedTextLLM(name="<model_name>")
# Prompt template
messages = [
{"role": "system", "content": "system_messages"},
{"role": "user", "content": "user_messages"},
]
result_df = llm.generate(<df> , prompt_template=messages)
print(result_df.execute())
Parameters:
model_name: Required. The name of the model.
df: Required. The text or data to be analyzed, encapsulated in a DataFrame.
prompt_template: Required. A list of messages compatible with the OpenAI Chat format. In the content, you can use an
f-stringto reference the content of a table column.
Scenario-specific interface: Task - Supported only by GU compute resources
This interface provides preset, standardized task interfaces to simplify development for common scenarios. Currently supported task interfaces include translate and extract.
from maxframe.learn.contrib.llm.models.managed import ManagedTextLLM
llm = ManagedTextLLM(name="<model_name>")
# Text translation
translated_df = llm.translate(
df["english_column"],
source_language="english",
target_language="Chinese",
examples=[("Hello", "你好"), ("Goodbye", "再见")],
)
translated_df.execute()Example
If this is your first time using MaxFrame for data processing, see Get started with MaxFrame to learn about its features.
This example runs in local mode. The following code shows the complete script and its description:
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. Create a session using the MaxFrame SDK.
session = new_session(odps_entry=o)
# Do not truncate column text to display the full content.
pd.set_option("display.max_colwidth", None)
# Display all columns to prevent middle columns from being omitted.
pd.set_option("display.max_columns", None)
# 2. Import a DataFrame and create five questions.
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. Create a ManagedTextLLM object and specify qwen3-14b as the model to use.
llm = ManagedTextLLM(name="qwen3-14b")
# 4. Define a prompt template that includes a system message and a user message.
# In the user message, reserve the variable {query} in f-string format. This placeholder will be replaced with the content from the query column of the DataFrame. Placeholders support using multiple columns from the DataFrame, all referenced by their corresponding column names.
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Please answer the following question: {query}"},
]
# 5. Call the generate method on the LLM object. Pass the DataFrame and the prompt template to get an answer for each question.
result_df = llm.generate(df, prompt_template=messages)
# 6. Use execute to trigger the calculation for the resulting DataFrame.
# All calculations will occur on the MaxCompute cluster. The input DataFrame will be automatically sharded and processed in parallel based on the scale of the computation.
print(result_df.execute())
The following result is returned:
Row number | response_json | success |
0 |
| True |
1 |
| True |
2 |
| True |
3 |
| True |
4 |
| True |
Application scenario 1: Language translation
Scenario description: A multinational corporation needs to translate 100,000 English contracts into Chinese and annotate key clauses.
The following is the sample code:
Sample data
CREATE TABLE IF NOT EXISTS raw_contracts ( id BIGINT, en STRING ); -- Insert sample data. 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.');Call the model
from maxframe.learn.contrib.llm.models.managed import ManagedTextLLM # 1. Use the Qwen3 1.7B model. llm = ManagedTextLLM(name="Qwen3-1.7B") # 2. Prepare the data. You must first create the MaxCompute table raw_contracts and prepare the data to be translated. df = md.read_odps_table("raw_contracts") # 3. Define the prompt template. 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. Use the `generate` interface directly, define the prompt, and reference the corresponding data column. result_df = llm.generate( df, prompt_template=messages, params={ "temperature": 0.7, "top_p": 0.8, }, ).execute() # 5. Write the result data to a MaxCompute table. result_df.to_odps_table("raw_contracts_result").execute()The following result is returned:
+------------+------------+---------+ | 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 | +------------+------------+---------+
Application scenario 2: Keyword extraction
Scenario description: This scenario demonstrates the capability of the MaxFrame AI Function to process unstructured data. Text and images, which make up a large portion of unstructured data, present significant challenges for big data analytics. The following example shows how to use the AI Function to simplify this process.
The following code demonstrates how to use AI Function to fetch a candidate's work experience from a resume with randomly generated text.
The following is the sample code:
Sample data
CREATE TABLE IF NOT EXISTS traditional_chinese_medicine ( index BIGINT, text STRING ); -- Insert sample data. 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.');Call the model
from maxframe.learn.contrib.llm.models.managed import ManagedTextLLM from pydantic import BaseModel from typing import List, Optional # 1. Use the Qwen3-4B-Instruct-2507-FP8 model. llm = ManagedTextLLM(name="Qwen3-4B-Instruct-2507-FP8") df = md.read_odps_table("traditional_chinese_medicine", index_col="index") # Four concurrent partitions parallel_partitions = 4 df = df.mf.rebalance(num_partitions=parallel_partitions) class MedicalRecord(BaseModel): """ Structured schema for a traditional Chinese medicine consultation record """ patient_name: Optional[str] = None # Patient's name (e.g., "Zhang") age: Optional[int] = None # Age gender: Optional[str] = None # Gender ("Male"/"Female") chief_complaint: str # Chief complaint symptoms: List[str] # List of symptoms tongue: str # Tongue diagnosis (e.g., "Pale tongue with a white, greasy coating") pulse: str # Pulse diagnosis (e.g., "Wiry and slippery pulse") diagnosis: str # TCM syndrome diagnosis treatment_principle: str # Treatment principle prescription: str # Prescription name # Use the extract preset task interface. 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()
Resource management and performance optimization
Heterogeneous resource scheduling policy
MaxFrame supports two types of resources:
CU (Compute Unit): General-purpose CPU compute resources, suitable for small models and small-scale data inference tasks.
GU (GPU Unit): GPU compute resources, optimized for large model inference and supporting larger model sizes.
For large models, such as 8B and larger, CPU inference is less efficient. You can switch to GU compute resources to run inference.
You can dynamically select resources by configuring the session:
# Configure the use of CU/GU resources.
# Use CU compute resources.
options.session.quota_name = "mf_cpu_quota"
# Use GU compute resources.
options.session.gu_quota_name = "mf_gpu_quota"
Parallel inference
MaxFrame uses a parallel computing mechanism to perform offline inference on large-scale data:
Data chunking: You can use the
rebalanceinterface to evenly distribute the input data table to multiple worker nodes based on the specified number of partitions (num_partitions).Parallel model loading: Each worker independently loads and prefetches the model to avoid cold start latency caused by model loading.
Result aggregation: The output results are written to a MaxCompute table by partition, supporting subsequent data analytics.
For large-scale data inference jobs, you can use the rebalance interface to pre-chunk the data for concurrency. This enables parallel processing of the data.