評估您的訓練模型
評估配方是一種 YAML 組態檔案,可定義 Amazon Nova 模型評估任務的執行方式。使用此配方,您可以根據常見的基準或您自己的自訂資料集,來評估基礎或訓練模型的效能。指標可以存放在 Amazon S3 或 TensorBoard 中。評估會提供量化指標,協助您評估各種任務的模型效能,以判斷是否需要進一步自訂。
模型評估是一種離線程序,在程序中會根據具有預先定義的回答測試模型。系統不會即時或根據即時使用者互動來評估它們。對於即時評估,將模型部署到 Amazon Bedrock 之後,您可以透過呼叫 Amazon Bedrock 執行時期 API 來評估模型。
可用的基準任務
提供範例程式碼套件,示範如何使用 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 即評審偏好比較 – 使用 Nova Judge 模型來針對您的提示判斷配對回應 (B 與 A 比較) 之間的偏好,並計算較 A 偏好 B 的機率。 |
全部 |
評審 |
否 |
humaneval |
文字 |
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
-
humaneval
-
-
strategy:(必要) 定義評估方法:-
zs_cot:零樣本思緒鏈 - 一種可提示大型語言模型的方法,鼓勵逐步推理,而無需明確的範例。
-
zs:零樣本 - 一種無需任何先前訓練範例即可解決問題的方法。
-
gen_qa:使用自有資料集配方特定的策略。
-
評審:Amazon Nova LLM 即評審配方特定的策略。
-
-
subtask:(選用且可移除) 針對特定評估任務指定特定子任務。如果您的任務沒有任何子任務,請從配方中移除此項目。 -
metric:(必要) 要使用的評估指標。-
正確性:正確回答的百分比
-
exact_match:(對於
math基準) 會傳回輸入預測字串與其參考完全相符的比率。 -
偏轉:(對於
strong reject基準測試) 會將相對偏轉傳回基本模型和顯著性指標的差異。 -
pass@1:(對於
humaneval基準測試) 用來測量模型最高可信度預測符合正確回答之案例百分比的指標。 -
all:傳回下列指標:-
對於
gen_qa和使用自有資料集基準,這會傳回下列指標:-
rouge1:測量所產生文字和參考文字之間一元語法 (一個字) 的重疊。 -
rouge2:測量所產生文字和參考文字之間二元語法 (連續兩個字) 的重疊。 -
rougeL:測量文字之間最長的共同子序列,允許相符項目中的差距。 -
exact_match:二元分數 (0 或 1),指出產生的文字是否逐字元完全符合參考文字。 -
quasi_exact_match:類似於完全相符但更寬鬆,通常忽略大小寫、標點符號和空格差異。 -
f1_score:精確率和召回率的調和平均數,可測量預測回答和參考回答之間的字詞重疊。 -
f1_score_quasi:類似於 f1_score,但比對更寬鬆,使用會忽略次要差異的標準化文字比較。 -
bleu:測量所產生文字和參考文字之間 n 元語法比對的精確率,常用於轉譯評估。
-
-
對於
llm_judge和使用自有資料集基準,這會傳回下列指標:-
a_scores:跨向前和向後評估傳遞的response_A其獲勝次數。 -
a_scores_stderr:跨配對判斷的response_A scores其標準誤。 -
b_scores:跨向前和向後評估傳遞的response_B其獲勝次數。 -
b_scores_stderr:跨配對判斷的response_B scores其標準誤。 -
ties:將response_A和response_B評估為相等的判斷數目。 -
ties_stderr:跨配對判斷的繫結其標準誤。 -
inference_error:無法正確評估的判斷計數。 -
inference_error_stderr:跨判斷的推論錯誤其標準誤。 -
score:根據response_B其向前和向後傳遞中的獲勝來彙總分數。 -
score_stderr:跨配對判斷的彙總分數其標準誤。 -
winrate:使用 Bradley-Terry 機率計算將比 response_A 偏好 response_B 的機率。 -
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 訓練任務可存取它的 S3 位置。
-
檔案必須遵循一般問與答資料集所需的結構描述格式。
-
-
結構描述格式需求 - 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 即評審是一種模型評估功能,可讓客戶將一個模型的回應品質與自訂資料集上的基準模型回應進行比較。它會採用具有提示、基準回應和挑戰者回應的資料集,然後使用 Nova Judge 模型透過配對比較,以根據 Bradley-Terry 機率
配方會以 xxx_llm_judge_eval.yaml 格式提供。
以下是 LLM 即評審需求:
-
檔案格式需求
-
包含一個包含評估範例的
llm_judge.jsonl檔案。檔案名稱必須是llm_judge.jsonl。 -
您的資料集必須上傳至 SageMaker AI HyperPod RIG 可存取的 S3 位置。
-
檔案必須遵循
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-namecluster-name# Submit the Job using the recipe for eval # Namespace by default should be kubeflow hyperpod start-job [--namespacenamespace] --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 [--namespacenamespace] [--all-namespaces] # Getting Job details hyperpod get-job --job-namejob-name[--namespacenamespace] [--verbose] # Listing Pods hyperpod list-pods --job-namejob-name--namespacenamespace# Cancel Job hyperpod cancel-job --job-namejob-name[--namespacenamespace]
您也應能夠透過 Amazon EKS 叢集主控台檢視任務狀態。
存取和分析評估結果
評估任務成功完成後,您可以使用本節中的資訊來存取和分析結果。根據配方中定義的 output_s3_path (例如 s3://output_path/),輸出結構如下:
job_name/ ├── eval-result/ │ └── results_[timestamp].json │ └── inference_output.jsonl (only present for gen_qa) │ └── details/ │ └── model/ │ └── execution-date-time/ │ └──details_task_name_#_datetime.parquet └── tensorboard-results/ └── 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 中。
llm_judge 和 strong_reject 除外,所有的推論輸出都存放在 S3 路徑:s3://output_path/job_name/eval-result/details/model/taskname.parquet。
對於 gen_qa,inference_output.jsonl 檔案包含每個 JSON 物件的下列欄位:
-
提示 - 提交到模型的最終提示
-
推論 - 來自模型的原始推論輸出
若要在 Tensorboard 中視覺化您的評估指標,請完成下列步驟:
-
導覽至 SageMaker AI Tensorboard。
-
選取 S3 資料夾。
-
新增 S3 資料夾路徑,例如
s3://output_path/job-name/eval-tensorboard-result/eval。 -
等待同步完成
時間序列、純量和文字視覺化可供使用。
建議遵循下列最佳實務:
-
透過模型和基準類型讓輸出路徑井然有序。
-
維持一致的命名慣例,以便於追蹤。
-
將擷取的結果儲存在安全的位置。
-
監控 TensorBoard 同步狀態以成功載入資料。
您可以在 CloudWatch 日誌群組 /aws/sagemaker/Clusters/cluster-id 中找到 HyperPod 任務錯誤日誌。