{"record":{"id":"c7b9623f8b5ccb55","repo":"jax-ml/jax","slug":"factor-factor-represents-a-whole-dimension-do-n","errorCode":null,"errorMessage":"Factor {factor} represents a whole dimension; do not specify its size","messagePattern":"Factor (.+?) represents a whole dimension; do not specify its size","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/custom_partitioning_sharding_rule.py","lineNumber":156,"sourceCode":"            if factor not in factors_inferrable.keys():\n              factors_inferrable[factor] = False\n\n    # Check that factors in factor_sizes are used in the rule.\n    for factor in factor_sizes:\n      if factor not in factors_inferrable:\n        raise ValueError(\n          f\"Factor {factor} is not used in the rule, but size is provided\")\n\n    # Check that factors that are used for a whole dimension aren't in\n    # 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.\")","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/custom_partitioning_sharding_rule.py#L138-L174","documentation":"The factor maps to a whole dimension on its own (inferable), so its size is derived from the array shape and must NOT be supplied in factor_sizes. Supplying it is contradictory and rejected.","triggerScenarios":"rule='(i,j)->(i,j)' with factor_sizes={'i':8} where 'i' occupies an entire dimension by itself.","commonSituations":"Over-specifying sizes 'just to be safe'; migrating a rule where a factor used to be compound but now covers a whole dim.","solutions":["Delete that factor's entry from factor_sizes","Restructure the rule so the factor appears only inside compound factors if you truly need to fix its size"],"exampleFix":"# before\ndef_partition(fn, rule='(i,j)->(i,j)', factor_sizes={'i':8})\n# after\ndef_partition(fn, rule='(i,j)->(i,j)')","handlingStrategy":"validation","validationCode":"# ensure no factor that spans a whole dimension is in factor_sizes\nwhole_dims = {f for op in rule.replace('->', ',').split(',') for f in ([op.strip()] if op.strip().isidentifier() else [])}\nbad = whole_dims & set(factor_sizes)\nassert not bad, f'remove whole-dim factors from factor_sizes: {bad}'","typeGuard":"def no_whole_dim_sizes(rule: str, factor_sizes: dict[str, int]) -> bool:\n    dims = [d.strip() for d in rule.replace('->', ',').split(',')]\n    return not ({d for d in dims if d.isidentifier()} & set(factor_sizes))","tryCatchPattern":null,"preventionTips":["Only factors inside compound parens belong in factor_sizes","When a rule changes, re-audit every factor's placement"],"tags":["jax","sharding","factor-sizes","redundant-config"],"backgroundTag":"redundant-config-value","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}