{"record":{"id":"a0f67b975c6cc1e1","repo":"tensorflow/models","slug":"steps-per-loop-should-be-positive-integer","errorCode":null,"errorMessage":"steps_per_loop should be positive integer.","messagePattern":"steps_per_loop should be positive integer\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/bert/model_training_utils.py","lineNumber":83,"sourceCode":"  return iterator\n\n\ndef _float_metric_value(metric):\n  \"\"\"Gets the value of a float-value keras metric.\"\"\"\n  return metric.result().numpy().astype(float)\n\n\ndef clip_by_global_norm_callback(grads_and_vars):\n  \"\"\"Performs gradient clipping.\"\"\"\n  grads, variables = zip(*grads_and_vars)\n  (clipped_grads, _) = tf.clip_by_global_norm(grads, clip_norm=1.0)\n  return zip(clipped_grads, variables)\n\n\ndef steps_to_run(current_step, steps_per_epoch, steps_per_loop):\n  \"\"\"Calculates steps to run on device.\"\"\"\n  if steps_per_loop <= 0:\n    raise ValueError('steps_per_loop should be positive integer.')\n  if steps_per_loop == 1:\n    return steps_per_loop\n  remainder_in_epoch = current_step % steps_per_epoch\n  if remainder_in_epoch != 0:\n    return min(steps_per_epoch - remainder_in_epoch, steps_per_loop)\n  else:\n    return steps_per_loop\n\n\ndef write_txt_summary(training_summary, summary_dir):\n  \"\"\"Writes a summary text file to record stats.\"\"\"\n  if not tf.io.gfile.exists(summary_dir):\n    tf.io.gfile.mkdir(summary_dir)\n  summary_path = os.path.join(summary_dir, _SUMMARY_TXT)\n  with tf.io.gfile.GFile(summary_path, 'wb') as f:\n    logging.info('Training Summary: \\n%s', str(training_summary))\n    f.write(json.dumps(training_summary, indent=4))\n","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/bert/model_training_utils.py#L65-L101","documentation":"Error \"steps_per_loop should be positive integer.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/legacy/bert/model_training_utils.py:83 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"}