{"record":{"id":"8262f79a7d22e2cb","repo":"tensorflow/models","slug":"when-input-hidden-cls-to-encoderscaffold-s-is-a-l","errorCode":null,"errorMessage":"When input hidden_cls to EncoderScaffold %s is a list, it must contain classes or instances with size specified by num_hidden_instances, got %d vs %d.","messagePattern":"When input hidden_cls to EncoderScaffold (.+?) is a list, it must contain classes or instances with size specified by num_hidden_instances, got (.+?) vs (.+?)\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/networks/encoder_scaffold.py","lineNumber":205,"sourceCode":"      embeddings = (\n          tf_keras.layers.Dropout(\n              rate=embedding_cfg['dropout_rate'])(embeddings))  # pyrefly: ignore[unsupported-operation]\n\n      mask_cfg = {} if mask_cfg is None else mask_cfg\n      if inspect.isclass(mask_cls):\n        mask_layer = mask_cls(**mask_cfg)\n      else:\n        mask_layer = mask_cls\n      attention_mask = mask_layer(embeddings, mask)\n\n    data = embeddings\n\n    layer_output_data = []\n    hidden_layers = []\n    hidden_cfg = hidden_cfg if hidden_cfg else {}\n\n    if isinstance(hidden_cls, list) and len(hidden_cls) != num_hidden_instances:\n      raise RuntimeError(\n          ('When input hidden_cls to EncoderScaffold %s is a list, it must '\n           'contain classes or instances with size specified by '\n           'num_hidden_instances, got %d vs %d.') % self.name, len(hidden_cls),\n          num_hidden_instances)\n    # Consider supporting customized init states.\n    recursive_states = None\n    for i in range(num_hidden_instances):\n      if isinstance(hidden_cls, list):\n        cur_hidden_cls = hidden_cls[i]\n      else:\n        cur_hidden_cls = hidden_cls\n      if inspect.isclass(cur_hidden_cls):\n        if hidden_cfg and 'attention_cfg' in hidden_cfg and (\n            layer_idx_as_attention_seed):\n          hidden_cfg = copy.deepcopy(hidden_cfg)\n          hidden_cfg['attention_cfg']['seed'] = i\n        if feed_layer_idx:\n          hidden_cfg['layer_idx'] = i","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/networks/encoder_scaffold.py#L187-L223","documentation":"Error \"When input hidden_cls to EncoderScaffold %s is a list, it must contain classes or instances with size specified by num_hidden_instances, got %d vs %d.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/networks/encoder_scaffold.py:205 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"}