← Back to Pull requests

Validate feature_group_count in nnx.Conv constructor #5624

Open
unknown opened this pull request with 279 lines diff across 3 files
View on GitHub
unknown unknown commented on Oct 25, 2026 21:48 UTC
Author

What does this PR do?

nnx.Conv accepts a feature_group_count that does not divide in_features. It builds a kernel of the wrong shape and only fails on the first call, with a bare AssertionError that has no message:

from flax import nnx
import jax.numpy as jnp

m = nnx.Conv(3, 4, kernel_size=(3,), feature_group_count=2, rngs=nnx.Rngs(0))
m.kernel.shape            # (3, 1, 4)
m(jnp.ones((1, 8, 3)))    # AssertionError (empty message)

nnx.Conv(4, 4, kernel_size=(3,), feature_group_count=0, rngs=nnx.Rngs(0))
# ZeroDivisionError: integer division or modulo by zero

This PR checks both conditions in Conv.__init__, where in_features and feature_group_count are both known. It raises ValueError with the offending values, for example in_features (3) must be divisible by feature_group_count (2). It also removes the now-redundant assert in Conv.__call__, and adds one sentence to the feature_group_count docstring. This follows the same pattern as #5505.

I left out_features divisibility alone. lax.conv_general_dilated already raises a clear ValueError for it at call time, and checking it in __init__ would also reject a custom conv_general_dilated that handles it.

Tests: a new TestConvValidation class in tests/nnx/nn/conv_test.py. It has four invalid cases (3/2, 8/3, 0, -2) and one valid grouped case that checks the kernel shape and a forward pass. The four invalid cases fail on main and pass with this change. tests/nnx/nn/conv_test.py, tests/nnx/nn and ruff check on both files were run on Windows with CPU jax 0.12.0.1; CI covers Linux.

No linked issue. This is a small bug found while reading flax/nnx/nn/linear.py.

Checklist


  • This PR fixes a minor issue (e.g.: typo or small bug) or improves the docs (you can dismiss the other checks if that's the case).

  • This change is discussed in a Github issue/discussion (please add a link).

  • The documentation and docstrings adhere to the documentation guidelines.

  • This change includes necessary high-coverage tests. (No quality testing = no merge!)
  • Diff: 279 lines (+209 / -70) across 3 files Reviewer: samanklesaria Review duration: 51647m
    All Vouch review confidence checks passed
    Residual risk 0.26 = Change Risk (0.47) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 279 lines diff across 3 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Shallow Review Depth shallow_review_depth
    0.344
    Diff Size diff_size
    0.337
    Real PR Conversation Timeline
    1 comments
    "Review active on #5624"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 46.6% (MEDIUM) · Higher = larger blast radius
    46.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.8% · Safe to merge
    25.8%
    Repository