Skip to content

refactor(char-causal-lm): drop redundant gradient checkpointing overrides - #13

Closed
AmitMY wants to merge 1 commit into
test/gradient-checkpointing-coveragefrom
simplify/drop-redundant-gc-overrides
Closed

refactor(char-causal-lm): drop redundant gradient checkpointing overrides#13
AmitMY wants to merge 1 commit into
test/gradient-checkpointing-coveragefrom
simplify/drop-redundant-gc-overrides

Conversation

@AmitMY

@AmitMY AmitMY commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Audit item #7, part two. Stacked on #10 — based on that branch so its four new tests run against this deletion. Merge #10 first; GitHub will retarget this to main automatically.

-    def gradient_checkpointing_enable(self, gradient_checkpointing_kwargs=None):
-        """Enable gradient checkpointing on the underlying model."""
-        self.model.gradient_checkpointing_enable(gradient_checkpointing_kwargs=gradient_checkpointing_kwargs)
-
-    def gradient_checkpointing_disable(self):
-        """Disable gradient checkpointing on the underlying model."""
-        self.model.gradient_checkpointing_disable()

Both only forwarded to self.model — which is exactly what PreTrainedModel already does. Its own implementation walks submodules and reaches the wrapped model without help.

Verified, not assumed

This is why #10 came first. With the overrides deleted, all four of those tests still pass on both CI transformers versions:

transformers 4.57.6 transformers 5.14.1
enable reaches wrapped model
disable reaches wrapped model
gradient_checkpointing_kwargs form
forward + backward produces gradients

245 passed on both. ruff clean.

If you would rather keep the explicit delegation as documentation of intent, that is a fair call — closing this costs nothing, and #10's tests are worth having either way.

🤖 Generated with Claude Code


Note

Low Risk
Small deletion of pass-through methods; behavior is covered by existing gradient-checkpointing tests on the stacked PR.

Overview
Removes gradient_checkpointing_enable and gradient_checkpointing_disable from CharacterCausalLMWrapper because they only delegated to the inner self.model.

PreTrainedModel already enables and disables gradient checkpointing across submodules, and the wrapper still sets supports_gradient_checkpointing = True, so training behavior is unchanged. Companion tests on the stacked branch cover both transformers versions.

Reviewed by Cursor Bugbot for commit 389f7b1. Bugbot is set up for automated code reviews on this repo. Configure here.

…ides

Both overrides only forwarded to self.model, which is what PreTrainedModel
already does: its own implementation walks submodules and reaches the
wrapped model on its own.

Verified against the four tests added in #10 rather than assumed. With the
overrides deleted, enable/disable/kwargs and the backward pass all still
pass on transformers 4.57.6 and 5.14.1: 245 passed on both.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@AmitMY
AmitMY deleted the branch test/gradient-checkpointing-coverage July 27, 2026 11:23
@AmitMY AmitMY closed this Jul 27, 2026
@AmitMY

AmitMY commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

Closing (auto-closed when #10's base branch was deleted, and that is the right outcome): keeping the explicit gradient_checkpointing_enable/disable delegation.

The measurement stands — PreTrainedModel's own implementation does reach the wrapped model on both transformers 4.57.6 and 5.14.1 — but relying on that means depending on transformers' submodule walk continuing to work through this wrapper in future versions. The explicit forwarding states the intent for 7 lines. Not worth the coupling.

The four tests from #10 are merged and remain valuable either way: they pin delegation behaviour that was previously untested, so a future transformers change that breaks it fails loudly instead of silently disabling checkpointing mid-training.

@AmitMY
AmitMY deleted the simplify/drop-redundant-gc-overrides branch July 27, 2026 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant