{"record":{"id":"d4e6681fd6504638","repo":"jax-ml/jax","slug":"factor-factor-can-only-be-in-one-of-the-reductio","errorCode":null,"errorMessage":"Factor {factor} can only be in one of the reduction, need replication, or permutation factor sets.","messagePattern":"Factor (.+?) can only be in one of the reduction, need replication, or permutation factor sets\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/custom_partitioning_sharding_rule.py","lineNumber":173,"sourceCode":"      if factor in factor_sizes and inferable:\n        raise ValueError(\n          f\"Factor {factor} represents a whole dimension; do not specify its\"\n          \" size\")\n\n    special_factors = set()\n    def check_special_factors(kind, factors):\n      if not isinstance(factors, tuple):\n        raise ValueError(f\"{kind} must be a tuple of factors\")\n\n      if len(factors) != len(set(factors)):\n        raise ValueError(f\"{kind} contains duplicated factors\")\n\n      for factor in factors:\n        if factor not in factors_inferrable:\n          raise ValueError(\n            f\"Factor {factor} in {kind} is not used in the rule\")\n        if factor in special_factors:\n          raise ValueError(f\"Factor {factor} can only be in one of the \"\n              f\"reduction, need replication, or permutation factor sets.\")\n        special_factors.add(factor)\n\n    check_special_factors(\"reduction_factors\", reduction_factors)\n    check_special_factors(\"need_replication_factors\", need_replication_factors)\n    check_special_factors(\"permutation_factors\", permutation_factors)\n\n    self.operand_mappings = operand_mappings\n    self.result_mappings = result_mappings\n    self.factor_sizes = factor_sizes\n    self.reduction_factors = reduction_factors\n    self.need_replication_factors = need_replication_factors\n    self.permutation_factors = permutation_factors\n\n\n  def __str__(self):\n    def to_str(kind, factors):\n      if len(factors) > 0:","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/custom_partitioning_sharding_rule.py#L155-L191","documentation":"A factor may belong to only one of the three special sets (reduction, need-replication, permutation). special_factors accumulates seen factors across all three checks and rejects a repeat.","triggerScenarios":"reduction_factors=('m',) and need_replication_factors=('m',) in the same call.","commonSituations":"Iterating on sharding rules and moving a factor between categories without removing it from the old one.","solutions":["Keep the factor in exactly one of the three tuples and delete it from the others","If different behavior is needed for the same name, rename one occurrence in the rule to a distinct factor"],"exampleFix":"# before\nreduction_factors=('m',), need_replication_factors=('m',)\n# after\nreduction_factors=('m',), need_replication_factors=('r',)","handlingStrategy":"validation","validationCode":"sets = [reduction_factors, need_replication_factors, permutation_factors]\nseen = set()\nfor s in sets:\n    assert not (seen & set(s)), f'factor in multiple sets: {seen & set(s)}'\n    seen |= set(s)","typeGuard":"def disjoint_factor_sets(*sets) -> bool:\n    seen = set()\n    return not any(seen & set(s) or (seen := seen | set(s)) for s in sets)","tryCatchPattern":null,"preventionTips":["When moving a factor between categories, delete it from the old tuple in the same commit"],"tags":["jax","sharding","conflicting-config","validation"],"backgroundTag":"conflicting-config-values","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}