{"record":{"id":"55449b2dd063c553","repo":"tensorflow/models","slug":"strategy-model-fn-loss-fn-model-dir-s","errorCode":null,"errorMessage":"`strategy`, `model_fn`, `loss_fn`, `model_dir`, `steps_per_epoch` and `train_input_fn` are required parameters.","messagePattern":"`strategy`, `model_fn`, `loss_fn`, `model_dir`, `steps_per_epoch` and `train_input_fn` are required parameters\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/bert/model_training_utils.py","lineNumber":227,"sourceCode":"  Raises:\n      ValueError: (1) When model returned by `model_fn` does not have optimizer\n        attribute or when required parameters are set to none. (2) eval args are\n        not specified correctly. (3) metric_fn must be a callable if specified.\n        (4) sub_model_checkpoint_name is specified, but `sub_model` returned\n        by `model_fn` is None.\n  \"\"\"\n\n  if _sentinel is not None:\n    raise ValueError('only call `run_customized_training_loop()` '\n                     'with named arguments.')\n\n  required_arguments = [\n      strategy, model_fn, loss_fn, model_dir, steps_per_epoch, train_input_fn\n  ]\n\n  steps_between_evals = int(steps_per_epoch / num_eval_per_epoch)  # pyrefly: ignore[unsupported-operation]\n  if [arg for arg in required_arguments if arg is None]:\n    raise ValueError('`strategy`, `model_fn`, `loss_fn`, `model_dir`, '\n                     '`steps_per_epoch` and `train_input_fn` are required '\n                     'parameters.')\n  if not steps_per_loop:\n    if tf.config.list_logical_devices('TPU'):\n      # One can't fully utilize a TPU with steps_per_loop=1, so in this case\n      # 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()","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/bert/model_training_utils.py#L209-L245","documentation":"Guard at the top of run_customized_training_loop that verifies the six mandatory arguments of the customized training loop were actually supplied. It fires when any of strategy, model_fn, loss_fn, model_dir, steps_per_epoch or train_input_fn is None (or omitted), because the loop cannot build/ distribute/ checkpoint a model without them.","triggerScenarios":"Thrown at official/legacy/bert/model_training_utils.py:227 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass non-None values for strategy, model_fn, loss_fn, model_dir, steps_per_epoch and train_input_fn","Create a distribution strategy with tf.distribute.MirroredStrategy() (or TPUStrategy) and pass it as strategy","Define a model_fn(params) that builds and returns the model and a loss_fn(labels, outputs) callable"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}