Skip to content

Models quick import - #164

Merged
copybara-service[bot] merged 3 commits into
jax-ml:mainfrom
vfdev-5:quick-import
Feb 19, 2026
Merged

Models quick import#164
copybara-service[bot] merged 3 commits into
jax-ml:mainfrom
vfdev-5:quick-import

Conversation

@vfdev-5

@vfdev-5 vfdev-5 commented Feb 13, 2026

Copy link
Copy Markdown
Member

Quicker model import
The idea is to simplify the model import and expose models inside bonsai.__init__:

Today’s API:

import flax.nnx as nnx
from bonsai.models.convnext.modeling import ConvNeXt, ModelConfig

cfg = ModelConfig.convnext_base_224()
model = ConvNeXt(cfg, rngs=nnx.Rngs(0))

Suggested API:

import flax.nnx as nnx
from bonsai import ConvNeXt, ConvNeXtConfig

cfg = ConvNeXtConfig.base_224()
model = ConvNeXt(cfg, rngs=nnx.Rngs(0))

Additionally, renamed model's configs to ModelConfig, e.g.
Mamba2Config -> ModelConfig

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 @vfdev-5, 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 enhances the usability and consistency of the bonsai model library by simplifying how models and their configurations are imported. By centralizing imports in a new __init__.py file and standardizing configuration class names to ModelConfig across various models, the API becomes more intuitive and easier to navigate for developers. This refactoring improves the developer experience without altering the core functionality of the models.

Highlights

  • Simplified Model Imports: A new bonsai/models/__init__.py file has been added to allow direct imports of models and their configurations from the bonsai package, streamlining the API for users.
  • Standardized Configuration Class Names: Model-specific configuration classes (e.g., Mamba2Config, SAM2Config, UMT5Config, VJEPA2Config) have been renamed to a generic ModelConfig within their respective modeling.py files. This change promotes consistency across the model library.
  • Updated References Across Files: All internal references to the old model configuration class names have been updated to ModelConfig in modeling.py, params.py, and test files for Mamba2, SAM2, UMT5, and VJEPA2 models to reflect the new naming convention.

🧠 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.

Changelog
  • bonsai/models/init.py
    • Added a new __init__.py file to expose various models and their configurations directly under the bonsai.models namespace.
    • Included __all__ list to explicitly define public API for models and their aliased ModelConfig classes.
  • bonsai/models/mamba2/modeling.py
    • Renamed Mamba2Config class to ModelConfig.
    • Updated all internal references to Mamba2Config to use ModelConfig.
  • bonsai/models/mamba2/params.py
    • Updated type hints and function parameters from Mamba2Config to ModelConfig.
  • bonsai/models/mamba2/tests/run_model.py
    • Updated the cfg parameter type hint from Mamba2Config to ModelConfig in _greedy_generate_cached.
    • Instantiated ModelConfig instead of Mamba2Config in run_model.
  • bonsai/models/mamba2/tests/test_outputs_mamba_2.py
    • Renamed test class TestMamba2Config to TestModelConfig.
    • Updated all instantiations and references of modeling.Mamba2Config to modeling.ModelConfig.
  • bonsai/models/sam2/modeling.py
    • Renamed SAM2Config class to ModelConfig.
    • Updated the cfg parameter type hint from SAM2Config to ModelConfig in build_sam2_model_from_config.
  • bonsai/models/sam2/params.py
    • Updated the config parameter type hint from model_lib.SAM2Config to model_lib.ModelConfig in create_sam2_from_pretrained.
  • bonsai/models/sam2/tests/SAM2_image_predictor_example.md
    • Updated the example code to use modeling.ModelConfig.sam2_small() instead of modeling.SAM2Config.sam2_small().
  • bonsai/models/sam2/tests/run_model.py
    • Updated the configuration instantiation from modeling.SAM2Config.sam2_tiny() to modeling.ModelConfig.sam2_tiny().
  • bonsai/models/umt5/README.md
    • Updated the contribution guidelines to refer to class ModelConfig instead of class UMT5Config.
  • bonsai/models/umt5/modeling.py
    • Renamed UMT5Config class to ModelConfig.
    • Updated all internal references to UMT5Config to use ModelConfig in class initializers and method signatures.
  • bonsai/models/umt5/params.py
    • Updated type hints and function parameters from model_lib.UMT5Config to model_lib.ModelConfig.
    • Modified logic to filter config fields based on model_lib.ModelConfig and instantiate model_lib.ModelConfig.
  • bonsai/models/vjepa2/modeling.py
    • Renamed VJEPA2Config class to ModelConfig.
    • Updated all internal references to VJEPA2Config to use ModelConfig in class initializers and method signatures.
  • bonsai/models/vjepa2/params.py
    • Updated import statement to use ModelConfig instead of VJEPA2Config.
    • Updated the cfg parameter type hint from VJEPA2Config to ModelConfig in create_model_from_safe_tensors.
  • bonsai/models/vjepa2/tests/run_model.py
    • Updated import statement to use ModelConfig instead of VJEPA2Config.
    • Instantiated ModelConfig instead of VJEPA2Config for model configuration.
  • bonsai/models/vjepa2/tests/test_outputs_vjepa2.py
    • Updated import statement to use ModelConfig instead of VJEPA2Config from transformers.
    • Updated instantiations of VJEPA2Config to ModelConfig for both Hugging Face and local model configurations.
Activity
  • The author has confirmed reading the Contribution Guidelines.
  • The author has confirmed using pre-commit hooks for formatting.
  • The author has confirmed adding all necessary unit tests.
  • The author has signed the Contributor License Agreement (CLA).
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 simplified API for importing models by exposing them and their configurations in the bonsai.models namespace. It also standardizes the configuration class name to ModelConfig across various models. The changes are mostly a large-scale refactoring, which appears to be correctly implemented. My review includes a critical fix for an incorrect refactoring in a test file that could lead to failures, and a medium-severity suggestion to improve code style and maintainability in the new __init__.py file.

Comment thread bonsai/models/vjepa2/tests/test_outputs_vjepa2.py Outdated
Comment thread bonsai/models/__init__.py
Quicker model import
The idea is to simplify the model import and expose models inside `bonsai.__init__`:

Today’s API:
``python
import flax.nnx as nnx
from bonsai.models.convnext.modeling import ConvNeXt, ModelConfig

cfg = ModelConfig.convnext_base_224()
model = ConvNeXt(cfg, rngs=nnx.Rngs(0))
```

Suggested API:
```python
import flax.nnx as nnx
from bonsai import ConvNeXt, ConvNeXtConfig

cfg = ConvNeXtConfig.base_224()
model = ConvNeXt(cfg, rngs=nnx.Rngs(0))
```

Additionally, renamed model's configs to ModelConfig, e.g.
Mamba2Config -> ModelConfig
@vfdev-5
vfdev-5 marked this pull request as ready for review February 13, 2026 17:40
@copybara-service
copybara-service Bot merged commit ef7247c into jax-ml:main Feb 19, 2026
5 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.

2 participants