jax-ml/jax · error · ValueError
Compound factors should be one level, nested brackets are…
Error message
Compound factors should be one level, nested brackets are not allowed
What it means
Parse error in the einsum-like sharding-rule string: '(' was encountered while already inside a parenthesized group. Compound factors (parenthesized groups) may not nest, so 'a(b c)' style input is rejected by _parse_values.
Solutions
- Flatten to a single level: '(a,b,c)'
- Express deeper structure via factor_sizes and separate factors instead of nesting
Example fix
# before rule = '((a,b),c)->(a,b,c)' # after rule = '(a,b,c)->(a,b,c)'
Defensive patterns
Strategy: validation
Validate before calling
import re
assert not re.search(r'\([^)]*\(', rule), 'nested compound factors not allowed' Type guard
import re
def is_flat_compounds(rule: str) -> bool:
return re.search(r'\([^)]*\(', rule) is None Prevention
- Keep compound factors one level deep: '(a,b,c)'
When it happens
Trigger: Rule containing '((a,b),c)' or '(a,(b,c))'.
Common situations: Trying to express hierarchical factor trees like mesh axis trees in the rule string.
Related errors
- Brackets should contain at least two factors
- Brackets are not balanced
- Brackets are not balanced in rule
- Character '.' must be used inside ellipsis '...'
- Factor is only used in compound factors; must specify its…
AI-assisted analysis of jax-ml/jax@1e1c6a8fc0 (2026-08-27).
Data as JSON: /api/errors/af4b0c0c6f6d513c.
Report an issue: GitHub.
Appendix: source
Thrown at jax/_src/custom_partitioning_sharding_rule.py:282
"Ellipsis can only be used at the beginning of a dimension")
if rule_index < rule_len and rule[rule_index].isdigit():
batching_group_str = ""
while rule_index < rule_len and rule[rule_index].isdigit():
batching_group_str += rule[rule_index]
rule_index += 1
batching_group = str(int(batching_group_str))
else:
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 = charView on GitHub (pinned to 1e1c6a8fc0)