tensorflow/models · error · ValueError
Distribution strategy has not been specified.
Error message
Distribution strategy has not been specified.
What it means
Guard in run_bert: no distribution strategy object was provided (strategy is None/falsy) before setting up distributed training. The strategy orchestrates replication across devices, so training cannot proceed; usually the strategy_type flag was not converted into a strategy via distribution_utils.get_distribution_strategy.
Solutions
- Build a strategy first: strategy = distribution_utils.get_distribution_strategy(FLAGS.strategy_type) and pass it to run_bert
- Check that the strategy_type/ tpu flag is set so get_distribution_strategy does not return None
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at official/legacy/bert/run_classifier.py:385 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of tensorflow/models@e006f5f0d5 (2026-08-24).
Data as JSON: /api/errors/86f8c48a623a6c8a.
Report an issue: GitHub.
Appendix: source
Thrown at official/legacy/bert/run_classifier.py:385
custom_metrics=None):
"""Run BERT training."""
# Enables XLA in Session Config. Should not be set for TPU.
keras_utils.set_session_config(FLAGS.enable_xla)
performance.set_mixed_precision_policy(common_flags.dtype())
epochs = FLAGS.num_train_epochs * FLAGS.num_eval_per_epoch
train_data_size = (
input_meta_data['train_data_size'] // FLAGS.num_eval_per_epoch)
if FLAGS.train_data_size:
train_data_size = min(train_data_size, FLAGS.train_data_size)
logging.info('Updated train_data_size: %s', train_data_size)
steps_per_epoch = int(train_data_size / FLAGS.train_batch_size)
warmup_steps = int(epochs * train_data_size * 0.1 / FLAGS.train_batch_size)
eval_steps = int(
math.ceil(input_meta_data['eval_data_size'] / FLAGS.eval_batch_size))
if not strategy:
raise ValueError('Distribution strategy has not been specified.')
if not custom_callbacks:
custom_callbacks = []
if FLAGS.log_steps:
custom_callbacks.append(
keras_utils.TimeHistory(
batch_size=FLAGS.train_batch_size,
log_steps=FLAGS.log_steps,
logdir=FLAGS.model_dir))
trained_model, _ = run_bert_classifier(
strategy,
model_config,
input_meta_data,
FLAGS.model_dir,
epochs,
steps_per_epoch,View on GitHub (pinned to e006f5f0d5)