View a markdown version of this page

SageMaker HyperPod 上的 Nova 2.0 強化微調 (RFT) - Amazon Nova

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

SageMaker HyperPod 上的 Nova 2.0 強化微調 (RFT)

本節涵蓋範例配方、開始微調任務、超參數指引,以及 SageMaker HyperPod 上 Nova 2.0 Lite 上 RFT 的訓練監控。如需準備 RFT 訓練資料的資料格式、支援的功能、限制條件和最佳實務的相關資訊,請參閱 在 Amazon Nova 2 上準備 RFT 的資料

若要判斷 RFT 是否適合您的使用案例,請參閱 強化微調 (RFT)

# Note: # This recipe can run on p5.48xlarge, p5e.48xlarge, and p5en.48xlarge instance types. run: name: "my-rft-run" # Unique run name (appears in logs and artifacts). model_type: amazon.nova-2-lite-v1:0:256k model_name_or_path: nova-lite-2/prod data_s3_path: s3://<bucket>/<data-file> # Training dataset in JSONL format. replicas: 4 # Number of total training instances. generation_replicas: 2 # Number of total instances dedicated to response generation. reward_lambda_arn: arn:aws:lambda:<region>:<account-id>:function:<function-name> ## MLFlow configs mlflow_tracking_uri: "" # Required for MLFlow mlflow_experiment_name: "my-rft-experiment" # Optional for MLFlow. Note: leave this field non-empty mlflow_run_name: "my-rft-run" # Optional for MLFlow. Note: leave this field non-empty ## SMHP RFT training configs training_config: max_length: 8192 # Context window (tokens) for inputs and prompt. global_batch_size: 32 # Total samples per optimizer step across all replicas (16/32/64/128/256). reasoning_effort: high # Reasoning mode: high, low, or null for non-reasoning. data: shuffle: true # Shuffle training data each epoch. rollout: # Controls how responses are generated for advantage calculation. rollout_strategy: type: off_policy_async # Asynchronous rollout for higher throughput. age_tolerance: 2 # Maximum policy age before regeneration. advantage_strategy: number_generation: 4 # Samples per prompt to estimate advantages (higher = lower variance but higher cost). generator: max_new_tokens: 6000 # Cap on tokens generated per sample. set_random_seed: true # Seed generation for reproducibility across runs. temperature: 1 # Softmax temperature for sampling. top_k: 1 # Sample only from top-K logits. rewards: preset_reward_function: null # Preset reward functions: exact_match or null for custom. api_endpoint: lambda_arn: arn:aws:lambda:<region>:<account-id>:function:<function-name> lambda_concurrency_limit: 12 # Max concurrent Lambda invocations (throughput vs. throttling). lambda_batch_size: 128 # Number of samples per Lambda invocation. trainer: max_steps: 2 # Steps to train for. One step = global_batch_size samples. save_steps: 5 # Save a checkpoint every N steps. test_steps: 1 # Run validation every N reference model updates. refit_freq: 4 # Frequency of reference model updates. clip_ratio_high: 0.2 # PPO clip ratio for policy updates. loss_scale: 1.0 # Scaling factor for the policy loss. # RL parameters ent_coeff: 0.0 # Entropy bonus added to the policy loss (higher = more exploration). kl_loss_coef: 0.0 # Weight on the KL penalty between the current and reference policy. optim_config: # Optimizer settings. lr: 1e-6 # Learning rate. weight_decay: 0.0 # L2 regularization strength (0.0 to 1.0). adam_beta1: 0.9 adam_beta2: 0.95 peft: # Parameter-efficient fine-tuning (LoRA). peft_scheme: "lora" # Enable LoRA for PEFT. lora_tuning: alpha: 64 # LoRA scaling factor. lora_plus_lr_ratio: 64.0 # LoRA+ learning rate scaling factor (0.0 to 100.0).

在 SageMaker HyperPod 上啟動微調任務

準備您的資料

如需準備 RFT 訓練資料的資料格式、支援的功能、限制條件和最佳實務的相關資訊,請參閱 在 Amazon Nova 2 上準備 RFT 的資料

上傳資料

將訓練資料集上傳至 S3 儲存貯體。在配方的 run 區塊中指定其位置:

## Run config run: ... data_s3_path: "s3://<bucket-name>/<training-directory>/<training-file>.jsonl"
注意

<bucket-name><training-directory>和 取代<training-file>為實際的 S3 路徑。

定義您的組態

使用 run 區塊中的 model_typemodel_name_or_path 欄位來定義基本模型:

## Run config run: ... model_type: amazon.nova-2-lite-v1:0:256k model_name_or_path: nova-lite-2/prod ...

超參數指引

根據您的訓練方法,使用以下建議的超參數:

一般:

  • Epochs:1

  • 學習率 (lr):1e-7

  • 世代數:8

  • 最大新權杖數:8192

  • 批次大小:256

LoRA (低排名調適):

  • LoRA 排名:32

注意

根據您的資料集大小和驗證效能調整這些值。監控訓練指標以防止過度擬合。