pytorch
70f3078d - [Pytorch Edge] Wrap lowered module in to_backend (#71597)

Commit
2 years ago
[Pytorch Edge] Wrap lowered module in to_backend (#71597) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/71597 Problem: _jit_to_backend overrides get/set state. This means any attributes added to the module after lowering will not be preserved after serialization. For edge workflows the biggest problem here is it breaks bundled_inputs. Solution?: Real quick and easy way to handle issues with to_backend overriding get/set state. Wraps the lowered module in another module and has forwarding functions for the api specified in 'method_compile_spec'. The tradeoff with this approach is now the actual workhorse of the module is 1 layer deep which might make debugging slightly grosser/more difficult/confusing. The other approach Martin David and I talked about would be to only lower the portions that require custom get/set state logic. This leaves the top level the same, and only specific backened internals are changed. Personally I'm not sure how much that really addresses the debugging concern all that well. It seems like if you cracked the model open you'd still run into similar amounts of confusion with a lot of the variables and logic referenced coming from another module. The other concern with this approach is whether or not 'compile_spec' specifies the public api of the module (since thats our source of truth for this wrapper). While it may not be enforced, it certainly seems to be true by convention and the to_backend api already uses it as a source of truth for all functions that get generated in the resulting module. I say we just formally commit to this (compile spec keys being functions) being the contract of the api instead of just assuming it to be the case and then having weird behavior if its not. Test Plan: New Unit Test CI to check for existing behavior and contracts. manually tested in a notebook with bundled inputs. {P475790313} Reviewed By: raziel Differential Revision: D33694257 fbshipit-source-id: 9ff27db421eba41bac083dff11a22e9e40a36970 (cherry picked from commit 91ef49977ef0bf18242df381a3ee805c24d6f68d)
Author
Committer
Parents
Loading