{"record":{"id":"368b742048036455","repo":"tensorflow/models","slug":"initial-cache-element-for-key-s-has-dtype-s-th-368b74","errorCode":null,"errorMessage":"initial_cache element for key '%s' has dtype %s that does not match sampling_module's dtype of %s. Value: %s","messagePattern":"initial_cache element for key '(.+?)' has dtype (.+?) that does not match sampling_module's dtype of (.+?)\\. Value: (.+?)","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/ops/sampling_module.py","lineNumber":264,"sourceCode":"      topk_seq = tf.tensor_scatter_nd_update(\n          topk_seq, [[i + 1]], tf.expand_dims(tf.squeeze(topk_ids, -1), 0))\n      topk_seq = tf.transpose(topk_seq, perm=[1, 0])\n    else:\n      topk_seq = tf.concat([alive_seq, topk_ids], axis=-1)\n    return topk_seq, topk_log_probs, topk_ids, new_cache\n\n  def _create_initial_state(\n      self,\n      initial_ids: tf.Tensor,\n      initial_cache: Dict[str, tf.Tensor],\n      batch_size: int,\n      initial_log_probs: Optional[tf.Tensor] = None\n  ) -> decoding_module.InitialState:\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 sampling_module's dtype of %s. Value: %s\" %\n              (key, value.dtype.name, self.dtype.name, inner_value))\n\n    # Current loop index (starts at 0)\n    cur_index = tf.constant(0)\n\n    # Alive sequence with shape [batch_size, 1]\n    alive_seq = initial_ids\n    alive_seq = tf.expand_dims(alive_seq, axis=-1)\n    if self.padded_decode:\n      alive_seq = tf.tile(alive_seq, [1, self.max_decode_length + 1])\n\n    # Initial log probabilities with shape [batch_size, 1].\n    if initial_log_probs is None:\n      initial_log_probs = tf.constant([[0.]], dtype=self.dtype)\n      alive_log_probs = tf.tile(initial_log_probs, [batch_size, 1])\n    else:","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/ops/sampling_module.py#L246-L282","documentation":"Error \"initial_cache element for key '%s' has dtype %s that does not match sampling_module's dtype of %s. Value: %s\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/ops/sampling_module.py:264 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"}