{"record":{"id":"bca5baea5c1a4730","repo":"jax-ml/jax","slug":"shard-map-requires-a-callable-for-its-first-argume","errorCode":null,"errorMessage":"shard_map requires a callable for its first argument, but got {f} of type {type(f)}.","messagePattern":"shard_map requires a callable for its first argument, but got (.+?) of type (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/shard_map.py","lineNumber":254,"sourceCode":"    raise TypeError(\"smap out_axes must be an int, None, or (nested) container \"\n                    f\"with those types as leaves, but got {out_axes}.\")\n\n  in_specs = (Infer if in_axes is Infer else\n              tree_map(partial(_axes_to_pspec, axis_name), in_axes,\n                       is_leaf=lambda x: x is None))\n  out_specs = tree_map(partial(_axes_to_pspec, axis_name), out_axes,\n                       is_leaf=lambda x: x is None)\n  return _shard_map(f, mesh=None, in_specs=in_specs, out_specs=out_specs,\n                    axis_names={axis_name}, check_vma=True, _smap=True)\n\n\n@partial(traceback_util.api_boundary, repro_api_name=\"jax.shard_map\")\ndef _shard_map[F: Callable](\n    f: F, *, mesh: Mesh | AbstractMesh | None,\n    in_specs: Specs, out_specs: Specs, axis_names: Set[AxisName],\n    check_vma: bool, _smap: bool = False) -> F:\n  if not callable(f):\n    raise TypeError(\"shard_map requires a callable for its first argument, \"\n                    f\"but got {f} of type {type(f)}.\")\n\n  @util.wraps(f)\n  @traceback_util.api_boundary\n  def wrapped(*args):\n    nonlocal mesh, axis_names\n    mesh, axis_names = _shmap_checks(\n        mesh, axis_names, in_specs, out_specs, _smap)\n    dbg = api_util.debug_info(\"shard_map\", f, args, {})\n    args_flat = ft.flatten(args)\n    api_util.check_no_transformed_refs_args(lambda: dbg, args_flat)\n\n    try:\n      in_specs_flat = broadcast_prefix(\n          in_specs, args, is_leaf=lambda x: x is None)\n    except ValueError:\n      e, *_ = prefix_errors(in_specs, args)\n      raise e('shard_map in_specs') from None","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/shard_map.py#L236-L272","documentation":"jax.shard_map (and smap internally) requires its first argument to be a Python callable. This TypeError catches passing a non-callable such as a result array, a string, or the output of a previous computation instead of the function itself.","triggerScenarios":"Calling shard_map(arr, mesh=...) instead of shard_map(f, mesh=...), or passing a lambda result, a module object, or a string expression.","commonSituations":"Missing parentheses elsewhere producing an array, refactoring where the function variable is shadowed, or copy-paste where a decorated result is passed instead of the function.","solutions":["Ensure the first positional argument is a function/lambda: shard_map(lambda x: x * 2, mesh=...)","Check that intermediate results weren't accidentally assigned to the name you pass"],"exampleFix":"// before\nresult = shard_map(computation(x), mesh=mesh, in_specs=P('i'), out_specs=P('i'))\n\n// after\nresult = shard_map(computation, mesh=mesh, in_specs=P('i'), out_specs=P('i'))(x)","handlingStrategy":"type-guard","validationCode":"assert callable(f), f'shard_map first arg must be callable, got {type(f)}'","typeGuard":"def is_callable(f) -> bool:\n    return callable(f)","tryCatchPattern":null,"preventionTips":["Pass the function, not its result","Beware shadowed names after refactors"],"tags":["jax","shard-map","callable","type-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}