{"record":{"id":"0db62f3d90e7ab85","repo":"tensorflow/models","slug":"producer-batch-size-differs-from-params-batch","errorCode":null,"errorMessage":"producer batch size ({}) differs from params batch size ({})","messagePattern":"producer batch size \\((.+?)\\) differs from params batch size \\((.+?)\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/recommendation/data_pipeline.py","lineNumber":349,"sourceCode":"          self.data_generator, epochs_between_evals=epochs_between_evals)\n      dataset = tf.data.Dataset.from_generator(\n          generator=data_generator, output_types=types, output_shapes=shapes)\n\n    return dataset.prefetch(16)\n\n  def make_input_fn(self, batch_size):\n    \"\"\"Create an input_fn which checks for batch size consistency.\"\"\"\n\n    def input_fn(params):\n      \"\"\"Returns batches for training.\"\"\"\n\n      # Estimator passes batch_size during training and eval_batch_size during\n      # eval.\n      param_batch_size = (\n          params[\"batch_size\"] if self._is_training else\n          params.get(\"eval_batch_size\") or params[\"batch_size\"])\n      if batch_size != param_batch_size:\n        raise ValueError(\"producer batch size ({}) differs from params batch \"\n                         \"size ({})\".format(batch_size, param_batch_size))\n\n      epochs_between_evals = (\n          params.get(\"epochs_between_evals\", 1) if self._is_training else 1)\n      return self.get_dataset(\n          batch_size=batch_size, epochs_between_evals=epochs_between_evals)\n\n    return input_fn\n\n\nclass BaseDataConstructor(threading.Thread):\n  \"\"\"Data constructor base class.\n\n  This class manages the control flow for constructing data. It is not meant\n  to be used directly, but instead subclasses should implement the following\n  two methods:\n\n    self.construct_lookup_variables","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/recommendation/data_pipeline.py#L331-L367","documentation":"Consistency check inside the input_fn closure created by make_input_fn: the batch size recorded when the data was produced differs from the batch size the Estimator passed in params, which would silently mis-shape the batches.","triggerScenarios":"Thrown at official/recommendation/data_pipeline.py:349 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Align the producer's batch_size with params['batch_size'] (train) or eval_batch_size (eval) when constructing the data pipeline","Rebuild/re-serialize the dataset files with the same batch size used at run time","Verify you are not passing a per-replica vs global batch size mismatch under distribution strategy"],"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"}