{"record":{"id":"948f091a46ea688d","repo":"tensorflow/models","slug":"mode-is-not-valid","errorCode":null,"errorMessage":"mode {} is not valid.","messagePattern":"mode (.+?) is not valid\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/legacy/transformer/embedding_layer.py","lineNumber":72,"sourceCode":"    \"\"\"Get token embeddings of inputs.\n\n    Args:\n      inputs: An int64 tensor with shape [batch_size, length]\n      mode: string, a valid value is one of \"embedding\" and \"linear\".\n\n    Returns:\n      outputs: (1) If mode == \"embedding\", output embedding tensor, float32 with\n        shape [batch_size, length, embedding_size]; (2) mode == \"linear\", output\n        linear tensor, float32 with shape [batch_size, length, vocab_size].\n    Raises:\n      ValueError: if mode is not valid.\n    \"\"\"\n    if mode == \"embedding\":\n      return self._embedding(inputs)\n    elif mode == \"linear\":\n      return self._linear(inputs)\n    else:\n      raise ValueError(\"mode {} is not valid.\".format(mode))\n\n  def _embedding(self, inputs):\n    \"\"\"Applies embedding based on inputs tensor.\"\"\"\n    with tf.name_scope(\"embedding\"):\n      # Create binary mask of size [batch_size, length]\n      embeddings = tf.gather(self.shared_weights, inputs)\n      # mask = tf.cast(tf.not_equal(inputs, 0), embeddings.dtype)\n      # embeddings *= tf.expand_dims(mask, -1)\n      # Scale embedding by the sqrt of the hidden size\n      embeddings *= self.hidden_size**0.5\n\n      return embeddings\n\n  def _linear(self, inputs):\n    \"\"\"Computes logits by running inputs through a linear layer.\n\n    Args:\n      inputs: A float32 tensor with shape [batch_size, length, hidden_size]","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/legacy/transformer/embedding_layer.py#L54-L90","documentation":"Error \"mode {} is not valid.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/legacy/transformer/embedding_layer.py:72 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}