diff --git a/docs/Pytorch-Lightning/LightningModule.md b/docs/LightningModule/RequiredTrainerInterface.md similarity index 92% rename from docs/Pytorch-Lightning/LightningModule.md rename to docs/LightningModule/RequiredTrainerInterface.md index 79e02029..465ce2fc 100644 --- a/docs/Pytorch-Lightning/LightningModule.md +++ b/docs/LightningModule/RequiredTrainerInterface.md @@ -1,4 +1,4 @@ -# Lightning module +# Lightning Module interface [[Github Code](https://github.com/williamFalcon/pytorch-lightning/blob/master/pytorch_lightning/root_module/root_module.py)] A lightning module is a strict superclass of nn.Module, it provides a standard interface for the trainer to interact with the model. @@ -9,22 +9,22 @@ Otherwise, to Define a Lightning Module, implement the following methods: **Required**: -- [training_step](LightningModule.md#training_step) -- [validation_step](LightningModule.md#validation_step) -- [validation_end](LightningModule.md#validation_end) +- [training_step](RequiredTrainerInterface.md#training_step) +- [validation_step](RequiredTrainerInterface.md#validation_step) +- [validation_end](RequiredTrainerInterface.md#validation_end) -- [configure_optimizers](LightningModule.md#configure_optimizers) -- [get_save_dict](LightningModule.md#get_save_dict) -- [load_model_specific](LightningModule.md#load_model_specific) +- [configure_optimizers](RequiredTrainerInterface.md#configure_optimizers) +- [get_save_dict](RequiredTrainerInterface.md#get_save_dict) +- [load_model_specific](RequiredTrainerInterface.md#load_model_specific) -- [tng_dataloader](LightningModule.md#tng_dataloader) -- [tng_dataloader](LightningModule.md#tng_dataloader) -- [test_dataloader](LightningModule.md#test_dataloader) +- [tng_dataloader](RequiredTrainerInterface.md#tng_dataloader) +- [tng_dataloader](RequiredTrainerInterface.md#tng_dataloader) +- [test_dataloader](RequiredTrainerInterface.md#test_dataloader) **Optional**: -- [update_tng_log_metrics](LightningModule.md#update_tng_log_metrics) -- [add_model_specific_args](LightningModule.md#add_model_specific_args) +- [update_tng_log_metrics](RequiredTrainerInterface.md#update_tng_log_metrics) +- [add_model_specific_args](RequiredTrainerInterface.md#add_model_specific_args) --- @@ -391,4 +391,4 @@ def add_model_specific_args(parent_parser, root_dir): parser.opt_list('--batch_size', default=256, type=int, options=[32, 64, 128, 256], tunable=False) parser.opt_list('--optimizer_name', default='adam', type=str, options=['adam'], tunable=False) return parser -``` +``` \ No newline at end of file diff --git a/docs/LightningModule/methods.md b/docs/LightningModule/methods.md new file mode 100644 index 00000000..9163326e --- /dev/null +++ b/docs/LightningModule/methods.md @@ -0,0 +1,49 @@ +Lightning modules are strict superclasses of torch.nn.Module. A LightningModule offers the following in addition to that API. + +--- +### freeze +Freeze all params for inference +```{.python} +model = MyLightningModule(...) +model.freeze() +``` + +--- +### load_from_metrics +This is the easiest/fastest way which uses the meta_tags.csv file from test-tube to rebuild the model. +The meta_tags.csv file can be found in the test-tube experiment save_dir. + +```{.python} +pretrained_model = MyLightningModule.load_from_metrics( + weights_path='/path/to/pytorch_checkpoint.ckpt', + tags_csv='/path/to/test_tube/experiment/version/meta_tags.csv', + on_gpu=True, + map_location=None +) + +# predict +pretrained_model.freeze() +y_hat = pretrained_model(x) +``` + +**Params** + +| Param | description | +|---|---| +| weights_path | Path to a pytorch checkpoint | +| tags_csv | Path to meta_tags.csv file generated by the test-tube Experiment | +| on_gpu | if True, puts model on GPU. Make sure to use transforms option if model devices have changed | +| map_location | A dictionary mapping saved weight GPU devices to new GPU devices | + +**Returns** + +LightningModule - The pretrained LightningModule + +--- +### unfreeze +Unfreeze all params for inference +```{.python} +model = MyLightningModule(...) +model.unfreeze() +``` + diff --git a/docs/Trainer/Checkpointing.md b/docs/Trainer/Checkpointing.md index 99bf6f7e..db0d7d50 100644 --- a/docs/Trainer/Checkpointing.md +++ b/docs/Trainer/Checkpointing.md @@ -2,17 +2,21 @@ Lightning can automate saving and loading checkpoints. --- ### Model saving -To enable checkpointing, define the checkpoint callback +To enable checkpointing, define the checkpoint callback and give it to the trainer. ``` {.python} from pytorch_lightning.utils.pt_callbacks import ModelCheckpoint -checkpoint = ModelCheckpoint( +checkpoint_callback = ModelCheckpoint( filepath='/path/to/store/weights.ckpt', - save_function=None, - save_best_only=not hparams.keep_all_checkpoints, + save_best_only=True, verbose=True, - monitor=hparams.model_save_monitor_value, - mode=hparams.model_save_monitor_mode + monitor='val_loss', + mode='min' ) -``` \ No newline at end of file + +trainer = Trainer(checkpoint_callback=checkpoint_callback) +``` + + + diff --git a/docs/index.md b/docs/index.md index 74a1b6b6..bae7e291 100644 --- a/docs/index.md +++ b/docs/index.md @@ -1,7 +1,7 @@ # PYTORCH-LIGHTNING DOCUMENTATION ###### Main Docs -- [LightningModule](Pytorch-Lightning/LightningModule) +- [LightningModule](LightningModule/LightningModule) - [Trainer](Trainer/) ###### New project Quick Start diff --git a/mkdocs.yml b/mkdocs.yml index d01098d5..585625c9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -3,7 +3,7 @@ theme: readthedocs docs_dir: docs repo_url: https://github.com/williamFalcon/pytorch-lightning site_dir: 'site' -site_description: 'Documentation for Pytorch Pytorch-Lightning, the researcher version of keras.' +site_description: 'Documentation for Pytorch LightningModule, the researcher version of keras.' dev_addr: '0.0.0.0:8000' #google_analytics: ['UA-aasd', 'sitename']