{"record":{"id":"81f445800423baec","repo":"tensorflow/models","slug":"found-unexpected-kwargs-for-grad","errorCode":null,"errorMessage":"Found unexpected kwargs for `grad`: ","messagePattern":"Found unexpected kwargs for `grad`: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"official/projects/bigbird/recompute_grad.py","lineNumber":217,"sourceCode":"      # Use the cached context in the recomputation phase.\n      with parent_context.children.popleft()._replace(\n          is_recomputing=True) as context:\n        result = f(*args, **kwargs)\n    else:\n      with RecomputeContext(\n          is_recomputing=False,\n          seed=_make_seed_if_none(seed),\n          children=collections.deque()) as context:\n        result = f(*args, **kwargs)\n        # In the forward pass, build up a tree of recomputation contexts.\n        if parent_context is not None and not parent_context.is_recomputing:\n          parent_context.children.append(context)\n\n    def grad(*dresult, **grad_kwargs):\n      \"\"\"Gradient function calculation for inner function.\"\"\"\n      variables = grad_kwargs.pop('variables', None)\n      if grad_kwargs:\n        raise ValueError('Found unexpected kwargs for `grad`: ',\n                         list(grad_kwargs.keys()))\n      inputs, seed = list(args), context.seed\n      if _in_xla_context():\n        inputs = _force_data_dependency(\n            tf.nest.flatten(dresult), inputs + [seed])\n        seed = inputs.pop()\n      with tf.GradientTape() as tape:\n        tape.watch(inputs)\n        if variables is not None:\n          tape.watch(variables)\n        with tf.control_dependencies(dresult):\n          with context._replace(is_recomputing=True, seed=seed):\n            result = f(*inputs, **kwargs)\n      kw_vars = []\n      if variables is not None:\n        kw_vars = list(variables)\n      grads = tape.gradient(\n          result, list(inputs) + kw_vars, output_gradients=dresult)","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/bigbird/recompute_grad.py#L199-L235","documentation":"Error \"Found unexpected kwargs for `grad`: \" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/bigbird/recompute_grad.py:217 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}