Skip to content

[NNX] Remove remaining Linen module code and dead references - #5203

Draft
ecnal-cienet wants to merge 1 commit into
mainfrom
feat/nnx-linen-cleanup
Draft

[NNX] Remove remaining Linen module code and dead references#5203
ecnal-cienet wants to merge 1 commit into
mainfrom
feat/nnx-linen-cleanup

Conversation

@ecnal-cienet

@ecnal-cienet ecnal-cienet commented Sep 11, 2026

Copy link
Copy Markdown
Collaborator

Deletes the last first-party Flax Linen modules and their dead references, following the Delete-Linen stack:

  • Delete the unused pipeline_deprecated.py (a Linen Pipeline imported nowhere).
  • Drop a stray @nn.compact left on MixtralDecoderLayer.init (an nnx.Module) and mixtral's now-unused linen import.
  • Delete decoders.py, whose only remaining symbol deepstack_process is a byte-identical duplicate of the copy in nnx_decoders.py; repoint the one test.
  • Fix stale nn.Module docstrings and return-type hints to nnx.Module.

The remaining flax.linen usage (quantization einsum bridge, logical-sharding primitives) is load-bearing and tracked for a follow-up.

Description

Start with a short description of what the PR does and how this is a change from
the past.

The rest of the description includes relevant details and context, examples:

  • why is this change being made,
  • the problem being solved and any relevant context,
  • why this is a good solution,
  • some information about the specific implementation,
  • shortcomings of the solution and possible future improvements.

If the change fixes a bug or a Github issue, please include a link, e.g.,:
FIXES: b/123456
FIXES: #123456

You can also provide a comma-separated list. If you don't want to close a bug but
simply to reference it, use BUGS, e.g.:
BUGS: b/123456

Notice 1: Once all tests pass, the "pull ready" label will automatically be assigned.
This label is used for administrative purposes. Please do not add it manually.

Notice 2: For external contributions, our settings currently require an approval from a MaxText maintainer to trigger CI tests.

Tests

Please describe how you tested this change, and include any instructions and/or
commands to reproduce.

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • 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, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request transitions several modules and functions from Flax Linen to Flax NNX, updating docstrings, type annotations, and imports accordingly, and removes deprecated decoder and pipeline implementations. The review feedback points out a few incorrect return type annotations in pipeline.py and model_creation_utils.py where Linen-wrapped modules are returned, suggesting they should remain annotated as nn.Module or nn.Module | models.Transformer instead of nnx.Module or models.Transformer.

Comment thread src/maxtext/layers/pipeline.py Outdated
Comment thread src/maxtext/utils/model_creation_utils.py Outdated
Comment thread src/maxtext/utils/model_creation_utils.py Outdated
@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

@AI-Hypercomputer AI-Hypercomputer deleted a comment from google-cla Bot Sep 11, 2026
@ecnal-cienet
ecnal-cienet force-pushed the feat/nnx-linen-cleanup branch 5 times, most recently from b0728c0 to 3dd6786 Compare September 11, 2026 18:50
Continues the Delete-Linen effort. No behavior change; validated by the unit
suite on TPU (cpu platform) -- 3505 tests collect clean, affected suites pass.

Module / dead-code removal:
- Delete the unused pipeline_deprecated.py (a Linen Pipeline) and decoders.py
  (a 46-line vestige whose only symbol duplicated nnx_decoders.deepstack_process;
  repoint the one test).
- Drop a stray @nn.compact left on MixtralDecoderLayer.__init__ (an nnx.Module).
- Delete grep-confirmed zero-caller Linen functions: create_nnx_sharded_model_hybrid,
  get_logical_annotations, the Linen get_prefill_kv_cache_annotations /
  get_kv_cache_annotations, vocab_tiling_linen_loss, create_flax_pipeline_scan /
  create_pipeline_stage / execute_pipeline_stage_flax, remove_logically_partition,
  kv_cache_as_linen / mla_kv_cache_as_linen, gpt3_layer_norm, and the Linen
  grpo_loss_fn (train/eval step already dispatch only to the _nnx variants).

Shared-primitive imports moved off flax.linen (same underlying objects):
- nn_partitioning.axis_rules / nn.logical_axis_rules -> flax.core.spmd.logical_axis_rules
  across the trainers, inference, and utils that used it, dropping their flax.linen import.
- nn.initializers.* -> jax.nn.initializers.* ; nn.one_hot -> jax.nn.one_hot ;
  getattr(nn, activation) -> getattr(jax.nn, activation).

The remaining flax.linen usage (quantization einsum bridge, with_logical_constraint /
LogicallyPartitioned sharding primitives, ToLinen transformer bridge) is tracked for
follow-up PRs.
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