apache/beam · error · ValueError
Callable create_model_fn must be passedwith…
Error message
Callable create_model_fn must be passedwith ModelType.SAVED_WEIGHTS
What it means
Raised in TFTensorFlowModelHandler (KeyedModelHandler) load_model when model_type is ModelType.SAVED_WEIGHTS but no create_model_fn callable was supplied. Loading raw saved weights requires a callable that instantiates the model architecture into which the weights are loaded.
Solutions
- Pass a create_model_fn that returns an instantiated tf.Module/keras model with the expected architecture
- Use model_type=ModelType.SAVED_MODEL instead if you have a full SavedModel and don't need weight-only loading
Example fix
// before
handler = TFTensorFlowModelHandlerMRU(
model_uri='gs://bucket/weights.ckpt', model_type=ModelType.SAVED_WEIGHTS)
// after
handler = TFTensorFlowModelHandlerMRU(
model_uri='gs://bucket/weights.ckpt',
model_type=ModelType.SAVED_WEIGHTS,
create_model_fn=lambda: MyNet()) Defensive patterns
Strategy: validation
Validate before calling
def validate_tf_handler_args(model_type, create_model_fn):
if model_type == ModelType.SAVED_WEIGHTS and not callable(create_model_fn):
raise ValueError('create_model_fn must be a callable when model_type is SAVED_WEIGHTS') Type guard
import collections.abc create_model_fn_is_valid = lambda fn: isinstance(fn, collections.abc.Callable)
Try / catch
try:
handler.load_model()
except ValueError as e:
if 'create_model_fn' in str(e):
handler._create_model_fn = build_model
handler.load_model()
else:
raise Prevention
- Pair ModelType.SAVED_WEIGHTS with a create_model_fn at construction time
- Add a construction-time unit test per handler/model_type combination
- Default to SAVED_MODEL unless weight-only loading is explicitly required
When it happens
Trigger: Constructing the TF handler with model_type=ModelType.SAVED_WEIGHTS and leaving create_model_fn as None, then calling load_model during pipeline setup.
Common situations: Switching a handler from SAVED_MODEL to SAVED_WEIGHTS without adding create_model_fn; assuming weights-only loading can infer the architecture; config-driven handler construction that omits the callable for the weights type.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Please specify either torch_script_model_path or…
- Unable to load the TensorFlow model
- Cannot make make an unkeyed model handler with pre or…
- Cannot override RemoteModelHandler.load_model, implement…
- Cannot override RemoteModelHandler.run_inference, implement…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/f324901bf4c51150.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/python/apache_beam/ml/inference/tensorflow_inference.py:182
max_batch_weight=max_batch_weight,
element_size_fn=element_size_fn,
batch_length_fn=batch_length_fn,
batch_bucket_boundaries=batch_bucket_boundaries,
large_model=large_model,
model_copies=model_copies,
**kwargs)
self._model_uri = model_uri
self._model_type = model_type
self._inference_fn = inference_fn
self._create_model_fn = create_model_fn
self._load_model_args = {} if not load_model_args else load_model_args
self._custom_weights = custom_weights
def load_model(self) -> tf.Module:
"""Loads and initializes a Tensorflow model for processing."""
if self._model_type == ModelType.SAVED_WEIGHTS:
if not self._create_model_fn:
raise ValueError(
"Callable create_model_fn must be passed"
"with ModelType.SAVED_WEIGHTS")
return _load_model_from_weights(self._create_model_fn, self._model_uri)
return _load_model(
self._model_uri, self._custom_weights, self._load_model_args)
def update_model_path(self, model_path: Optional[str] = None):
self._model_uri = model_path if model_path else self._model_uri
def run_inference(
self,
batch: Sequence[numpy.ndarray],
model: tf.Module,
inference_args: Optional[dict[str, Any]] = None
) -> Iterable[PredictionResult]:
"""
Runs inferences on a batch of numpy array and returns an Iterable ofView on GitHub (pinned to 12126d8942)