Skip to content

llada fixes - #146

Merged
copybara-service[bot] merged 5 commits into
jax-ml:mainfrom
chapman20j:llada_fixes
Feb 2, 2026
Merged

llada fixes#146
copybara-service[bot] merged 5 commits into
jax-ml:mainfrom
chapman20j:llada_fixes

Conversation

@chapman20j

Copy link
Copy Markdown
Collaborator

Resolves #65

Checklist

  • I have read the Contribution Guidelines and used pre-commit hooks to format this commit.
  • I have added all the necessary unit tests for my change. (run_model.py for model usage, test_outputs.py and/or model_validation_colab.ipynb for quality).
  • (If using an LLM) I have carefully reviewed and removed all superfluous comments or unneeded, commented-out code. Only necessary and functional code remains.
  • I have signed the Contributor License Agreement (CLA).

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @chapman20j, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the LLaDA model implementation within the bonsai repository. It introduces a new, more robust, and sharding-aware JAX/Flax NNX implementation of the LLaDA model, addressing previous issues and enhancing its capabilities. The changes include a complete rewrite of the model architecture, integration of explicit sharding, and a sophisticated block-wise text generation mechanism. This update aims to provide a more efficient and scalable LLaDA model for JAX users.

Highlights

  • New LLaDA Model Implementation: Introduced a pure JAX implementation of the LLaDA model using the Flax NNX API, providing a modern and flexible architecture.
  • Sharding Support: Added ShardingConfig, ShardedLinear, and ShardedEmbedding to enable explicit sharding for model parameters and activations, crucial for large-scale model deployment.
  • Block-wise Generation: Implemented a generate function for efficient block-wise text generation, incorporating features like Gumbel noise, classifier-free guidance, and various remasking strategies.
  • Pretrained Weight Loading: Provided utilities in params.py to load and convert pretrained LLaDA weights from safetensors files into the new Flax NNX model structure, including support for sharding.
  • Refactor and Rename: The previous bonsai/models/llada_8b directory and its contents have been entirely removed, replaced by the new and improved implementation under bonsai/models/llada.
  • Comprehensive Testing: Included run_model.py for practical inference examples and test_outputs_llada.py for numerical validation of model components and full forward passes against a baseline PyTorch model.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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

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.

Code Review

This pull request introduces a significant and valuable refactoring of the LLaDA model implementation. The new code is more focused and cleaner than the previous generic version. However, I've identified several critical issues that will prevent the code from executing correctly, including unpacking errors and incorrect function arguments. There are also several medium-severity issues related to code correctness and best practices. Addressing these points will greatly improve the quality and robustness of this new implementation.

Comment thread bonsai/models/llada/modeling.py Outdated
Comment thread bonsai/models/llada/modeling.py Outdated
Comment thread bonsai/models/llada/params.py
Comment thread bonsai/models/llada/tests/test_outputs_llada.py
Comment thread bonsai/models/llada/README.md
Comment thread bonsai/models/llada/modeling.py Outdated
Comment thread bonsai/models/llada/modeling.py Outdated
Comment thread bonsai/models/llada/params.py
Comment thread bonsai/models/llada/tests/run_model.py
Comment thread bonsai/models/llada/tests/test_outputs_llada.py Outdated
self.config = cfg
shd = cfg.shd_cfg
ei = partial(default_embed_init, out_sharding=cfg.shd_cfg.emb_kernel)
self.wte = ShardedEmbedding(cfg.embedding_size, cfg.d_model, embedding_init=ei, rngs=rngs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could we avoid non-obvious acronyms?

@copybara-service
copybara-service Bot merged commit 8280f9d into jax-ml:main Feb 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LLaDA-8B] Full forward and first block test fails (NaN logits) likely due to missing attention mask

2 participants