@@ -264,37 +264,55 @@ fn train_joint(
264264) ;
265265
266266let mut deploy =true ;
267+
267268match automatic_deploy{
268- // Deploy only if metrics are better than previous model.
269+ // Deploy only if metrics are better than previous model, or if its the first model
269270Some ( true ) |None =>{
270271if let Ok ( Some ( deployed_metrics) ) = deployed_metrics{
271- let deployed_metrics = deployed_metrics. 0 . as_object ( ) . unwrap ( ) ;
272- let deployed_metric = deployed_metrics
273- . get ( & project. task . default_target_metric ( ) )
274- . unwrap ( )
275- . as_f64 ( )
276- . unwrap ( ) ;
277- info ! (
278- "Comparing to deployed model {}: {:?}" ,
279- project. task. default_target_metric( ) ,
280- deployed_metric
281- ) ;
282- if project. task . value_is_better (
283- deployed_metric,
284- new_metrics
285- . get ( & project. task . default_target_metric ( ) )
286- . unwrap ( )
287- . as_f64 ( )
288- . unwrap ( ) ,
289- ) {
272+ if let Some ( deployed_metrics_obj) = deployed_metrics. 0 . as_object ( ) {
273+ let default_target_metric = project. task . default_target_metric ( ) ;
274+ let deployed_metric = deployed_metrics_obj
275+ . get ( & default_target_metric)
276+ . and_then ( |v| v. as_f64 ( ) ) ;
277+ info ! (
278+ "Comparing to deployed model {}: {:?}" ,
279+ default_target_metric, deployed_metric
280+ ) ;
281+ let new_metric = new_metrics. get ( & default_target_metric) . and_then ( |v| v. as_f64 ( ) ) ;
282+
283+ match ( deployed_metric, new_metric) {
284+ ( Some ( deployed) , Some ( new) ) =>{
285+ // only compare metrics when both new and old model have metrics to compare
286+ if project. task . value_is_better ( deployed, new) {
287+ warning ! (
288+ "New model's {} is not better than current model. New: {}, Current {}" ,
289+ & default_target_metric,
290+ new,
291+ deployed
292+ ) ;
293+ deploy =false ;
294+ }
295+ }
296+ ( None , None ) =>{
297+ warning ! ( "No metrics available for both deployed and new model. Deploying new model." )
298+ }
299+ ( Some ( _deployed) , None ) =>{
300+ warning ! ( "No metrics for new model. Retaining old model." ) ;
301+ deploy =false ;
302+ }
303+ ( None , Some ( _new) ) =>warning ! ( "No metrics for deployed model. Deploying new model." ) ,
304+ }
305+ } else {
306+ warning ! ( "Failed to parse deployed model metrics. Check data types of model metadata on pgml.models.metrics" ) ;
290307 deploy =false ;
291308}
292309}
293310}
294-
295- Some ( false ) => deploy =false ,
311+ Some ( false ) =>{
312+ warning ! ( "Automatic deployment disabled via configuration." ) ;
313+ deploy =false ;
314+ }
296315} ;
297-
298316if deploy{
299317 project. deploy ( model. id , Strategy :: new_score) ;
300318} else {