{"record":{"id":"df30dae2372d213b","repo":"tensorflow/models","slug":"tpustrategy-should-not-run-eagerly-as-it-heavily-r","errorCode":null,"errorMessage":"TPUStrategy should not run eagerly as it heavily relies on graph optimization for the distributed system.","messagePattern":"TPUStrategy should not run eagerly as it heavily relies on graph optimization for the distributed system\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/bert/model_training_utils.py","lineNumber":251,"sourceCode":"      # default users to a more useful value.\n      steps_per_loop = min(1000, steps_between_evals)\n    else:\n      steps_per_loop = 1\n    logging.info('steps_per_loop not specified. Using steps_per_loop=%d',\n                 steps_per_loop)\n  if steps_per_loop > steps_between_evals:\n    logging.warning(\n        'steps_per_loop: %d is specified to be greater than '\n        ' steps_between_evals: %d, we will use steps_between_evals as'\n        ' steps_per_loop.', steps_per_loop, steps_between_evals)\n    steps_per_loop = steps_between_evals\n  assert tf.executing_eagerly()\n\n  if run_eagerly:\n    if isinstance(\n        strategy,\n        (tf.distribute.TPUStrategy, tf.distribute.experimental.TPUStrategy)):\n      raise ValueError(\n          'TPUStrategy should not run eagerly as it heavily relies on graph'\n          ' optimization for the distributed system.')\n\n  if eval_input_fn and eval_steps is None:\n    raise ValueError(\n        '`eval_step` is required when `eval_input_fn ` is not none.')\n  if metric_fn and not callable(metric_fn):\n    raise ValueError(\n        'if `metric_fn` is specified, metric_fn must be a callable.')\n\n  total_training_steps = steps_per_epoch * epochs  # pyrefly: ignore[unsupported-operation]\n  train_iterator = _get_input_iterator(train_input_fn, strategy)\n  eval_loss_metric = tf_keras.metrics.Mean('training_loss', dtype=tf.float32)\n\n  with distribute_utils.get_strategy_scope(strategy):\n    # To correctly place the model weights on accelerators,\n    # model and optimizer should be created in scope.\n    model, sub_model = model_fn()  # pyrefly: ignore[not-callable]","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/bert/model_training_utils.py#L233-L269","documentation":"Error \"TPUStrategy should not run eagerly as it heavily relies on graph optimization for the distributed system.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/legacy/bert/model_training_utils.py:251 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"}