Skip to content

Refactor: Decouple Core Transformer Blocks #1852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

parambole
Copy link
Collaborator

@parambole parambole commented Jun 19, 2025

TL;DR

  • What: This PR refactors the core DecoderLayer and its related components out of layers/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 fundamental Decoder and DecoderLayer classes. Higher-level files like models.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):

  • I have performed a self-review of my code.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed.

@parambole parambole force-pushed the parambole/mtp_refactor branch from c7e43e0 to 2e56b95 Compare June 19, 2025 18:59
@parambole parambole changed the title Refactor: Decouple Decoder into layers/blocks.py Refactor: Decouple Core Transformer Blocks Jun 19, 2025
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.

3 participants