Skip to content

Add RegionAC vision transformer regions - #4611

Merged
anijain2305 merged 30 commits into
mainfrom
gh/anijain2305/16/head
Sep 14, 2026
Merged

anijain2305 merged 30 commits into
mainfrom
gh/anijain2305/16/head

Conversation

@anijain2305

@anijain2305 anijain2305 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@anijain2305 anijain2305 changed the title Add RegionAC vision transformer regions [DONT REVIEW YET] Add RegionAC vision transformer regions Sep 11, 2026
[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]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@anijain2305 anijain2305 changed the title [DONT REVIEW YET] Add RegionAC vision transformer regions Add RegionAC vision transformer regions Sep 13, 2026
@anijain2305
anijain2305 marked this pull request as ready for review September 13, 2026 19:40
anijain2305 added a commit that referenced this pull request Sep 13, 2026
ghstack-source-id: 48236b0
Pull-Request: #4611
Comment on lines +158 to +162
q_THDh, k_THDh, v_THDh = remat.region(
self._qkv,
self.remat_region_name("qkv"),
recompute=self.remat_should_recompute("qkv"),
)(x)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@anijain2305 anijain2305 Sep 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment on lines +158 to +162
q_THDh, k_THDh, v_THDh = remat.region(
self._qkv,
self.remat_region_name("qkv"),
recompute=self.remat_should_recompute("qkv"),
)(x)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

similar

[ghstack-poisoned]
@anijain2305
anijain2305 changed the base branch from gh/anijain2305/16/base to main September 14, 2026 03:54
@anijain2305
anijain2305 changed the base branch from main to gh/anijain2305/16/base September 14, 2026 04:38
[ghstack-poisoned]
@anijain2305
anijain2305 changed the base branch from gh/anijain2305/16/base to main September 14, 2026 04:41
@anijain2305
anijain2305 merged commit b21f7d4 into main Sep 14, 2026
9 checks passed
submartingales pushed a commit to botcanlearn/torchtitan-upstream that referenced this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants