@@ -2125,12 +2125,18 @@ def test_tune_chat_model(
2125
2125
):
2126
2126
model = language_models .ChatModel .from_pretrained ("chat-bison@001" )
2127
2127
2128
+ tuning_job_location = "europe-west4"
2129
+ tensorboard_name = f"projects/{ _TEST_PROJECT } /locations/{ tuning_job_location } /tensorboards/123"
2130
+
2128
2131
default_context = "Default context"
2129
2132
tuning_job = model .tune_model (
2130
2133
training_data = _TEST_TEXT_BISON_TRAINING_DF ,
2131
2134
tuning_job_location = "europe-west4" ,
2132
2135
tuned_model_location = "us-central1" ,
2133
2136
default_context = default_context ,
2137
+ tuning_evaluation_spec = preview_language_models .TuningEvaluationSpec (
2138
+ tensorboard = tensorboard_name ,
2139
+ ),
2134
2140
accelerator_type = "TPU" ,
2135
2141
)
2136
2142
call_kwargs = mock_pipeline_service_create .call_args [1 ]
@@ -2140,6 +2146,7 @@ def test_tune_chat_model(
2140
2146
assert pipeline_arguments ["large_model_reference" ] == "chat-bison@001"
2141
2147
assert pipeline_arguments ["default_context" ] == default_context
2142
2148
assert pipeline_arguments ["accelerator_type" ] == "TPU"
2149
+ assert pipeline_arguments ["tensorboard_resource_id" ] == tensorboard_name
2143
2150
2144
2151
# Testing the tuned model
2145
2152
tuned_model = tuning_job .get_tuned_model ()
@@ -2148,6 +2155,26 @@ def test_tune_chat_model(
2148
2155
== test_constants .EndpointConstants ._TEST_ENDPOINT_NAME
2149
2156
)
2150
2157
2158
+ unsupported_tuning_evaluation_spec_att = (
2159
+ {"evaluation_data" : "gs://bucket/eval.jsonl" },
2160
+ {"evaluation_interval" : 37 },
2161
+ {"enable_early_stopping" : True },
2162
+ {"enable_checkpoint_selection" : True },
2163
+ )
2164
+ for unsupported_att in unsupported_tuning_evaluation_spec_att :
2165
+ unsupported_tuning_evaluation_spec = (
2166
+ preview_language_models .TuningEvaluationSpec (** unsupported_att )
2167
+ )
2168
+ with pytest .raises (AttributeError ):
2169
+ model .tune_model (
2170
+ training_data = _TEST_TEXT_BISON_TRAINING_DF ,
2171
+ tuning_job_location = "europe-west4" ,
2172
+ tuned_model_location = "us-central1" ,
2173
+ default_context = default_context ,
2174
+ tuning_evaluation_spec = unsupported_tuning_evaluation_spec ,
2175
+ accelerator_type = "TPU" ,
2176
+ )
2177
+
2151
2178
@pytest .mark .parametrize (
2152
2179
"job_spec" ,
2153
2180
[_TEST_PIPELINE_SPEC_JSON ],
@@ -2228,12 +2255,18 @@ def test_tune_code_chat_model(
2228
2255
):
2229
2256
model = language_models .CodeChatModel .from_pretrained ("codechat-bison@001" )
2230
2257
2258
+ tuning_job_location = "europe-west4"
2259
+ tensorboard_name = f"projects/{ _TEST_PROJECT } /locations/{ tuning_job_location } /tensorboards/123"
2260
+
2231
2261
# The tune_model call needs to be inside the PublisherModel mock
2232
2262
# since it gets a new PublisherModel when tuning completes.
2233
2263
model .tune_model (
2234
2264
training_data = _TEST_TEXT_BISON_TRAINING_DF ,
2235
2265
tuning_job_location = "europe-west4" ,
2236
2266
tuned_model_location = "us-central1" ,
2267
+ tuning_evaluation_spec = preview_language_models .TuningEvaluationSpec (
2268
+ tensorboard = tensorboard_name ,
2269
+ ),
2237
2270
accelerator_type = "TPU" ,
2238
2271
)
2239
2272
call_kwargs = mock_pipeline_service_create .call_args [1 ]
@@ -2242,6 +2275,26 @@ def test_tune_code_chat_model(
2242
2275
].runtime_config .parameter_values
2243
2276
assert pipeline_arguments ["large_model_reference" ] == "codechat-bison@001"
2244
2277
assert pipeline_arguments ["accelerator_type" ] == "TPU"
2278
+ assert pipeline_arguments ["tensorboard_resource_id" ] == tensorboard_name
2279
+
2280
+ unsupported_tuning_evaluation_spec_att = (
2281
+ {"evaluation_data" : "gs://bucket/eval.jsonl" },
2282
+ {"evaluation_interval" : 37 },
2283
+ {"enable_early_stopping" : True },
2284
+ {"enable_checkpoint_selection" : True },
2285
+ )
2286
+ for unsupported_att in unsupported_tuning_evaluation_spec_att :
2287
+ unsupported_tuning_evaluation_spec = (
2288
+ preview_language_models .TuningEvaluationSpec (** unsupported_att )
2289
+ )
2290
+ with pytest .raises (AttributeError ):
2291
+ model .tune_model (
2292
+ training_data = _TEST_TEXT_BISON_TRAINING_DF ,
2293
+ tuning_job_location = "europe-west4" ,
2294
+ tuned_model_location = "us-central1" ,
2295
+ tuning_evaluation_spec = unsupported_tuning_evaluation_spec ,
2296
+ accelerator_type = "TPU" ,
2297
+ )
2245
2298
2246
2299
@pytest .mark .usefixtures (
2247
2300
"get_model_with_tuned_version_label_mock" ,
0 commit comments