{"record":{"id":"86f8c48a623a6c8a","repo":"tensorflow/models","slug":"distribution-strategy-has-not-been-specified","errorCode":null,"errorMessage":"Distribution strategy has not been specified.","messagePattern":"Distribution strategy has not been specified\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/bert/run_classifier.py","lineNumber":385,"sourceCode":"             custom_metrics=None):\n  \"\"\"Run BERT training.\"\"\"\n  # Enables XLA in Session Config. Should not be set for TPU.\n  keras_utils.set_session_config(FLAGS.enable_xla)\n  performance.set_mixed_precision_policy(common_flags.dtype())\n\n  epochs = FLAGS.num_train_epochs * FLAGS.num_eval_per_epoch\n  train_data_size = (\n      input_meta_data['train_data_size'] // FLAGS.num_eval_per_epoch)\n  if FLAGS.train_data_size:\n    train_data_size = min(train_data_size, FLAGS.train_data_size)\n    logging.info('Updated train_data_size: %s', train_data_size)\n  steps_per_epoch = int(train_data_size / FLAGS.train_batch_size)\n  warmup_steps = int(epochs * train_data_size * 0.1 / FLAGS.train_batch_size)\n  eval_steps = int(\n      math.ceil(input_meta_data['eval_data_size'] / FLAGS.eval_batch_size))\n\n  if not strategy:\n    raise ValueError('Distribution strategy has not been specified.')\n\n  if not custom_callbacks:\n    custom_callbacks = []\n\n  if FLAGS.log_steps:\n    custom_callbacks.append(\n        keras_utils.TimeHistory(\n            batch_size=FLAGS.train_batch_size,\n            log_steps=FLAGS.log_steps,\n            logdir=FLAGS.model_dir))\n\n  trained_model, _ = run_bert_classifier(\n      strategy,\n      model_config,\n      input_meta_data,\n      FLAGS.model_dir,\n      epochs,\n      steps_per_epoch,","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/bert/run_classifier.py#L367-L403","documentation":"Error \"Distribution strategy has not been specified.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/legacy/bert/run_classifier.py:385 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"}