{"record":{"id":"5707e3060100aecc","repo":"keras-team/keras","slug":"the-tfsmlayer-is-only-currently-supported-with-the","errorCode":null,"errorMessage":"The TFSMLayer is only currently supported with the TensorFlow backend.","messagePattern":"The TFSMLayer is only currently supported with the TensorFlow backend\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"keras/src/export/tfsm_layer.py","lineNumber":59,"sourceCode":"    custom signature.\n    * If you need training-time behavior to differ from inference-time behavior\n    (i.e. if you need the reloaded object to support a `training=True` argument\n    in `__call__()`), make sure that the training-time call function is\n    saved as a standalone endpoint in the artifact, and provide its name\n    to the `TFSMLayer` via the `call_training_endpoint` argument.\n    \"\"\"\n\n    def __init__(\n        self,\n        filepath,\n        call_endpoint=\"serve\",\n        call_training_endpoint=None,\n        trainable=True,\n        name=None,\n        dtype=None,\n    ):\n        if backend.backend() != \"tensorflow\":\n            raise NotImplementedError(\n                \"The TFSMLayer is only currently supported with the \"\n                \"TensorFlow backend.\"\n            )\n\n        # Initialize an empty layer, then add_weight() etc. as needed.\n        super().__init__(trainable=trainable, name=name, dtype=dtype)\n\n        self._reloaded_obj = tf.saved_model.load(filepath)\n\n        self.filepath = filepath\n        self.call_endpoint = call_endpoint\n        self.call_training_endpoint = call_training_endpoint\n\n        # Resolve the call function.\n        if hasattr(self._reloaded_obj, call_endpoint):\n            # Case 1: it's set as an attribute.\n            self.call_endpoint_fn = getattr(self._reloaded_obj, call_endpoint)\n        elif call_endpoint in self._reloaded_obj.signatures:","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/export/tfsm_layer.py#L41-L77","documentation":"TFSMLayer reloads a TensorFlow SavedModel, which requires the TensorFlow runtime, so keras.src.export.tfsm_layer.__init__ raises NotImplementedError when keras.backend() is anything other than 'tensorflow'. Keras 3 is multi-backend, and the reloader only works when the active backend is TensorFlow. The check happens before any loading, so it fires immediately at construction.","triggerScenarios":"Constructing keras.layers.TFSMLayer('path/to/saved_model', ...) while KERAS_BACKEND is 'jax', 'torch', or 'numpy'; common when a notebook set the backend env var earlier or the script imports a jax-based library first.","commonSituations":"Teams migrating to Keras 3 with KERAS_BACKEND=jax or torch in CI; loading a TF-Hub or legacy TF2 SavedModel in a JAX training pipeline; default backend resolution picking a non-TF backend installed alongside TF.","solutions":["Set the backend before any keras import: os.environ['KERAS_BACKEND']='tensorflow' at the top of the entry script, then restart/reimport.","Convert the SavedModel to a backend-neutral format instead: reload under TF once, save as .keras (model.save), then load in your jax or torch pipeline.","Verify with keras.config.backend() right before constructing TFSMLayer to catch backend drift early."],"exampleFix":"# before (KERAS_BACKEND=jax was set)\nlayer = keras.layers.TFSMLayer('saved_model/')  # -> NotImplementedError\n\n# after\nimport os\nos.environ['KERAS_BACKEND'] = 'tensorflow'\nimport keras\nlayer = keras.layers.TFSMLayer('saved_model/')","handlingStrategy":"validation","validationCode":"import keras\nassert keras.config.backend() == 'tensorflow', 'TFSMLayer requires the TF backend'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set os.environ['KERAS_BACKEND']='tensorflow' in the entrypoint before any keras import.","Fail fast with a backend assertion before TFSMLayer construction.","Prefer backend-neutral .keras artifacts for jax or torch pipelines."],"tags":["keras","tfsmlayer","backend","tensorflow","not-implemented"],"backgroundTag":"unsupported-backend","analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}