[pytorch][mobile] remove backward functions from jit-op-registry for mobile build#26657
[pytorch][mobile] remove backward functions from jit-op-registry for mobile build#26657ljk53 merged 3 commits intogh/ljk53/54/basefrom
Conversation
…mobile build Summary: Add codegen option to remove backward ops from jit-op-registry as they are not likely to be used for inference only mobile build. Measured ARM-v7 AAR build size change: 5,804,182 -> 5,331,219. Test Plan: - build and integrate with demo app; [ghstack-poisoned]
…mobile build Summary: Add codegen option to remove backward ops from jit-op-registry as they are not likely to be used for inference only mobile build. Measured ARM-v7 AAR build size change: 5,804,182 -> 5,331,219. Test Plan: - build and integrate with demo app; ghstack-source-id: e0530c5 Pull Request resolved: #26657
|
|
||
|
|
||
| def is_backward_op(decl): | ||
| return decl['name'].endswith('_backward') or decl['name'].endswith('_backward_out') |
There was a problem hiding this comment.
This looks a bit hacky but there is an example above searching for "_out" and another example searching for "backward": https://github.com/pytorch/pytorch/blob/master/tools/autograd/gen_variable_type.py#L574
There was a problem hiding this comment.
can we use the same set of filters as in python bindings? (and add a comment about it)
There was a problem hiding this comment.
can we use the same set of filters as in python bindings? (and add a comment about it)
Do you think I should use the entire SKIP_PYTHON_BINDINGS / even directly references it?
It has a lot other stuff like '.*_forward', 'index', .. - I haven't verified but do you think these can all be safely deleted from JIT binding?
| declarations_path or DECLARATIONS_PATH, | ||
| jit_gen_dir, | ||
| 'tools/jit/templates', | ||
| disable_autograd=disable_autograd) |
There was a problem hiding this comment.
I think technically backward ops are not coupled with autograd? Maybe I should rename all "disable_autograd" to "inference_only"? Just don't want to create too many different concepts while the main purpose is just to shrink prebuilt mobile lib size...
There was a problem hiding this comment.
I think the same setting makes sense - and the backward ops ARE coupled with autograd. They are not exposed to python, so the only way to use them is through autograd
| lvalues=lvalues) | ||
| return constructor | ||
|
|
||
| def filter_decls(jit_decls, disable_autograd): |
There was a problem hiding this comment.
I'm going to add another option to take a while list of ops to create custom mobile build so making this a separate function.
…gistry for mobile build" Summary: Add codegen option to remove backward ops from jit-op-registry as they are not likely to be used for inference only mobile build. Measured ARM-v7 AAR build size change: 5,804,182 -> 5,331,219. Test Plan: - build and integrate with demo app; Differential Revision: [D17533887](https://our.internmc.facebook.com/intern/diff/D17533887) [ghstack-poisoned]
…gistry for mobile build" Summary: Add codegen option to remove backward ops from jit-op-registry as they are not likely to be used for inference only mobile build. Measured ARM-v7 AAR build size change: 5,804,182 -> 5,331,219. Test Plan: - build and integrate with demo app; Differential Revision: [D17533887](https://our.internmc.facebook.com/intern/diff/D17533887) [ghstack-poisoned]
dzhulgakov
left a comment
There was a problem hiding this comment.
@gchanan made a good point during offline discussion: we don't bind these backward functions in python, probably should simply skip all of them by default?
I think they should be still bound to JIT because of symbolic gradients
|
|
||
|
|
||
| def is_backward_op(decl): | ||
| return decl['name'].endswith('_backward') or decl['name'].endswith('_backward_out') |
There was a problem hiding this comment.
can we use the same set of filters as in python bindings? (and add a comment about it)
| declarations_path or DECLARATIONS_PATH, | ||
| jit_gen_dir, | ||
| 'tools/jit/templates', | ||
| disable_autograd=disable_autograd) |
There was a problem hiding this comment.
I think the same setting makes sense - and the backward ops ARE coupled with autograd. They are not exposed to python, so the only way to use them is through autograd
|
Yeah just make a new PR. Sorry about the trouble. If you can send me some rages I can look into it. |
…mobile build Summary: Add codegen option to remove backward ops from jit-op-registry as they are not likely to be used for inference only mobile build. Measured ARM-v7 AAR build size change: 5,804,182 -> 5,331,219. Test Plan: - build and integrate with demo app; ghstack-source-id: 03a3854 Pull Request resolved: pytorch/pytorch#26657
Stack from ghstack:
Summary:
Add codegen option to remove backward ops from jit-op-registry as they are not
likely to be used for inference only mobile build.
Measured ARM-v7 AAR build size change: 5,804,182 -> 5,331,219.
Test Plan:
Differential Revision: D17533887