{"record":{"id":"dd6521a2bf5b198b","repo":"jax-ml/jax","slug":"kind-contains-duplicated-factors","errorCode":null,"errorMessage":"{kind} contains duplicated factors","messagePattern":"(.+?) contains duplicated factors","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/custom_partitioning_sharding_rule.py","lineNumber":166,"sourceCode":"    # factor_sizes and factors that are never used for a whole dimension are\n    # in factor_sizes.\n    for factor, inferable in factors_inferrable.items():\n      if factor not in factor_sizes and not inferable:\n        raise ValueError(\n          f\"Factor {factor} is only used in compound factors; must specify\"\n          \" its size\")\n      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","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/custom_partitioning_sharding_rule.py#L148-L184","documentation":"check_special_factors requires all factor names within one special-factor tuple to be unique; len(factors) != len(set(factors)) detects duplicates.","triggerScenarios":"reduction_factors=('m','m') passed to def_partition.","commonSituations":"Concatenating factor lists programmatically and accidentally repeating an entry.","solutions":["Deduplicate while preserving order, e.g. tuple(dict.fromkeys(factors))","Fix the source list so each factor appears once"],"exampleFix":"# before\nreduction_factors = ('m', 'm')\n# after\nreduction_factors = ('m',)","handlingStrategy":"validation","validationCode":"assert len(factors) == len(set(factors)), f'duplicates: {factors}'","typeGuard":"def no_dup_factors(factors: tuple) -> bool:\n    return len(factors) == len(set(factors))","tryCatchPattern":null,"preventionTips":["Deduplicate with tuple(dict.fromkeys(factors)) when building programmatically"],"tags":["jax","sharding","duplicate-values","validation"],"backgroundTag":"duplicate-config-entry","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}