{"record":{"id":"140c4a3cdecd6e9b","repo":"jax-ml/jax","slug":"factor-names-have-to-start-with-a-letter-but-got","errorCode":null,"errorMessage":"Factor names have to start with a letter, but got '{factor[0]}'","messagePattern":"Factor names have to start with a letter, but got '(.+?)'","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"jax/_src/custom_partitioning_sharding_rule.py","lineNumber":38,"sourceCode":"from jax._src.lib.mlir.dialects import sdy\n\n\n# A single character replacement for ... to simplify parsing.\nBATCHING: str = \"…\"\n\n# A prefix for names of batching dimension factors, used for expanding the\n# leading ... into factors.\n_BATCHING_DIM_FACTOR_PREFIX = \"?\"\n\n\ndef _check_factor(factor:str):\n  \"\"\"Validates a factor.\n\n  A factor is a string starting with a letter and containing only letters,\n  digits, or underscores.\n  \"\"\"\n  if not factor[0].isalpha():\n    raise ValueError(f\"Factor names have to start with a letter, but got '{factor[0]}'\")\n  for char in factor[1:]:\n    if char != \"_\" and not char.isdigit() and not char.isalpha():\n      raise ValueError(f\"Unknown character '{char}'\")\n\ndef _is_batching(factor: str) -> bool:\n  \"\"\"Checks if a factor is a representation for leading batching dimensions.\n\n  Leading batching dimensions is represented by a factor containing ... and\n     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","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/custom_partitioning_sharding_rule.py#L20-L56","documentation":"Factor names in SdyShardingRule / ArrayMapping notation must start with an ASCII letter. This ValueError is raised when a factor string begins with a digit, underscore, or symbol.","triggerScenarios":"Constructing ArrayMapping('1x', 'b') or using a sharding-rule string where a factor token starts with a digit or '-' (e.g. '0 i -> i', or negative-sign tokens parsed as factors).","commonSituations":"Typos in Einsum-like sharding rules; using dimension indices as factor names; copy-pasting from GSPMD replication strings.","solutions":["Rename the factor to start with a letter, e.g. 'd0' instead of '0'","Check the rule string for stray symbols adjacent to factor tokens","Use descriptive factor names matching mesh axes"],"exampleFix":"# before\nrule = SdyShardingRule((ArrayMapping('0', 'i'), ArrayMapping('i', '0')), ...)\n\n# after\nrule = SdyShardingRule((ArrayMapping('d0', 'i'), ArrayMapping('i', 'd0')), ...)","handlingStrategy":"validation","validationCode":"import re\nFACTOR = re.compile(r'^[A-Za-z][A-Za-z0-9_]*$')\ndef check_factor(f): assert FACTOR.match(f), f","typeGuard":"def valid_factor(f: str) -> bool:\n    return bool(re.match(r'^[A-Za-z][A-Za-z0-9_]*$', f))","tryCatchPattern":null,"preventionTips":["Use letter-first factor names like 'd0', 'd1'","Lint sharding-rule strings for factor tokens"],"tags":["jax","shardy","sharding-rule","validation"],"backgroundTag":"invalid-identifier-name","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}