{"record":{"id":"21b2e1c991c3f953","repo":"jax-ml/jax","slug":"factor-sizes-must-be-a-dict-of-str-to-int-but-got","errorCode":null,"errorMessage":"factor_sizes must be a dict of str to int, but got {factor_sizes}","messagePattern":"factor_sizes must be a dict of str to int, but got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/custom_partitioning_sharding_rule.py","lineNumber":338,"sourceCode":"\n  This is done by verifying that the input Einsum notation like string and\n  with optional special factors and factor sizes represents a valid sharding\n  rule and converting it to an internal representation.\n\n  Args:\n    rule: The Einsum notation like string for an operation.\n    reduction_factors: A tuple of factors that are reduction factors.\n    need_replication_factors: A tuple of factors that are need_replication factors.\n    permutation_factors: A tuple of factors that are permutation factors.\n    **factor_sizes: The optional factor sizes.\n\n  Raises:\n    ValueError: If there is any problem with the rule or factor_sizes.\n  \"\"\"\n  if not isinstance(rule, str):\n    raise TypeError(f\"rule must be a str, but got {type(rule)}\")\n  if not all(isinstance(size, int) for size in factor_sizes.values()):\n    raise TypeError(\n        f\"factor_sizes must be a dict of str to int, but got {factor_sizes}\")\n\n  # Replace ... with a single char to simplify parsing.\n  if BATCHING in rule:\n    raise ValueError(f\"Unknown character '{BATCHING}'\")\n  if \".\" in rule:\n    rule = rule.replace(\"...\", BATCHING)\n    if \".\" in rule:\n      raise ValueError(\"Character '.' must be used inside ellipsis '...'\")\n\n  try:\n    operands, results = rule.split(\"->\")\n  except ValueError as e:\n    raise ValueError(f\"There is no -> in rule: '{rule}'\") from e\n\n  operand_mappings = _parse_values(operands)\n  result_mappings = _parse_values(results)\n  return SdyShardingRule(operand_mappings, result_mappings,","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/custom_partitioning_sharding_rule.py#L320-L356","documentation":"factor_sizes must map factor-name strings to Python ints. The guard checks all values with isinstance(size, int); any float, string, numpy scalar type that isn't int, or None triggers TypeError.","triggerScenarios":"factor_sizes={'a': 2.0}, {'a': '2'}, or {'a': np.int64(2)} depending on isinstance behavior; most commonly floats from config parsing or YAML.","commonSituations":"Sizes loaded from JSON/YAML where numbers parse as floats; computed sizes like prod(mesh) returning numpy scalars.","solutions":["Coerce values with int(): {k: int(v) for k, v in factor_sizes.items()}","Fix the config source so sizes are integers (e.g. quote-check YAML)","Cast numpy scalars via int() before building the dict"],"exampleFix":"# before\nfactor_sizes = {'a': 2.0}\n# after\nfactor_sizes = {'a': int(2.0)}","handlingStrategy":"type-guard","validationCode":"factor_sizes = {k: int(v) for k, v in factor_sizes.items()}","typeGuard":"def is_int_factor_sizes(fs: dict) -> bool:\n    return all(isinstance(k, str) and isinstance(v, int) and not isinstance(v, bool) for k, v in fs.items())","tryCatchPattern":null,"preventionTips":["Coerce YAML/JSON-loaded sizes with int()","Watch numpy scalar types from mesh computations"],"tags":["jax","sharding","type-error","factor-sizes"],"backgroundTag":"wrong-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}