{"record":{"id":"5adaf8037d95767b","repo":"deezer/spleeter","slug":"unknown-mode-mode","errorCode":null,"errorMessage":"Unknown mode {mode}","messagePattern":"Unknown mode (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"spleeter/model/__init__.py","lineNumber":585,"sourceCode":"            loss=loss, global_step=tf.compat.v1.train.get_global_step()\n        )\n        return tf.estimator.EstimatorSpec(\n            mode=tf.estimator.ModeKeys.TRAIN,\n            loss=loss,\n            train_op=train_operation,\n            eval_metric_ops=metrics,\n        )\n\n\ndef model_fn(features, labels, mode, params):\n    builder = EstimatorSpecBuilder(features, params)\n    if mode == tf.estimator.ModeKeys.PREDICT:\n        return builder.build_predict_model()\n    elif mode == tf.estimator.ModeKeys.EVAL:\n        return builder.build_evaluation_model(labels)\n    elif mode == tf.estimator.ModeKeys.TRAIN:\n        return builder.build_train_model(labels)\n    raise ValueError(f\"Unknown mode {mode}\")\n","sourceCodeStart":567,"sourceCodeEnd":586,"githubUrl":"https://github.com/deezer/spleeter/blob/c8854001ac8acad34a9bc2bd15f28475541828b1/spleeter/model/__init__.py#L567-L586","documentation":"model_fn is the tf.estimator model function dispatcher: it routes PREDICT/EVAL/TRAIN modes to the corresponding builder and raises ValueError for any mode outside tf.estimator.ModeKeys. In practice this fires when an unsupported estimator mode is passed by the training/evaluation driver.","triggerScenarios":"Calling model_fn (directly or via tf.estimator.Estimator with a custom mode_fn wrapper) with a mode not in {PREDICT, EVAL, TRAIN}, e.g. a custom string like 'infer' or a None mode from a misconfigured RunConfig.","commonSituations":"Custom training loops passing a hand-made mode string instead of tf.estimator.ModeKeys; TF2 migration where estimator plumbing changes; tests invoking model_fn with mock modes.","solutions":["Always pass a value from tf.estimator.ModeKeys (TRAIN, EVAL, or PREDICT)","If you need another behavior, add a branch before the raise in model_fn","Check the caller (training/eval script) for how mode is derived and fix the mapping","Verify your TensorFlow version: custom estimator modes are not supported"],"exampleFix":"// before\nestimator = tf.estimator.Estimator(model_fn=lambda features, labels, mode: model_fn(features, labels, mode, params), model_dir=...)\n# with mode string 'infer'\n// after\nmode = tf.estimator.ModeKeys.PREDICT\nestimator = tf.estimator.Estimator(model_fn=..., model_dir=...)","handlingStrategy":"validation","validationCode":"import tensorflow as tf\n\ndef assert_valid_mode(mode):\n    if mode not in (tf.estimator.ModeKeys.TRAIN, tf.estimator.ModeKeys.EVAL, tf.estimator.ModeKeys.PREDICT):\n        raise ValueError(f\"mode must be a tf.estimator.ModeKeys member, got {mode!r}\")\n    return mode","typeGuard":"import tensorflow as tf\n\ndef is_estimator_mode(mode) -> bool:\n    try:\n        return mode in (tf.estimator.ModeKeys.TRAIN, tf.estimator.ModeKeys.EVAL, tf.estimator.ModeKeys.PREDICT)\n    except Exception:\n        return False","tryCatchPattern":"try:\n    estimator.train(input_fn)  # or eval/predict\nexcept ValueError as e:\n    if 'Unknown mode' in str(e):\n        raise RuntimeError(f\"model_fn received a non-estimator mode; use tf.estimator.ModeKeys: {e}\") from e\n    raise","preventionTips":["Never pass raw strings like 'train'/'infer' — use tf.estimator.ModeKeys.*","When wrapping model_fn, propagate the mode argument unchanged","In tests, parametrize only over the three ModeKeys values","Watch for TF upgrades changing estimator signatures and mode plumbing"],"tags":["python","valueerror","tensorflow","estimator","spleeter"],"backgroundTag":"unsupported-mode","analyzedSha":"c8854001ac8acad34a9bc2bd15f28475541828b1","analyzedAt":"2026-08-28T21:38:40.142Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}