{"record":{"id":"f4a3296321bd4f4c","repo":"tensorflow/models","slug":"initial-cache-element-for-key-s-has-dtype-s-th","errorCode":null,"errorMessage":"initial_cache element for key '%s' has dtype %s that does not match SequenceBeamSearch's dtype of %s. Value: %s","messagePattern":"initial_cache element for key '(.+?)' has dtype (.+?) that does not match SequenceBeamSearch's dtype of (.+?)\\. Value: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/ops/beam_search.py","lineNumber":451,"sourceCode":"    finished_cond = tf.reduce_any(finished_flags, 1, name=\"finished_cond\")\n    seq_cond = _expand_to_same_rank(finished_cond, finished_seq)\n    score_cond = _expand_to_same_rank(finished_cond, finished_scores)\n\n    # Account for corner case where there are no finished sequences for a\n    # particular batch item. In that case, return alive sequences for that batch\n    # item.\n    finished_seq = tf.where(seq_cond, finished_seq, alive_seq)\n    finished_scores = tf.where(score_cond, finished_scores, alive_log_probs)\n    return finished_seq, finished_scores\n\n  def _create_initial_state(\n      self, initial_ids, initial_cache, batch_size, constraint_mask=None\n  ):\n    \"\"\"Return initial state dictionary and its shape invariants.\"\"\"\n    for key, value in initial_cache.items():\n      for inner_value in tf.nest.flatten(value):\n        if inner_value.dtype != self.dtype:\n          raise TypeError(\n              \"initial_cache element for key '%s' has dtype %s that does not \"\n              \"match SequenceBeamSearch's dtype of %s. Value: %s\" %\n              (key, inner_value.dtype.name, self.dtype.name, inner_value))\n\n    # Current loop index (starts at 0)\n    cur_index = tf.constant(0)\n\n    # Create alive sequence with shape [batch_size, beam_size, 1]\n    alive_seq = expand_to_beam_size(initial_ids, self.beam_size)\n    alive_seq = tf.expand_dims(alive_seq, axis=2)\n    if self.padded_decode:\n      alive_seq = tf.tile(alive_seq, [1, 1, self.max_decode_length + 1])\n\n    # Create tensor for storing initial log probabilities.\n    # Assume initial_ids are prob 1.0\n    initial_log_probs = tf.constant([[0.] + [-float(\"inf\")] *\n                                     (self.beam_size - 1)],\n                                    dtype=self.dtype)","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/ops/beam_search.py#L433-L469","documentation":"Error \"initial_cache element for key '%s' has dtype %s that does not match SequenceBeamSearch's dtype of %s. Value: %s\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/ops/beam_search.py:451 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"}