forked from aws/sagemaker-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rlaif_trainer_integration.py
More file actions
144 lines (116 loc) · 5.55 KB
/
Copy pathtest_rlaif_trainer_integration.py
File metadata and controls
144 lines (116 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""Integration tests for RLAIF trainer"""
from __future__ import absolute_import
import time
import random
import boto3
from sagemaker.core.helper.session_helper import Session
from sagemaker.train.rlaif_trainer import RLAIFTrainer
from sagemaker.train.common import TrainingType
import pytest
def test_rlaif_trainer_lora_complete_workflow(sagemaker_session):
"""Test complete RLAIF training workflow with LORA."""
unique_id = f"{int(time.time())}-{random.randint(1000, 9999)}"
rlaif_trainer = RLAIFTrainer(
model="meta-textgeneration-llama-3-2-1b-instruct",
training_type=TrainingType.LORA,
model_package_group="sdk-test-finetuned-models",
reward_model_id='openai.gpt-oss-120b-1:0',
reward_prompt='Builtin.Summarize',
mlflow_experiment_name="test-rlaif-finetuned-models-exp",
mlflow_run_name="test-rlaif-finetuned-models-run",
training_dataset="s3://mc-flows-sdk-testing/input_data/rlvr-rlaif-test-data/train_285.jsonl",
s3_output_path="s3://mc-flows-sdk-testing/output/",
accept_eula=True,
base_job_name=f"rlaif-lora-integ-{unique_id}",
)
# Create training job
training_job = rlaif_trainer.train(wait=False)
# Manual wait loop to avoid resource_config issue
max_wait_time = 3600 # 1 hour timeout
poll_interval = 30 # Check every 30 seconds
start_time = time.time()
while time.time() - start_time < max_wait_time:
training_job.refresh()
status = training_job.training_job_status
if status in ["Completed", "Failed", "Stopped"]:
break
time.sleep(poll_interval)
# Verify job completed successfully
assert training_job.training_job_status == "Completed"
assert hasattr(training_job, 'output_model_package_arn')
assert training_job.output_model_package_arn is not None
def test_rlaif_trainer_with_custom_reward_settings(sagemaker_session):
"""Test RLAIF trainer with different reward model and prompt."""
unique_id = f"{int(time.time())}-{random.randint(1000, 9999)}"
rlaif_trainer = RLAIFTrainer(
model="meta-textgeneration-llama-3-2-1b-instruct",
training_type=TrainingType.LORA,
model_package_group="sdk-test-finetuned-models",
reward_model_id='openai.gpt-oss-120b-1:0',
reward_prompt="arn:aws:sagemaker:us-west-2:729646638167:hub-content/sdktest/JsonDoc/rlaif-test-prompt/0.0.1",
mlflow_experiment_name="test-rlaif-finetuned-models-exp",
mlflow_run_name="test-rlaif-finetuned-models-run",
training_dataset="s3://mc-flows-sdk-testing/input_data/rlvr-rlaif-test-data/train_285.jsonl",
s3_output_path="s3://mc-flows-sdk-testing/output/",
accept_eula=True,
base_job_name=f"rlaif-rwd-integ-{unique_id}",
)
training_job = rlaif_trainer.train(wait=False)
# Manual wait loop
max_wait_time = 3600
poll_interval = 30
start_time = time.time()
while time.time() - start_time < max_wait_time:
training_job.refresh()
status = training_job.training_job_status
if status in ["Completed", "Failed", "Stopped"]:
break
time.sleep(poll_interval)
# Verify job completed successfully
assert training_job.training_job_status == "Completed"
assert hasattr(training_job, 'output_model_package_arn')
assert training_job.output_model_package_arn is not None
def test_rlaif_trainer_continued_finetuning(sagemaker_session):
"""Test complete RLAIF training workflow with LORA."""
unique_id = f"{int(time.time())}-{random.randint(1000, 9999)}"
rlaif_trainer = RLAIFTrainer(
model="arn:aws:sagemaker:us-west-2:729646638167:model-package/sdk-test-finetuned-models/1",
training_type=TrainingType.LORA,
model_package_group="sdk-test-finetuned-models",
reward_model_id='openai.gpt-oss-120b-1:0',
reward_prompt='Builtin.Summarize',
mlflow_experiment_name="test-rlaif-finetuned-models-exp",
mlflow_run_name="test-rlaif-finetuned-models-run",
training_dataset="s3://mc-flows-sdk-testing/input_data/rlvr-rlaif-test-data/train_285.jsonl",
s3_output_path="s3://mc-flows-sdk-testing/output/",
accept_eula=True,
base_job_name=f"rlaif-cont-integ-{unique_id}",
)
# Create training job
training_job = rlaif_trainer.train(wait=False)
# Manual wait loop to avoid resource_config issue
max_wait_time = 3600 # 1 hour timeout
poll_interval = 30 # Check every 30 seconds
start_time = time.time()
while time.time() - start_time < max_wait_time:
training_job.refresh()
status = training_job.training_job_status
if status in ["Completed", "Failed", "Stopped"]:
break
time.sleep(poll_interval)
# Verify job completed successfully
assert training_job.training_job_status == "Completed"
assert hasattr(training_job, 'output_model_package_arn')
assert training_job.output_model_package_arn is not None