評估您的訓練模型 - Amazon SageMaker AI

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

評估您的訓練模型

評估配方是一種 YAML 組態檔案,可定義 Amazon Nova 模型評估任務的執行方式。使用此配方,您可以根據常見的基準或您自己的自訂資料集來評估基礎或訓練模型的效能。指標可以存放在 Amazon S3 或 TensorBoard 中。評估提供量化指標,協助您評估各種任務的模型效能,以判斷是否需要進一步自訂。

模型評估是一種離線程序,其中針對具有預先定義答案的固定基準測試模型。它們不會即時或針對即時使用者互動進行評估。對於即時評估,您可以呼叫 Amazon Bedrock 執行時間 APIs,在模型部署到 Amazon Bedrock 之後對其進行評估。

可用的基準測試任務

提供範例程式碼套件,示範如何使用 Amazon Nova 的 SageMaker AI 模型評估功能來計算基準指標。若要存取程式碼套件,請參閱 sample-Nova-lighteval-custom-task

以下是支援、可用產業標準基準的清單。您可以在 eval_task 參數中指定下列基準:

Benchmark

模式

描述

指標

策略

可用的子任務

mmlu

文字

多任務語言理解 – 測試 57 個主題的知識。

正確性

zs_cot

mmlu_pro

文字

MMLU – 專業子集 – 專注於專業領域,例如法律、醫學、會計和工程。

正確性

zs_cot

bbh

文字

進階推理任務 – 一系列挑戰性問題,可測試高階認知和問題解決技能。

正確性

zs_cot

gpqa

文字

一般物理問題回答 – 評估對物理概念和相關問題解決能力的理解。

正確性

zs_cot

數學運算

文字

數學問題解決 – 測量各個主題的數學推理,包括代數、計算和單字問題。

exact_match

zs_cot

strong_reject

文字

品質控管任務 – 測試模型偵測和拒絕不適當、有害或不正確內容的能力。

偏轉

zs

IFEval

文字

指示追蹤評估 – 測量模型遵循指定指示的準確度,並根據規格完成任務。

正確性

zs

gen_qa

文字

自訂資料集評估 – 可讓您使用自己的資料集進行基準測試,將模型輸出與參考答案與 ROUGE 和 BLEU 等指標進行比較。

全部

gen_qa

mmmu

多模態

大規模多學科多模式理解 (MMMU) – 學院層級基準測試,包含來自 30 個學科的多選和開放式問題。

正確性

zs_cot

llm_judge

文字

LLM-as-a-Judge 偏好設定比較 – 使用 Nova Judge 模型來判斷您的提示配對回應之間的偏好設定 (B 相較於 A),計算 B 優於 A 的機率。

全部

判斷

人道

文字

HumanEval - 旨在評估大型語言模型程式碼產生功能的基準資料集

pass@1

zs

可使用下列mmlu子任務:

MMLU_SUBTASKS = [ "abstract_algebra", "anatomy", "astronomy", "business_ethics", "clinical_knowledge", "college_biology", "college_chemistry", "college_computer_science", "college_mathematics", "college_medicine", "college_physics", "computer_security", "conceptual_physics", "econometrics", "electrical_engineering", "elementary_mathematics", "formal_logic", "global_facts", "high_school_biology", "high_school_chemistry", "high_school_computer_science", "high_school_european_history", "high_school_geography", "high_school_government_and_politics", "high_school_macroeconomics", "high_school_mathematics", "high_school_microeconomics", "high_school_physics", "high_school_psychology", "high_school_statistics", "high_school_us_history", "high_school_world_history", "human_aging", "human_sexuality", "international_law", "jurisprudence", "logical_fallacies", "machine_learning", "management", "marketing", "medical_genetics", "miscellaneous", "moral_disputes", "moral_scenarios", "nutrition", "philosophy", "prehistory", "professional_accounting", "professional_law", "professional_medicine", "professional_psychology", "public_relations", "security_studies", "sociology", "us_foreign_policy", "virology", "world_religions" ]

可使用下列bbh子任務:

BBH_SUBTASKS = [ "boolean_expressions", "causal_judgement", "date_understanding", "disambiguation_qa", "dyck_languages", "formal_fallacies", "geometric_shapes", "hyperbaton", "logical_deduction_five_objects", "logical_deduction_seven_objects", "logical_deduction_three_objects", "movie_recommendation", "multistep_arithmetic_two", "navigate", "object_counting", "penguins_in_a_table", "reasoning_about_colored_objects", "ruin_names", "salient_translation_error_detection", "snarks", "sports_understanding", "temporal_sequences", "tracking_shuffled_objects_five_objects", "tracking_shuffled_objects_seven_objects", "tracking_shuffled_objects_three_objects", "web_of_lies", "word_sorting" ]

可使用下列math子任務:

MATH_SUBTASKS = [ "algebra", "counting_and_probability", "geometry", "intermediate_algebra", "number_theory", "prealgebra", "precalculus", ]

了解配方參數

執行組態

以下是一般執行組態和所涉及參數的說明。

run: name: eval_job_name model_type: amazon.nova-micro-v1:0:128k model_name_or_path: nova-micro/prod replicas: 1 data_s3_path: "" output_s3_path: s3://output_path
  • name:(必要) 評估任務的描述性名稱。這有助於在 AWS 主控台中識別您的任務。

  • model_type:(必要) 指定要使用的 Amazon Nova 模型變體。請勿手動修改此欄位。選項包括:

    • amazon.nova-micro-v1:0:128k

    • amazon.nova-lite-v1:0:300k

    • amazon.nova-pro-v1:0:300k

  • model_name_or_path:(必要) 基礎模型的路徑或訓練後檢查點的 S3 路徑。選項包括:

    • nova-micro/prod

    • nova-lite/prod

    • nova-pro/prod

    • (訓練後檢查點的 S3 路徑) s3://<escrow bucket>/<job id>/outputs/checkpoints

  • replicas:(必要) 用於分散式訓練的運算執行個體數量。您必須將此值設定為 1,因為不支援多節點。

  • data_s3_path:(必要) 輸入資料集的 S3 路徑。除非您使用 將自己的資料集LLM 做為判斷配方,否則請將此參數保留空白。

  • output_s3_path:(必要) 存放輸出評估成品的 S3 路徑。請注意,輸出 S3 儲存貯體必須由建立任務的相同帳戶建立。

評估組態

以下是模型評估組態,以及所涉及參數的說明。

evaluation: task: mmlu strategy: zs_cot subtask: mathematics metric: accuracy
  • task:(必要) 指定要使用的評估基準或任務。

    支援的任務清單:

    • mmlu

    • mmlu_pro

    • bbh

    • gpqa

    • 數學運算

    • strong_reject

    • gen_qa

    • ifeval

    • mmmu

    • llm_judge

    • 人道

  • strategy:(必要) 定義評估方法:

    • zs_cot:Zero-shot Chain-of-Thought - 一種提示大型語言模型的方法,可鼓勵step-by-step推理,而無需明確的範例。

    • zs:零鏡頭 - 一種無需任何先前訓練範例即可解決問題的方法。

    • gen_qa:一種策略,專用於使用您自己的資料集配方。

    • 判斷:Amazon Nova LLM 作為判斷配方的特定策略。

  • subtask:(選用和可移除) 指定特定評估任務的特定子任務。如果您的任務沒有任何子任務,請從配方中移除此項目。

  • metric:(必要) 要使用的評估指標。

    • 準確度:正確答案的百分比

    • exact_match:(對於math基準測試), 會傳回輸入預測字串與其參考完全相符的速率。

    • 偏轉:(對於strong reject基準測試), 會將相對偏轉傳回基礎模型和顯著性指標的差異。

    • pass@1: (針對humaneval基準測試) 是用來測量模型最高可信度預測符合正確答案之案例百分比的指標。

    • all:傳回下列指標:

      • 對於 gen_qa和 使用您自己的資料集基準,請傳回下列指標:

        • rouge1:測量所產生和參考文字之間的單文 (單字) 重疊。

        • rouge2:測量所產生和參考文字之間的 Bigrams (連續兩個字) 重疊。

        • rougeL:測量文字之間的最長常見子序列,允許相符項目中的差距。

        • exact_match:二進位分數 (0 或 1),指出產生的文字是否完全符合參考文字,依字元表示。

        • quasi_exact_match:類似於完全相符但更寬鬆,通常忽略大小寫、標點符號和空格差異。

        • f1_score:精確度和取回的諧波平均值,測量預測和參考答案之間的字詞重疊。

        • f1_score_quasi:類似於 f1_score,但具有更寬鬆的比對,使用忽略次要差異的標準化文字比較。

        • bleu:測量所產生和參考文字之間 n-gram 相符項目的精確度,常用於轉譯評估。

      • 對於 llm_judge和 使用您自己的資料集基準,請傳回下列指標:

        • a_scoresresponse_A跨向前和向後評估通過的 獲勝次數。

        • a_scores_stderrresponse_A scores跨配對判斷的標準錯誤。

        • b_scoresresponse_B跨向前和向後評估通過的 獲勝次數。

        • b_scores_stderrresponse_B scores跨配對判斷的標準錯誤。

        • ties:將 response_A和 評估為相等response_B的判斷數目。

        • ties_stderr:跨成對判斷的關聯標準錯誤。

        • inference_error:無法正確評估的判斷計數。

        • inference_error_stderr:跨判斷推論錯誤的標準錯誤。

        • score:根據 向前和向後通過中獲勝的彙總分數response_B

        • score_stderr:跨配對判斷彙總分數的標準錯誤。

        • winrate:Response_B 將優先於 response_A 的概率,此概率會使用 Bradley-Terry 概率計算。

        • lower_rate:從引導取樣估計勝率的下限 (第 2.5 個百分位數)。

推論組態

以下是推論組態和所涉及參數的說明。所有參數都是選用的。

inference: max_new_tokens: 200 top_k: -1 top_p: 1.0 temperature: 0
  • max_new_tokens:要產生的字符數目上限。這必須是整數。

  • top_k:要考慮的最高機率字符數量。這必須是整數。

  • top_p:字符抽樣的累積機率閾值。這必須是介於 0.0 和 1.0 之間的浮點數,包括在內。

  • temperature:字符選擇中的隨機性。較大的值會帶來更多隨機性。使用 0 讓結果具有決定性。此值必須是最小值為 0 的浮點數。

請注意,對於 humaneval,我們建議使用下列推論組態:

inference: top_k: 1 max_new_tokens: 1600 temperature: 0.0

評估配方範例

Amazon Nova 提供四種類型的評估配方,可在 HyperPod 配方 GitHub 儲存庫中找到。

一般文字基準配方

這些配方可讓您在一套完整的純文字基準中評估 Amazon Nova 模型的基本功能。它們會以 格式提供xxx_general_text_benchmark_eval.yaml

一般多模態基準配方

這些配方可讓您跨多模態基準的完整套件評估 Amazon Nova 模型的基本功能。它們會以 格式提供xxx_general_multi_modal_benchmark_eval.yaml

使用您自己的資料集基準配方

這些配方可讓您使用自己的資料集進行基準測試,並使用不同類型的指標比較模型輸出以參考答案。它們會以 格式提供xxx_bring_your_own_dataset_eval.yaml

以下是使用您自己的資料集需求:

  • 檔案格式需求

    • 您必須包含包含評估範例的單一gen_qa.jsonl檔案。

    • 您的資料集必須上傳至 SageMaker AI 訓練任務可存取的 SS3 位置。

    • 檔案必須遵循一般 Q&A 資料集所需的結構描述格式。

  • 結構描述格式要求 - JSONL 檔案中的每一行都必須是具有下列欄位的 JSON 物件:

    • query:(必要) 字串,其中包含需要答案的問題或指示

    • response:(必要) 包含預期模型輸出的字串

    • system:(選用) 包含系統提示的字串,在處理查詢之前設定 AI 模型的行為、角色或身分

以下是自備的資料集範例項目

{ "system":"You are a english major with top marks in class who likes to give minimal word responses: ", "query":"What is the symbol that ends the sentence as a question", "response":"?" } { "system":"You are a pattern analysis specialist that provides succinct answers: ", "query":"What is the next number in this series? 1, 2, 4, 8, 16, ?", "response":"32" } { "system":"You have great attention to detail that follows instructions accurately: ", "query":"Repeat only the last two words of the following: I ate a hamburger today and it was kind of dry", "response":"of dry" }

若要使用您的自訂資料集,請使用下列必要欄位修改您的評估配方,請勿變更任何內容:

evaluation: task: gen_qa strategy: gen_qa metric: all

有下列限制:

  • 每次評估僅允許一個 JSONL 檔案。

  • 檔案必須嚴格遵循定義的結構描述。

  • 內容長度限制:對於資料集中的每個範例,內容長度 (包括系統 + 查詢提示) 應小於 3.5k

Amazon Nova LLM 作為判斷基準配方

Amazon Nova LLM as a Judge 是一種模型評估功能,可讓客戶將一個模型的回應品質與自訂資料集上的基準模型回應進行比較。它會採用具有提示、基準回應和挑戰者回應的資料集,並使用 Nova Judge 模型,根據 Bradley-Terry 機率和配對比較提供勝率指標。

配方會以 格式提供xxx_llm_judge_eval.yaml

以下是 LLM 做為判斷要求:

  • 檔案格式需求

    • 包含包含評估範例的單一llm_judge.jsonl檔案。檔案名稱必須為 llm_judge.jsonl

    • 您的資料集必須上傳至 SageMaker AI HyperPod RIG 可存取的 S HyperPodS3 位置。

    • 檔案必須遵循llm_judge.jsonl資料集所需的結構描述格式。

    • 輸入資料集應確保所有記錄都低於 12k 內容長度。

  • 結構描述格式要求 - JSONL 檔案中的每一行都必須是具有下列欄位的 JSON 物件:

    • prompt:(必要) 包含所產生回應提示的字串。

    • response_A:包含基準回應的字串。

    • response_B:包含替代回應的字串會與基準回應進行比較。

以下是做為判斷範例項目的 LLM

{ "prompt": "What is the most effective way to combat climate change?", "response_A": "The most effective way to combat climate change is through a combination of transitioning to renewable energy sources and implementing strict carbon pricing policies. This creates economic incentives for businesses to reduce emissions while promoting clean energy adoption.", "response_B": "We should focus on renewable energy. Solar and wind power are good. People should drive electric cars. Companies need to pollute less." } { "prompt": "Explain how a computer's CPU works", "response_A": "CPU is like brain of computer. It does math and makes computer work fast. Has lots of tiny parts inside.", "response_B": "A CPU (Central Processing Unit) functions through a fetch-execute cycle, where instructions are retrieved from memory, decoded, and executed through its arithmetic logic unit (ALU). It coordinates with cache memory and registers to process data efficiently using binary operations." } { "prompt": "How does photosynthesis work?", "response_A": "Plants do photosynthesis to make food. They use sunlight and water. It happens in leaves.", "response_B": "Photosynthesis is a complex biochemical process where plants convert light energy into chemical energy. They utilize chlorophyll to absorb sunlight, combining CO2 and water to produce glucose and oxygen through a series of chemical reactions in chloroplasts." }

若要使用您的自訂資料集,請使用下列必要欄位修改您的評估配方,請勿變更任何內容:

evaluation: task: llm_judge strategy: judge metric: all

有下列限制:

  • 每次評估僅允許一個 JSONL 檔案。

  • 檔案必須嚴格遵循定義的結構描述。

  • Amazon Nova Judge 模型在所有模型系列規格中都相同 (即 Lite、Micro 和 Pro)。

  • 目前不支援自訂判斷模型。

  • 內容長度限制:對於資料集中的每個範例,內容長度 (包括系統 + 查詢提示) 應小於 7k

啟動評估任務

以下提供建議的評估執行個體類型和模型類型組態:

# Install Dependencies (Helm - https://helm.sh/docs/intro/install/) curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 chmod 700 get_helm.sh ./get_helm.sh rm -f ./get_helm.sh # Install the HyperPod CLI git clone --recurse-submodules https://github.com/aws/sagemaker-hyperpod-cli.git git checkout -b release_v2 cd sagemaker-hyperpod-cli pip install . # Verify the installation hyperpod --help # Connect to a HyperPod Cluster hyperpod connect-cluster --cluster-name cluster-name # Submit the Job using the recipe for eval # Namespace by default should be kubeflow hyperpod start-job [--namespace namespace] --recipe evaluation/nova/nova_micro_p5_48xl_general_text_benchmark_eval --override-parameters \ '{ "instance_type":"p5d.48xlarge", "container": "708977205387.dkr.ecr.us-east-1.amazonaws.com/nova-evaluation-repo:SM-HP-Eval-latest", "recipes.run.name": custom-run-name, "recipes.run.model_type": model_type, "recipes.run.model_name_or_path" " model name or finetune checkpoint s3uri, "recipes.run.data_s3_path": s3 for input data only for genqa and llm_judge, must be full S3 path that include filename, }' # List jobs hyperpod list-jobs [--namespace namespace] [--all-namespaces] # Getting Job details hyperpod get-job --job-name job-name [--namespace namespace] [--verbose] # Listing Pods hyperpod list-pods --job-name job-name --namespace namespace # Cancel Job hyperpod cancel-job --job-name job-name [--namespace namespace]

您也應該能夠透過 Amazon EKS 叢集主控台檢視任務狀態。

存取並視覺化您的結果

評估任務成功完成後,您可以使用本節中的資訊來存取和分析結果。根據配方中定義的 output_s3_path(例如 s3://output_path/),輸出結構如下:

job_name/ ├── eval-result/ │ └── job-name/ │ └── results_[timestamp].json │ └── details/ │ └── model/ │ └── execution-date-time/ │ └──details_task_name_#_datetime.parquet └── eval-tensorboard-result/ └── job-name/ └── eval/ └── events.out.tfevents.[timestamp]

指標結果會存放在指定的 S3 輸出位置 s3://output_path/job_name/eval-result/result-timestamp.json

Tensorboard 結果會儲存在 S3 路徑 中s3://output_path/job_name/eval-tensorboard-result/eval/event.out.tfevents.epoch+ip

預期 strong_reject和 的推論輸出gen_qa會存放在 S3 路徑 中s3://output_path/job_name/eval-result/details/model/taskname.parquet

若要在 Tensorboard 中視覺化您的評估指標,請完成下列步驟:

  1. 導覽至 SageMaker AI Tensorboard。

  2. 選取 S3 資料夾

  3. 新增 S3 資料夾路徑,例如 s3://output_path/job-name/eval-tensorboard-result/eval

  4. 等待同步完成。

時間序列、純量和文字視覺化可供使用。

建議遵循下列最佳實務:

  • 依模型和基準類型整理輸出路徑。

  • 維持一致的命名慣例,以便於追蹤。

  • 將擷取的結果儲存在安全的位置。

  • 監控 TensorBoard 同步狀態以成功載入資料。

您可以在 CloudWatch 日誌群組 中找到 HyperPod 任務錯誤日誌/aws/sagemaker/Clusters/cluster-id