{"record":{"id":"caaec78d74683dc9","repo":"tensorflow/models","slug":"decoder-layer-should-be-built","errorCode":null,"errorMessage":"decoder_layer should be built.","messagePattern":"decoder_layer should be built\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/nhnet/models.py","lineNumber":78,"sourceCode":"  # remove <s>\n  targets = seq[:, 1:]\n  # pad\n  pad_ids = tf.ones([batch_size], tf.int32) * pad_token_id\n  targets = tf.concat([targets, tf.expand_dims(pad_ids, axis=1)], axis=1)\n  tf.assert_equal(tf.shape(targets), (batch_size, seq_len))\n  return targets\n\n\nclass Bert2Bert(tf_keras.Model):\n  \"\"\"Bert2Bert encoder decoder model for training.\"\"\"\n\n  def __init__(self, params, bert_layer, decoder_layer, name=None):\n    super(Bert2Bert, self).__init__(name=name)\n    self.params = params\n    if not bert_layer.built:\n      raise ValueError(\"bert_layer should be built.\")\n    if not decoder_layer.built:\n      raise ValueError(\"decoder_layer should be built.\")\n    self.bert_layer = bert_layer\n    self.decoder_layer = decoder_layer\n\n  def get_config(self):\n    return {\"params\": self.params.as_dict()}\n\n  def get_decode_logits(self,\n                        decoder_inputs,\n                        ids,\n                        decoder_self_attention_bias,\n                        step,\n                        cache=None):\n    if cache:\n      if self.params.get(\"padded_decode\", False):\n        bias_shape = decoder_self_attention_bias.shape.as_list()\n        self_attention_bias = tf.slice(\n            decoder_self_attention_bias, [0, 0, step, 0],\n            [bias_shape[0], bias_shape[1], 1, bias_shape[3]])","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/nhnet/models.py#L60-L96","documentation":"Bert2Bert requires the decoder layer to be built (weights created) before model assembly, since it calls the decoder to establish the encoder-decoder wiring; decoder_layer.built is False at construction time.","triggerScenarios":"Thrown at official/projects/nhnet/models.py:78 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Build the decoder_layer before passing it (call it on dummy inputs or build())","Construct the decoder via the network factory so it is already built"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}