{"record":{"id":"dade6ac36abe06b0","repo":"jax-ml/jax","slug":"keyword-arguments-could-not-be-resolved-to-positio","errorCode":null,"errorMessage":"keyword arguments could not be resolved to positions","messagePattern":"keyword arguments could not be resolved to positions","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"jax/_src/custom_partitioning.py","lineNumber":55,"sourceCode":"from jax._src import flattree as ft\nfrom jax._src import mesh as mesh_lib\nfrom jax._src import sharding_impls\nfrom jax._src import tree_util\nfrom jax._src import xla_bridge as xb\nfrom jax._src.custom_partitioning_sharding_rule import sdy_sharding_rule_to_mlir, SdyShardingRule, str_to_sdy_sharding_rule\nfrom jax._src.interpreters import mlir\nfrom jax._src.interpreters import partial_eval as pe\nfrom jax._src.lib import xla_client as xc\nfrom jax._src.lib.mlir import ir\nfrom jax._src.lib.mlir.dialects import hlo\nfrom jax._src.sharding import Sharding\n\n\ndef _resolve_kwargs(fun, args, kwargs):\n  ba = inspect.signature(fun).bind(*args, **kwargs)\n  ba.apply_defaults()\n  if ba.kwargs:\n    raise TypeError(\"keyword arguments could not be resolved to positions\")\n  else:\n    return ba.args\n\n\nclass _ShardingCallbackInfo:\n\n  def __init__(self, propagate_user_sharding, partition, to_mesh_pspec_sharding,\n      in_tree, out_tree, infer_sharding_from_operands, module_context, mesh,\n      static_args):\n    self.propagate_user_sharding = propagate_user_sharding\n    self.partition = partition\n    self.to_mesh_pspec_sharding = to_mesh_pspec_sharding\n    self.in_tree = in_tree\n    self.out_tree = out_tree\n    self.infer_sharding_from_operands = infer_sharding_from_operands\n    self.module_context = module_context\n    self.mesh = mesh\n    self.static_args = static_args","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/jax-ml/jax/blob/1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb/jax/_src/custom_partitioning.py#L37-L73","documentation":"jax.custom_partitioning (and custom API sharding callbacks) resolves keyword arguments to positional ones via inspect.signature. If after binding and applying defaults there remain unresolvable keyword arguments (e.g. **kwargs in the wrapped function's signature or unrecognized kwargs), TypeError is raised.","triggerScenarios":"Passing a keyword argument that inspect.signature(fun).bind leaves in ba.kwargs — typically because fun accepts **kwargs, so the keyword cannot be mapped to a named parameter position.","commonSituations":"Wrapping a custom_partitioning-decorated function that has a **kwargs catch-all, or passing an unexpected kwarg name (typo) to a custom-partitioned function.","solutions":["Remove **kwargs from the wrapped function's signature or stop passing the extra keyword","Pass all arguments positionally","Fix the keyword name typo so it matches a declared parameter"],"exampleFix":"# before\ndef f(x, **kwargs): ...\nnamed_sharding_constraint(f)  # f called with kwargs later\n\n# after\ndef f(x, scale): ...\n# call f(x, scale=2.0) or f(x, 2.0) positionally","handlingStrategy":"validation","validationCode":"import inspect\nba = inspect.signature(fun).bind(*args, **kwargs)\nba.apply_defaults()\nassert not ba.kwargs, f'unresolvable kwargs: {ba.kwargs}'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid **kwargs in functions passed to custom_partitioning","Call custom-partitioned functions with positional args"],"tags":["jax","custom-partitioning","kwargs","typeerror"],"backgroundTag":"unresolvable-keyword-argument","analyzedSha":"1e1c6a8fc06dfcd1247076ec5cae4640cea5d7bb","analyzedAt":"2026-08-27T09:53:25.647Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}