Make blocks attachable automatically when needed by mannatsingh · Pull Request #461 · facebookresearch/ClassyVision
added
CLA Signed
fb-exported labels
Mar 31, 2020mannatsingh added a commit to mannatsingh/ClassyVision that referenced this pull request
Apr 1, 2020Summary: Pull Request resolved: facebookresearch#461 I was frustrated by the fact that I needed to change the code for every model if I needed to be able to attach heads to it - something we need to do with most trained models. Ideally, users should be able to write their models without writing anything classy vision specific and be able to attach heads. I've made a couple of diffs which get us there, wanted to see what everyone thought about them. Please look at the second diff to see the end result. In this diff, I make the following changes - - `build_attachable_block` becomes a private function (`_build_attachable_block`), and models don't need to call it anymore. - Instead, when someone tries to attach to a module called `my_block`, we recursively search for it and wrap it by a `ClassyBlock` on the fly - Updated `get_classy_state` and `set_classy_state` to be compatible with the changes - Users can attach heads to any block which has a unique name (like `block3-2`) - `models_classy_model_test` wasn't being run internally; renamed `classy_block_test` to `models_classy_block_test` - Added additional test cases to test the changes NOTE: This breaks all checkpoints since the model definitions have changed. Differential Revision: D20714865 fbshipit-source-id: 95c1ce4655663538919ca28f77f554ea67570edb
mannatsingh added a commit to mannatsingh/ClassyVision that referenced this pull request
Apr 1, 2020Summary: Pull Request resolved: facebookresearch#461 I was frustrated by the fact that I needed to change the code for every model if I needed to be able to attach heads to it - something we need to do with most trained models. Ideally, users should be able to write their models without writing anything classy vision specific and be able to attach heads. I've made a couple of diffs which get us there, wanted to see what everyone thought about them. Please look at the second diff to see the end result. In this diff, I make the following changes - - `build_attachable_block` becomes a private function (`_build_attachable_block`), and models don't need to call it anymore. - Removed `_should_cache_output` and `set_cache_output` from `ClassyBlock` - Added a redundant `_attachable_block_names` attribute - this is needed for reading the block names inside torch script (`_attachable_blocks` is inaccessible) - T64918869 - Instead, when someone tries to attach to a module called `my_block`, we recursively search for it and wrap it by a `ClassyBlock` on the fly - Updated `get_classy_state` and `set_classy_state` to be compatible with the changes - Users can attach heads to any block which has a unique name (like `block3-2`) - `models_classy_model_test` wasn't being run internally; renamed `classy_block_test` to `models_classy_block_test` - Added additional test cases to test the changes NOTE: This breaks all checkpoints since the model definitions have changed. We still handle old checkpoints for `ResNeXt` models to allow for a smoother transition - T61141249 Differential Revision: D20714865 fbshipit-source-id: f48e768aede1c10d25754f0fad0f24ccac9a1503
mannatsingh added a commit to mannatsingh/ClassyVision that referenced this pull request
Apr 1, 2020Summary: Pull Request resolved: facebookresearch#461 I was frustrated by the fact that I needed to change the code for every model if I needed to be able to attach heads to it - something we need to do with most trained models. Ideally, users should be able to write their models without writing anything classy vision specific and be able to attach heads. I've made a couple of diffs which get us there, wanted to see what everyone thought about them. Please look at the second diff to see the end result. In this diff, I make the following changes - - `build_attachable_block` becomes a private function (`_build_attachable_block`), and models don't need to call it anymore. - Removed `_should_cache_output` and `set_cache_output` from `ClassyBlock` - Added a redundant `_attachable_block_names` attribute - this is needed for reading the block names inside torch script (`_attachable_blocks` is inaccessible) - T64918869 - Instead, when someone tries to attach to a module called `my_block`, we recursively search for it and wrap it by a `ClassyBlock` on the fly - Updated `get_classy_state` and `set_classy_state` to be compatible with the changes - Users can attach heads to any block which has a unique name (like `block3-2`) - `models_classy_model_test` wasn't being run internally; renamed `classy_block_test` to `models_classy_block_test` - Added additional test cases to test the changes NOTE: This breaks all checkpoints since the model definitions have changed. We still handle old checkpoints for `ResNeXt` models to allow for a smoother transition - T61141249 Reviewed By: vreis Differential Revision: D20714865 fbshipit-source-id: 993a841b7190d5fabd751d8cca25381dcd93d898
Summary: Pull Request resolved: facebookresearch#461 I was frustrated by the fact that I needed to change the code for every model if I needed to be able to attach heads to it - something we need to do with most trained models. Ideally, users should be able to write their models without writing anything classy vision specific and be able to attach heads. I've made a couple of diffs which get us there, wanted to see what everyone thought about them. Please look at the second diff to see the end result. In this diff, I make the following changes - - `build_attachable_block` becomes a private function (`_build_attachable_block`), and models don't need to call it anymore. - Removed `_should_cache_output` and `set_cache_output` from `ClassyBlock` - Added a redundant `_attachable_block_names` attribute - this is needed for reading the block names inside torch script (`_attachable_blocks` is inaccessible) - T64918869 - Instead, when someone tries to attach to a module called `my_block`, we recursively search for it and wrap it by a `ClassyBlock` on the fly - Updated `get_classy_state` and `set_classy_state` to be compatible with the changes - Users can attach heads to any block which has a unique name (like `block3-2`) - `models_classy_model_test` wasn't being run internally; renamed `classy_block_test` to `models_classy_block_test` - Added additional test cases to test the changes NOTE: This breaks all checkpoints since the model definitions have changed. We still handle old checkpoints for `ResNeXt` models to allow for a smoother transition - T61141249 Reviewed By: vreis Differential Revision: D20714865 fbshipit-source-id: d3cd867886ad857efe31442458da761418a51d6d
facebook-github-bot pushed a commit that referenced this pull request
Apr 9, 2020Summary: Pull Request resolved: #461 I was frustrated by the fact that I needed to change the code for every model if I needed to be able to attach heads to it - something we need to do with most trained models. Ideally, users should be able to write their models without writing anything classy vision specific and be able to attach heads. I've made a couple of diffs which get us there, wanted to see what everyone thought about them. Please look at the second diff to see the end result. In this diff, I make the following changes - - `build_attachable_block` becomes a private function (`_build_attachable_block`), and models don't need to call it anymore. - Removed `_should_cache_output` and `set_cache_output` from `ClassyBlock` - Added a redundant `_attachable_block_names` attribute - this is needed for reading the block names inside torch script (`_attachable_blocks` is inaccessible) - T64918869 - Instead, when someone tries to attach to a module called `my_block`, we recursively search for it and wrap it by a `ClassyBlock` on the fly - Updated `get_classy_state` and `set_classy_state` to be compatible with the changes - Users can attach heads to any block which has a unique name (like `block3-2`) - `models_classy_model_test` wasn't being run internally; renamed `classy_block_test` to `models_classy_block_test` - Added additional test cases to test the changes NOTE: This breaks all checkpoints since the model definitions have changed. We still handle old checkpoints for `ResNeXt` models to allow for a smoother transition - T61141249 Reviewed By: vreis Differential Revision: D20714865 fbshipit-source-id: f8fa269b5deddbdd77461047850e7050b1bc921a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters