jax-ml/jax · error · ValueError

{kind} contains duplicated factors

Error message

{kind} contains duplicated factors

What it means

check_special_factors requires all factor names within one special-factor tuple to be unique; len(factors) != len(set(factors)) detects duplicates.

Source

Thrown at jax/_src/custom_partitioning_sharding_rule.py:166

    # factor_sizes and factors that are never used for a whole dimension are
    # in factor_sizes.
    for factor, inferable in factors_inferrable.items():
      if factor not in factor_sizes and not inferable:
        raise ValueError(
          f"Factor {factor} is only used in compound factors; must specify"
          " its size")
      if factor in factor_sizes and inferable:
        raise ValueError(
          f"Factor {factor} represents a whole dimension; do not specify its"
          " size")

    special_factors = set()
    def check_special_factors(kind, factors):
      if not isinstance(factors, tuple):
        raise ValueError(f"{kind} must be a tuple of factors")

      if len(factors) != len(set(factors)):
        raise ValueError(f"{kind} contains duplicated factors")

      for factor in factors:
        if factor not in factors_inferrable:
          raise ValueError(
            f"Factor {factor} in {kind} is not used in the rule")
        if factor in special_factors:
          raise ValueError(f"Factor {factor} can only be in one of the "
              f"reduction, need replication, or permutation factor sets.")
        special_factors.add(factor)

    check_special_factors("reduction_factors", reduction_factors)
    check_special_factors("need_replication_factors", need_replication_factors)
    check_special_factors("permutation_factors", permutation_factors)

    self.operand_mappings = operand_mappings
    self.result_mappings = result_mappings
    self.factor_sizes = factor_sizes
    self.reduction_factors = reduction_factors

View on GitHub (pinned to 1e1c6a8fc0)

Solutions

  1. Deduplicate while preserving order, e.g. tuple(dict.fromkeys(factors))
  2. Fix the source list so each factor appears once

Example fix

# before
reduction_factors = ('m', 'm')
# after
reduction_factors = ('m',)
Defensive patterns

Strategy: validation

Validate before calling

assert len(factors) == len(set(factors)), f'duplicates: {factors}'

Type guard

def no_dup_factors(factors: tuple) -> bool:
    return len(factors) == len(set(factors))

Prevention

When it happens

Trigger: reduction_factors=('m','m') passed to def_partition.

Common situations: Concatenating factor lists programmatically and accidentally repeating an entry.

Related errors


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