Repository navigation
Add RegionAC vision transformer regions - #4611
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
| q_THDh, k_THDh, v_THDh = remat.region( | ||
| self._qkv, | ||
| self.remat_region_name("qkv"), | ||
| recompute=self.remat_should_recompute("qkv"), | ||
| )(x) |
There was a problem hiding this comment.
vision encoder is typically small -- would this code couple encoder and decoder AC behavior? Not asking you to expose options, but a genuine question of whether we should decouple or not.
There was a problem hiding this comment.
So the fqn-region name is different for encoder and decoder (perhaps just by accident)
- Decoder block stores the module as self.attention.
- Vision block stores it as self.attn.
So this PR does not introduce a new coupling. But I think we should perhaps have stricter checks in codebase so that the decoder and encoder blocks have different names for the attention atleast.
Other way is to fully decouple as you say - have separately controlled Remat config for the encoder and decoder. This will introduce some complexity.
From a quick read, it seems the vision encoder, even though its small, has a high activation memory footprint, so I think we should give option to AC it.
If you want, I can see what is the added complexity of supporting separately controlled Remat configs. We parked that earlier when we said lets have same policy for each transformer block.
There was a problem hiding this comment.
I think for now it sounds fine to have a central AC policy.
If they indeed need separate policy, I probably would rename vision block with vision_attention or encoder_attention to differentiate, rather than relying on attention vs. attn.
On the other hand, if they don't need to have different policy between encoder and decoder, probably can just name them the same, lol.
| q_THDh, k_THDh, v_THDh = remat.region( | ||
| self._qkv, | ||
| self.remat_region_name("qkv"), | ||
| recompute=self.remat_should_recompute("qkv"), | ||
| )(x) |
There was a problem hiding this comment.
I think for now it sounds fine to have a central AC policy.
If they indeed need separate policy, I probably would rename vision block with vision_attention or encoder_attention to differentiate, rather than relying on attention vs. attn.
On the other hand, if they don't need to have different policy between encoder and decoder, probably can just name them the same, lol.
| return self.proj(out_TD) | ||
| out_TD = remat.region( | ||
| self.proj, | ||
| self.remat_region_name("proj"), |
There was a problem hiding this comment.
probably should unify the naming such as wo, optionally with encoder prefix
| return self.linear_fc2(self.act_fn(self.linear_fc1(x))) | ||
| hidden_TF = remat.region( | ||
| self.linear_fc1, | ||
| self.remat_region_name("fc1"), |
ghstack-source-id: a83e0a8 Pull-Request: pytorch/torchtitan#4611
Stack from ghstack (oldest at bottom):