Skip to content

[pytorch][mobile] remove backward functions from jit-op-registry for mobile build#26657

Merged
ljk53 merged 3 commits intogh/ljk53/54/basefrom
gh/ljk53/54/head
Sep 25, 2019
Merged

[pytorch][mobile] remove backward functions from jit-op-registry for mobile build#26657
ljk53 merged 3 commits intogh/ljk53/54/basefrom
gh/ljk53/54/head

Conversation

@ljk53
Copy link
Contributor

@ljk53 ljk53 commented Sep 23, 2019

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:

  • build and integrate with demo app;

Differential Revision: D17533887

…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]
@pytorchbot pytorchbot added oncall: jit Add this issue/PR to JIT oncall triage queue module: build Build system issues labels Sep 23, 2019
ljk53 added a commit that referenced this pull request Sep 23, 2019
…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')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use the same set of filters as in python bindings? (and add a comment about it)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]
@ljk53 ljk53 added this to the 1.3 milestone Sep 24, 2019
@ljk53 ljk53 requested review from suo and zdevito September 24, 2019 16:46
@ljk53
Copy link
Contributor Author

ljk53 commented Sep 24, 2019

Add @zdevito and @suo to help review.
@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?

'.*_backward', '.*_backward_(out|input|weight|bias)', '.*_forward',

…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]
Copy link
Collaborator

@dzhulgakov dzhulgakov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@ljk53 ljk53 merged commit 3dc5a3d into gh/ljk53/54/base Sep 25, 2019
@ljk53
Copy link
Contributor Author

ljk53 commented Sep 25, 2019

Seems I hit some weird bug with ghstack here - #26700 used to be after this PR, I landed it first as it doesn't really depend on this PR and swapped their order. It somehow marked this PR as merged.
I can recreate this PR but hope it doesn't cause any other problem...

cc: @ezyang

@ezyang
Copy link
Contributor

ezyang commented Sep 25, 2019

Yeah just make a new PR. Sorry about the trouble. If you can send me some rages I can look into it.

karansachdev-1012 pushed a commit to karansachdev-1012/pytorch that referenced this pull request Feb 17, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: build Build system issues oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants