{"record":{"id":"6d696e1341a11b51","repo":"jax-ml/jax","slug":"a-compound-factor-should-contain-at-least-two-fact","errorCode":null,"errorMessage":"A compound factor should contain at least two factors","messagePattern":"A compound factor should contain at least two factors","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/custom_partitioning_sharding_rule.py","lineNumber":65,"sourceCode":"     optionally followed by a digit, and ... is equivalent to ...0.\n  \"\"\"\n  if len(factor) < 1 or factor[0] != BATCHING:\n    return False\n  return len(factor) == 1 or factor[1:].isdigit()\n\ndef _get_batching_group(factor: str) -> str:\n  \"\"\"Extracts the batching group from a factor for leading batching dimensions.\"\"\"\n  return factor[1:] if len(factor) > 1 else \"0\"\n\nclass CompoundFactor(tuple):\n  \"\"\"Describes the factors for a compound factor.\n\n  A compound factor should contain at least two factors, e.g.\n  * CompoundFactor('b', 'c').\n  \"\"\"\n  def __init__(self, *factors):\n    if len(factors) < 2:\n      raise ValueError(\"A compound factor should contain at least two factors\")\n    for factor in factors:\n      if not isinstance(factor, str):\n        raise ValueError(f\"Each element of CompoundFactor must be a str, but got {type(factor)}\")\n      if _is_batching(factor):\n        raise ValueError(\"Ellipsis can't be used in a compound factor\")\n      else:\n        _check_factor(factor)\n\n  def __new__(cls, *factors):\n    return tuple.__new__(CompoundFactor, factors)\n\n\nclass ArrayMapping(tuple):\n  \"\"\"Describes the factors for an operand or result.\n\n  Each element is either a factor or a CompoundFactor. A leading element can\n  also be BATCHING, which represents batching dimensions. examples:\n  * ArrayMapping('a')","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/custom_partitioning_sharding_rule.py#L47-L83","documentation":"CompoundFactor groups multiple factors that must all be matched along a single dimension; it requires at least two factors. Constructing CompoundFactor with fewer raises ValueError.","triggerScenarios":"Calling CompoundFactor('b') (one factor) or CompoundFactor() (none) while building an SdyShardingRule mapping.","commonSituations":"Programmatic rule generation that loops over factor lists and can emit a singleton compound factor.","solutions":["Pass at least two factors, e.g. CompoundFactor('b', 'c')","If only one factor applies, use the plain string 'b' instead of CompoundFactor","Guard generated rule builders against singleton lists"],"exampleFix":"# before\nCompoundFactor('b')\n\n# after\n'b'  # single factor needs no CompoundFactor","handlingStrategy":"validation","validationCode":"assert len(factors) >= 2, 'CompoundFactor needs >= 2 factors'\nCompoundFactor(*factors) if len(factors) >= 2 else factors[0]","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In generated rules, replace singleton factor lists with the bare string"],"tags":["jax","shardy","sharding-rule","validation"],"backgroundTag":"invalid-constructor-arguments","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}