Refactor: Decouple Core Transformer Blocks #1852
Open
+792
−735
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TL;DR
What: This PR refactors the core
DecoderLayer
and its related components out oflayers/models.py
and into a new, foundational file:layers/blocks.py
.Why: To improve the overall code architecture and break potential circular dependencies. This is a necessary prerequisite for adding new, complex modules that also need access to these core building blocks.
How: By creating
layers/blocks.py
to house the fundamentalDecoder
andDecoderLayer
classes. Higher-level files likemodels.py
and other future modules now import these components from a single location.Detailed Description
This pull request introduces a structural refactoring to improve modularity and maintainability.
The primary change is the creation of
MaxText/layers/blocks.py
, which now serves as the source for fundamental building blocks of the Transformer architecture, such as:DecoderLayer
Decoder
Previously, these classes were located in
layers/models.py
, which created tight coupling. As we add more features this tight coupling would lead to circular import dependencies.By decoupling these core components, we establish a clearer hierarchy in the codebase, where high-level modules can depend on these "building blocks" without depending on each other.
Checklist
Before submitting this PR, please make sure (put X in square brackets):