{"record":{"id":"14b01dbe0462b780","repo":"hankcs/HanLP","slug":"self-model-config-pad-token-id-has-to-be-defined","errorCode":null,"errorMessage":"self.model.config.pad_token_id has to be defined.","messagePattern":"self\\.model\\.config\\.pad_token_id has to be defined\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"hanlp/components/amr/amrbart/model_interface/modeling_bart.py","lineNumber":84,"sourceCode":"_QA_EXPECTED_OUTPUT = \"' nice puppet'\"\n\n\nBART_PRETRAINED_MODEL_ARCHIVE_LIST = [\n    \"facebook/bart-large\",\n    # see all BART models at https://huggingface.co/models?filter=bart\n]\n\n\ndef shift_tokens_right(input_ids: torch.Tensor, pad_token_id: int, decoder_start_token_id: int):\n    \"\"\"\n    Shift input ids one token to the right.\n    \"\"\"\n    shifted_input_ids = input_ids.new_zeros(input_ids.shape)\n    shifted_input_ids[:, 1:] = input_ids[:, :-1].clone()\n    shifted_input_ids[:, 0] = decoder_start_token_id\n\n    if pad_token_id is None:\n        raise ValueError(\"self.model.config.pad_token_id has to be defined.\")\n    # replace possible -100 values in labels by `pad_token_id`\n    shifted_input_ids.masked_fill_(shifted_input_ids == -100, pad_token_id)\n\n    return shifted_input_ids\n\n\ndef _make_causal_mask(input_ids_shape: torch.Size, dtype: torch.dtype, past_key_values_length: int = 0):\n    \"\"\"\n    Make causal mask used for bi-directional self-attention.\n    \"\"\"\n    bsz, tgt_len = input_ids_shape\n    mask = torch.full((tgt_len, tgt_len), torch.tensor(torch.finfo(dtype).min))\n    mask_cond = torch.arange(mask.size(-1))\n    mask.masked_fill_(mask_cond < (mask_cond + 1).view(mask.size(-1), 1), 0)\n    mask = mask.to(dtype)\n\n    if past_key_values_length > 0:\n        mask = torch.cat([torch.zeros(tgt_len, past_key_values_length, dtype=dtype), mask], dim=-1)","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/model_interface/modeling_bart.py#L66-L102","documentation":"Feedforward accepts dropout as a scalar (broadcast to all layers) or a per-layer list; if you pass a list its length must equal num_layers, otherwise the constructor raises ValueError.","triggerScenarios":"Passing dropout=[0.2, 0.5] with num_layers=3, or dropout=0.5 as a string/list with the wrong length via config.","commonSituations":"Hyperparameter sweeps generating per-layer dropout lists of the wrong length; editing configs and changing layer counts; JSON configs where a scalar was replaced by a list.","solutions":["Pass a scalar dropout (e.g. dropout=0.5) to apply uniformly","Set len(dropout) == num_layers","Validate generated sweep configs before model construction"],"exampleFix":"# before\nFeedforward(input_dim=300, num_layers=3, hidden_dims=[128]*3, dropout=[0.2, 0.5])\n# after\nFeedforward(input_dim=300, num_layers=3, hidden_dims=[128]*3, dropout=0.5)","handlingStrategy":"validation","validationCode":"assert isinstance(dropout, (int, float)) or len(dropout) == num_layers","typeGuard":null,"tryCatchPattern":"try:\n    ff = Feedforward(..., dropout=dropout)\nexcept ValueError:\n    ff = Feedforward(..., dropout=0.5)","preventionTips":["Use scalar dropout unless per-layer rates are needed","Validate sweep-generated configs programmatically"],"tags":["hanlp","feedforward","dropout","config-validation"],"backgroundTag":"config-validation-failed","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}