{"record":{"id":"73308c68ac84b288","repo":"tensorflow/models","slug":"resetting-the-generator-s-s","errorCode":null,"errorMessage":"Resetting the generator. %s: %s","messagePattern":"Resetting the generator\\. (.+?): (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"official/projects/bigbird/recompute_grad.py","lineNumber":162,"sourceCode":"  ]\n\n\ndef _make_seed_if_none(seed: Optional[tf.Tensor]) -> tf.Tensor:\n  \"\"\"Uses the global generator to make a seed if necessary.\"\"\"\n  if seed is not None:\n    return seed\n  generator = tf.random.experimental.get_global_generator()\n  # The two seeds for stateless random ops don't have individual semantics and\n  # are scrambled together, so providing one seed is fine. This makes it easier\n  # for users to provide a local seed without worrying about integer overflow.\n  # See `make_seeds` in\n  # https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/ops/stateful_random_ops.py.\n  try:\n    return generator.uniform_full_int([], tf.int32, name='recompute_grad_seed')\n  except (RuntimeError, TypeError, ValueError, tf.errors.NotFoundError) as e:\n    # For a number of reasons, the above operation can fail like using multiple\n    # graphs or toggling between eager and graph modes. Reset the generator.\n    logging.warn('Resetting the generator. %s: %s', type(e), e)\n    tf.random.experimental.set_global_generator(None)\n    generator = tf.random.experimental.get_global_generator()\n    return generator.uniform_full_int([], tf.int32, name='recompute_grad_seed')\n\n\ndef recompute_grad(f, seed=None):\n  \"\"\"An eager-compatible version of recompute_grad.\n\n  For f(*args, **kwargs), this supports gradients with respect to args, or to\n  gradients with respect to any variables residing in the kwarg 'variables'.\n  Note that for keras layer and model objects, this is handled automatically.\n\n  Warning: If `f` was originally a tf.keras Model or Layer object, `g` will not\n  be able to access the member variables of that object, because `g` returns\n  through the wrapper function `inner`.  When recomputing gradients through\n  objects that inherit from keras, we suggest keeping a reference to the\n  underlying object around for the purpose of accessing these variables.\n","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/bigbird/recompute_grad.py#L144-L180","documentation":"Error \"Resetting the generator. %s: %s\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/bigbird/recompute_grad.py:162 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Re-create the checkpoint reader/generator after this reset; the previous generator state is discarded.","Handle the logged exception (see the logged error) that triggered the reset."],"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"}