jax-ml/jax · error · ValueError

Brackets should contain at least two factors

Error message

Brackets should contain at least two factors

What it means

A parenthesized compound factor must list at least two factors, e.g. '(a,b)'; '(a)' with a single factor is rejected because it adds no meaning.

Source

Thrown at jax/_src/custom_partitioning_sharding_rule.py:290

        batching_group = "0"

      add_factor(f"{BATCHING}{batching_group}")
      continue
    if char in "(), ":
      if current_factor is not None:
        add_factor(current_factor)
        current_factor = None
      if char == "(":
        if current_compound_dim is not None:
          raise ValueError(
              "Compound factors should be one level, nested brackets are not"
              " allowed")
        current_compound_dim = []
      elif char == ")":
        if current_compound_dim is None:
          raise ValueError("Brackets are not balanced")
        if len(current_compound_dim) <= 1:
          raise ValueError("Brackets should contain at least two factors")
        value.append(CompoundFactor(*current_compound_dim))
        current_compound_dim = None
      elif char == ",":
        all_values.append(ArrayMapping(*value))
        value = []
    elif char == "_" or char.isdigit() or char.isalpha():
      if current_factor is None:
        if str.isdigit(char):
          raise ValueError(f"Factor names have to start with a letter, but got '{char}'")
        current_factor = char
      else:
        current_factor += char
    else:
      raise ValueError(f"Unknown character '{char}'")

  if current_compound_dim is not None:
    raise ValueError(f"Brackets are not balanced in rule: '{rule}'")
  if current_factor is not None:

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Remove the parentheses around the single factor
  2. Add a second factor if a compound dim was intended: '(a,b)'

Example fix

# before
rule = '(a),b->b'
# after
rule = 'a,b->b'
Defensive patterns

Strategy: validation

Validate before calling

import re
assert not re.search(r'\([^),]+\)', rule), 'compound factor needs >= 2 factors'

Type guard

import re
def no_single_factor_parens(rule: str) -> bool:
    return re.search(r'\([^),]+\)', rule) is None

Prevention

When it happens

Trigger: Rule like '(a),b->b' where a compound factor wraps one name.

Common situations: Programmatically wrapping factors in parentheses uniformly, including singletons; leftover parens after deleting a factor.

Related errors


AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27). Data as JSON: /api/errors/01ddd6d4747a1ed1. Report an issue: GitHub.