@@ -480,10 +480,14 @@ def __init__(
480
480
# default .predict() loop
481
481
self .predict_loop = PredictionLoop ()
482
482
483
- # .validate() and .test() set this when they load a checkpoint
484
- self .validated_ckpt_path : Optional [str ] = None
485
- self .tested_ckpt_path : Optional [str ] = None
486
- self .predicted_ckpt_path : Optional [str ] = None
483
+ # set when a checkpoint is loaded via `Trainer.{fit,validate,test,predict}`.
484
+ self ._ckpt_path : Optional [str ] = None
485
+
486
+ # .validate(), predict() and .test() set these when they load a checkpoint. They will be removed in favor of
487
+ # the unified read-only `Trainer.ckpt_path` attribute in v1.8
488
+ self ._validated_ckpt_path : Optional [str ] = None # TODO: remove in v1.8
489
+ self ._tested_ckpt_path : Optional [str ] = None # TODO: remove in v1.8
490
+ self ._predicted_ckpt_path : Optional [str ] = None # TODO: remove in v1.8
487
491
488
492
# todo: remove in v1.7
489
493
self ._weights_summary : Optional [str ] = None
@@ -758,7 +762,10 @@ def _fit_impl(
758
762
759
763
# TODO: ckpt_path only in v2.0
760
764
ckpt_path = ckpt_path or self .resume_from_checkpoint
761
- results = self ._run (model , ckpt_path = ckpt_path )
765
+ self ._ckpt_path = self .__set_ckpt_path (
766
+ ckpt_path , model_provided = model , model_connected = self .lightning_module is not None
767
+ )
768
+ results = self ._run (model , ckpt_path = self .ckpt_path )
762
769
763
770
assert self .state .stopped
764
771
self .training = False
@@ -837,12 +844,14 @@ def _validate_impl(
837
844
# links data to the trainer
838
845
self ._data_connector .attach_data (model , val_dataloaders = dataloaders , datamodule = datamodule )
839
846
840
- self .validated_ckpt_path = self .__set_ckpt_path (
847
+ self ._ckpt_path = self .__set_ckpt_path (
841
848
ckpt_path , model_provided = model_provided , model_connected = self .lightning_module is not None
842
849
)
843
850
851
+ self ._validated_ckpt_path = self .ckpt_path # TODO: remove in v1.8
852
+
844
853
# run validate
845
- results = self ._run (model , ckpt_path = self .validated_ckpt_path )
854
+ results = self ._run (model , ckpt_path = self .ckpt_path )
846
855
847
856
assert self .state .stopped
848
857
self .validating = False
@@ -923,12 +932,14 @@ def _test_impl(
923
932
# links data to the trainer
924
933
self ._data_connector .attach_data (model , test_dataloaders = dataloaders , datamodule = datamodule )
925
934
926
- self .tested_ckpt_path = self .__set_ckpt_path (
935
+ self ._ckpt_path = self .__set_ckpt_path (
927
936
ckpt_path , model_provided = model_provided , model_connected = self .lightning_module is not None
928
937
)
929
938
939
+ self ._tested_ckpt_path = self .ckpt_path # TODO: remove in v1.8
940
+
930
941
# run test
931
- results = self ._run (model , ckpt_path = self .tested_ckpt_path )
942
+ results = self ._run (model , ckpt_path = self .ckpt_path )
932
943
933
944
assert self .state .stopped
934
945
self .testing = False
@@ -1009,11 +1020,13 @@ def _predict_impl(
1009
1020
# links data to the trainer
1010
1021
self ._data_connector .attach_data (model , predict_dataloaders = dataloaders , datamodule = datamodule )
1011
1022
1012
- self .predicted_ckpt_path = self .__set_ckpt_path (
1023
+ self ._ckpt_path = self .__set_ckpt_path (
1013
1024
ckpt_path , model_provided = model_provided , model_connected = self .lightning_module is not None
1014
1025
)
1015
1026
1016
- results = self ._run (model , ckpt_path = self .predicted_ckpt_path )
1027
+ self ._predicted_ckpt_path = self .ckpt_path # TODO: remove in v1.8
1028
+
1029
+ results = self ._run (model , ckpt_path = self .ckpt_path )
1017
1030
1018
1031
assert self .state .stopped
1019
1032
self .predicting = False
@@ -2217,6 +2230,74 @@ def resume_from_checkpoint(self) -> Optional[Union[str, Path]]:
2217
2230
2218
2231
return resume_from_checkpoint
2219
2232
2233
+ @property
2234
+ def ckpt_path (self ) -> Optional [str ]:
2235
+ """Set to the path/URL of checkpoints loaded via :meth:`~pytorch_lightning.trainer.trainer.Trainer.fit`,
2236
+ :meth:`~pytorch_lightning.trainer.trainer.Trainer.validate`,
2237
+ :meth:`~pytorch_lightning.trainer.trainer.Trainer.test`, or
2238
+ :meth:`~pytorch_lightning.trainer.trainer.Trainer.predict`. ``None`` otherwise."""
2239
+ return self ._ckpt_path
2240
+
2241
+ @property
2242
+ def validated_ckpt_path (self ) -> Optional [str ]:
2243
+ rank_zero_deprecation (
2244
+ "The `Trainer.validated_ckpt_path` attribute was deprecated in v1.6 and will be removed in v1.8. The"
2245
+ " path of checkpoints loaded via `Trainer.{fit,validate,test,predict}` should be accessed via"
2246
+ " `Trainer.ckpt_path` instead." ,
2247
+ stacklevel = 5 ,
2248
+ )
2249
+ return self ._validated_ckpt_path
2250
+
2251
+ @validated_ckpt_path .setter
2252
+ def validated_ckpt_path (self , ckpt_path : Optional [str ]) -> None :
2253
+ rank_zero_deprecation (
2254
+ "The `Trainer.validated_ckpt_path` attribute was deprecated in v1.6 and will be removed in v1.8. The"
2255
+ " path of checkpoints loaded via `Trainer.{fit,validate,test,predict}` should be accessed via the read-only"
2256
+ " `Trainer.ckpt_path`." ,
2257
+ stacklevel = 5 ,
2258
+ )
2259
+ self ._validated_ckpt_path = ckpt_path
2260
+
2261
+ @property
2262
+ def tested_ckpt_path (self ) -> Optional [str ]:
2263
+ rank_zero_deprecation (
2264
+ "The `Trainer.tested_ckpt_path` attribute was deprecated in v1.6 and will be removed in v1.8. The"
2265
+ " path of checkpoints loaded via `Trainer.{fit,validate,test,predict}` should be accessed via"
2266
+ " `Trainer.ckpt_path` instead." ,
2267
+ stacklevel = 5 ,
2268
+ )
2269
+ return self ._tested_ckpt_path
2270
+
2271
+ @tested_ckpt_path .setter
2272
+ def tested_ckpt_path (self , ckpt_path : Optional [str ]) -> None :
2273
+ rank_zero_deprecation (
2274
+ "The `Trainer.tested_ckpt_path` attribute was deprecated in v1.6 and will be removed in v1.8. The"
2275
+ " path of checkpoints loaded via `Trainer.{fit,validate,test,predict}` should be accessed via the read-only"
2276
+ " `Trainer.ckpt_path` instead." ,
2277
+ stacklevel = 5 ,
2278
+ )
2279
+ self ._tested_ckpt_path = ckpt_path
2280
+
2281
+ @property
2282
+ def predicted_ckpt_path (self ) -> Optional [str ]:
2283
+ rank_zero_deprecation (
2284
+ "The `Trainer.predicted_ckpt_path` attribute was deprecated in v1.6 and will be removed in v1.8. The"
2285
+ " path of checkpoints loaded via `Trainer.{fit,validate,test,predict}` should be accessed via"
2286
+ " `Trainer.ckpt_path` instead." ,
2287
+ stacklevel = 5 ,
2288
+ )
2289
+ return self ._predicted_ckpt_path
2290
+
2291
+ @predicted_ckpt_path .setter
2292
+ def predicted_ckpt_path (self , ckpt_path : Optional [str ]) -> None :
2293
+ rank_zero_deprecation (
2294
+ "The `Trainer.predicted_ckpt_path` attribute was deprecated in v1.6 and will be removed in v1.8. The"
2295
+ " path of checkpoints loaded via `Trainer.{fit,validate,test,predict}` should be accessed via the read-only"
2296
+ " `Trainer.ckpt_path` instead." ,
2297
+ stacklevel = 5 ,
2298
+ )
2299
+ self ._predicted_ckpt_path = ckpt_path
2300
+
2220
2301
def save_checkpoint (self , filepath : _PATH , weights_only : bool = False ) -> None :
2221
2302
r"""
2222
2303
Runs routine to create a checkpoint.
0 commit comments