tensorflow/models · error · ValueError
`dataset_or_fn` should be either callable or an instance of
Error message
`dataset_or_fn` should be either callable or an instance of `tf.data.Dataset`.
What it means
Error "`dataset_or_fn` should be either callable or an instance of `tf.data.Dataset`." thrown in tensorflow/models.
Source
Thrown at orbit/utils/common.py:74
*args: Any positional arguments to pass through to `dataset_or_fn`.
**kwargs: Any keyword arguments to pass through to `dataset_or_fn`, except
that the `input_options` keyword is used to specify a
`tf.distribute.InputOptions` for making the distributed dataset.
Returns:
A distributed Dataset.
"""
if strategy is None:
strategy = tf.distribute.get_strategy()
input_options = kwargs.pop("input_options", None)
if isinstance(dataset_or_fn, tf.data.Dataset):
return strategy.experimental_distribute_dataset(dataset_or_fn,
input_options)
if not callable(dataset_or_fn):
raise ValueError("`dataset_or_fn` should be either callable or an instance "
"of `tf.data.Dataset`.")
def dataset_fn(input_context):
"""Wraps `dataset_or_fn` for strategy.distribute_datasets_from_function."""
# If `dataset_or_fn` is a function and has an argument named
# `input_context`, pass through the given `input_context`. Otherwise
# `input_context` will be ignored.
argspec = inspect.getfullargspec(dataset_or_fn)
arg_names = argspec.args
if "input_context" in arg_names:
kwargs["input_context"] = input_context
return dataset_or_fn(*args, **kwargs)
return strategy.distribute_datasets_from_function(dataset_fn, input_options)
View on GitHub (pinned to e006f5f0d5)
Solutions
- Pass a tf.data.Dataset instance or a callable returning one.
- Wrap dataset creation in a function if you need lazy construction.
When it happens
Trigger: Thrown at orbit/utils/common.py:74 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/ad0d4e6aa639e3a4.
Report an issue: GitHub.