apache/beam · error · AssertionError
Unsupported serialization type.
Error message
Unsupported serialization type.
What it means
Raised in sklearn_inference._load_model as an AssertionError when the provided file_type is neither PICKLE nor JOBLIB. It is the terminal fall-through guard after the ModelFileType branches, meaning an unsupported serialization type reached the loader.
Source
Thrown at sdks/python/apache_beam/ml/inference/sklearn_inference.py:69
class ModelFileType(enum.Enum):
"""Defines how a model file is serialized. Options are pickle or joblib."""
PICKLE = 1
JOBLIB = 2
def _load_model(model_uri, file_type):
file = FileSystems.open(model_uri, 'rb')
if file_type == ModelFileType.PICKLE:
return pickle.load(file)
elif file_type == ModelFileType.JOBLIB:
if not joblib:
raise ImportError(
'Could not import joblib in this execution environment. '
'For help with managing dependencies on Python workers.'
'see https://beam.apache.org/documentation/sdks/python-pipeline-dependencies/' # pylint: disable=line-too-long
)
return joblib.load(file)
raise AssertionError('Unsupported serialization type.')
def _default_numpy_inference_fn(
model: BaseEstimator,
batch: Sequence[numpy.ndarray],
inference_args: Optional[dict[str, Any]] = None) -> Any:
inference_args = {} if not inference_args else inference_args
# vectorize data for better performance
vectorized_batch = numpy.stack(batch, axis=0)
return model.predict(vectorized_batch, **inference_args)
class SklearnModelHandlerNumpy(ModelHandler[numpy.ndarray,
PredictionResult,
BaseEstimator]):
def __init__(
self,
model_uri: str,View on GitHub (pinned to 12126d8942)
Solutions
- Pass model_file_type as ModelFileType.PICKLE or ModelFileType.JOBLIB explicitly
- Verify the ModelFileType enum members available in your installed Beam version
- Upgrade apache-beam on workers if the serialization type was added in a newer release
Example fix
// before handler = SklearnModelHandler(model_uri=uri, model_file_type='joblib') // after handler = SklearnModelHandler(model_uri=uri, model_file_type=ModelFileType.JOBLIB)
Defensive patterns
Strategy: validation
Validate before calling
from apache_beam.ml.inference.sklearn_inference import ModelFileType
assert model_file_type in (ModelFileType.PICKLE, ModelFileType.JOBLIB), f'Unsupported type: {model_file_type}' Type guard
def is_supported_model_file_type(t) -> bool:
return t in (ModelFileType.PICKLE, ModelFileType.JOBLIB) Try / catch
try:
model = handler.load_model()
except AssertionError as e:
if 'Unsupported serialization type' in str(e):
handler.model_file_type = ModelFileType.PICKLE
model = handler.load_model()
else:
raise Prevention
- Always reference ModelFileType enum members, never raw strings
- Check enum members against your installed apache-beam version
- Validate handler construction in unit tests before pipeline launch
When it happens
Trigger: Calling SklearnModelHandler (or _load_model) with a model_file_type value outside the ModelFileType enum's PICKLE/JOBLIB members, or constructing the enum with an arbitrary value.
Common situations: Passing a raw string instead of a ModelFileType enum member; an enum version mismatch where a new member exists in a newer Beam version than the worker runs; typo-ed enum construction via ModelFileType('pickle') with wrong case.
Related errors
- Unable to deterministically encode non-frozen '%s' of type '
- Unable to deterministically encode '%s' of type '%s', please
- Unable to deterministically encode '%s' of type '%s', for th
- Invalid PaneInfoEncoding: %s
- No fallback.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/5f541a9cba445e90.
Report an issue: GitHub.