{"record":{"id":"285c556d410afc11","repo":"jax-ml/jax","slug":"axis-names-argument-of-shard-map-should-be-of-ty","errorCode":null,"errorMessage":"`axis_names` argument of shard_map should be of type `frozenset` or `set`. Got type: {type(axis_names)}","messagePattern":"`axis_names` argument of shard_map should be of type `frozenset` or `set`\\. Got type: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/shard_map.py","lineNumber":390,"sourceCode":"    ctx_mesh = get_abstract_mesh()\n    if not ctx_mesh.empty and mesh.abstract_mesh != ctx_mesh:\n      raise ValueError(\n          f\"The context mesh {ctx_mesh} should match the mesh passed to\"\n          f\" shard_map {mesh}\")\n\n  if not isinstance(mesh, (Mesh, AbstractMesh)):\n    raise TypeError(\"shard_map requires a `jax.sharding.Mesh` or a \"\n                    \"`jax.sharding.AbstractMesh` instance for its \"\n                    f\"second argument, but got {mesh} of type {type(mesh)}.\")\n  if mesh.empty:\n    raise ValueError(f\"shard_map requires a non-empty mesh. Got {mesh}\")\n\n  mesh_axis_names_wo_vmap = (\n      frozenset(mesh.axis_names) - core.get_axis_env().explicit_mesh_axis_names\n  )\n\n  if not isinstance(axis_names, (frozenset, set)):\n    raise TypeError(\n        \"`axis_names` argument of shard_map should be of type `frozenset` or\"\n        f\" `set`. Got type: {type(axis_names)}\")\n  if isinstance(axis_names, set):\n    axis_names = frozenset(axis_names)\n  if not axis_names:\n    axis_names = mesh_axis_names_wo_vmap\n  if not axis_names.issubset(mesh_axis_names_wo_vmap):\n    raise ValueError(\n        f\"jax.shard_map requires axis_names={axis_names} to be a subset of \"\n        f\"mesh.axis_names={mesh_axis_names_wo_vmap}\")\n\n  if (in_specs is Infer and\n      not all(mesh._name_to_type[a] == AxisType.Explicit for a in axis_names)):\n    axis_types = ', '.join(str(mesh._name_to_type[a]) for a in axis_names)\n    if _smap:\n      msg = (f\"in_axes was not specified when axis_name={axis_names} was of\"\n             f\" type {axis_types}\")\n    else:","sourceCodeStart":372,"sourceCodeEnd":408,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/shard_map.py#L372-L408","documentation":"shard_map's internal _shmap_checks requires axis_names to be a frozenset or set of mesh axis names. Passing any other container type — list, tuple, string, or None — raises this TypeError reporting the actual type received.","triggerScenarios":"Calling shard_map(..., axis_names=('i','j')) (tuple), axis_names=['i'] (list), axis_names='i' (bare string), or axis_names=None. This typically happens when calling the private _shard_map path or smap incorrectly, since the public shard_map API wraps names into a frozenset.","commonSituations":"Using jax.experimental.smap or internal/lower-level shard_map entry points; refactoring code that previously passed a single name; version upgrades that tightened axis_names typing.","solutions":["Wrap names in a set/frozenset: axis_names=frozenset({'i','j'})","Use the public jax.shard_map API which normalizes the argument for you"],"exampleFix":"// before\nshard_map(f, mesh=mesh, in_specs=P('i'), out_specs=P('i'), axis_names=('i',))\n\n// after\nshard_map(f, mesh=mesh, in_specs=P('i'), out_specs=P('i'), axis_names=frozenset({'i'}))","handlingStrategy":"type-guard","validationCode":"assert isinstance(axis_names, (frozenset, set)), type(axis_names)\naxis_names = frozenset(axis_names)","typeGuard":"def is_valid_axis_names(ns) -> bool:\n    return isinstance(ns, (frozenset, set))","tryCatchPattern":null,"preventionTips":["Always pass axis_names as frozenset({...})","Prefer the public jax.shard_map API which normalizes the argument"],"tags":["jax","shard-map","axis-names","type-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}