{"record":{"id":"ad0d4e6aa639e3a4","repo":"tensorflow/models","slug":"dataset-or-fn-should-be-either-callable-or-an-in","errorCode":null,"errorMessage":"`dataset_or_fn` should be either callable or an instance of `tf.data.Dataset`.","messagePattern":"`dataset_or_fn` should be either callable or an instance of `tf\\.data\\.Dataset`\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"orbit/utils/common.py","lineNumber":74,"sourceCode":"    *args: Any positional arguments to pass through to `dataset_or_fn`.\n    **kwargs: Any keyword arguments to pass through to `dataset_or_fn`, except\n      that the `input_options` keyword is used to specify a\n      `tf.distribute.InputOptions` for making the distributed dataset.\n\n  Returns:\n    A distributed Dataset.\n  \"\"\"\n  if strategy is None:\n    strategy = tf.distribute.get_strategy()\n\n  input_options = kwargs.pop(\"input_options\", None)\n\n  if isinstance(dataset_or_fn, tf.data.Dataset):\n    return strategy.experimental_distribute_dataset(dataset_or_fn,\n                                                    input_options)\n\n  if not callable(dataset_or_fn):\n    raise ValueError(\"`dataset_or_fn` should be either callable or an instance \"\n                     \"of `tf.data.Dataset`.\")\n\n  def dataset_fn(input_context):\n    \"\"\"Wraps `dataset_or_fn` for strategy.distribute_datasets_from_function.\"\"\"\n\n    # If `dataset_or_fn` is a function and has an argument named\n    # `input_context`, pass through the given `input_context`. Otherwise\n    # `input_context` will be ignored.\n    argspec = inspect.getfullargspec(dataset_or_fn)\n    arg_names = argspec.args\n\n    if \"input_context\" in arg_names:\n      kwargs[\"input_context\"] = input_context\n    return dataset_or_fn(*args, **kwargs)\n\n  return strategy.distribute_datasets_from_function(dataset_fn, input_options)\n\n","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/orbit/utils/common.py#L56-L92","documentation":"Error \"`dataset_or_fn` should be either callable or an instance of `tf.data.Dataset`.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at orbit/utils/common.py:74 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a tf.data.Dataset instance or a callable returning one.","Wrap dataset creation in a function if you need lazy construction."],"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"}