hankcs/HanLP · error · ValueError
self.model.config.pad_token_id has to be defined.
Error message
self.model.config.pad_token_id has to be defined.
What it means
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.
Source
Thrown at hanlp/components/amr/amrbart/model_interface/modeling_bart.py:84
_QA_EXPECTED_OUTPUT = "' nice puppet'"
BART_PRETRAINED_MODEL_ARCHIVE_LIST = [
"facebook/bart-large",
# see all BART models at https://huggingface.co/models?filter=bart
]
def shift_tokens_right(input_ids: torch.Tensor, pad_token_id: int, decoder_start_token_id: int):
"""
Shift input ids one token to the right.
"""
shifted_input_ids = input_ids.new_zeros(input_ids.shape)
shifted_input_ids[:, 1:] = input_ids[:, :-1].clone()
shifted_input_ids[:, 0] = decoder_start_token_id
if pad_token_id is None:
raise ValueError("self.model.config.pad_token_id has to be defined.")
# replace possible -100 values in labels by `pad_token_id`
shifted_input_ids.masked_fill_(shifted_input_ids == -100, pad_token_id)
return shifted_input_ids
def _make_causal_mask(input_ids_shape: torch.Size, dtype: torch.dtype, past_key_values_length: int = 0):
"""
Make causal mask used for bi-directional self-attention.
"""
bsz, tgt_len = input_ids_shape
mask = torch.full((tgt_len, tgt_len), torch.tensor(torch.finfo(dtype).min))
mask_cond = torch.arange(mask.size(-1))
mask.masked_fill_(mask_cond < (mask_cond + 1).view(mask.size(-1), 1), 0)
mask = mask.to(dtype)
if past_key_values_length > 0:
mask = torch.cat([torch.zeros(tgt_len, past_key_values_length, dtype=dtype), mask], dim=-1)View on GitHub (pinned to ddb1299bdd)
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
Example fix
# before Feedforward(input_dim=300, num_layers=3, hidden_dims=[128]*3, dropout=[0.2, 0.5]) # after Feedforward(input_dim=300, num_layers=3, hidden_dims=[128]*3, dropout=0.5)
Defensive patterns
Strategy: validation
Validate before calling
assert isinstance(dropout, (int, float)) or len(dropout) == num_layers
Try / catch
try:
ff = Feedforward(..., dropout=dropout)
except ValueError:
ff = Feedforward(..., dropout=0.5) Prevention
- Use scalar dropout unless per-layer rates are needed
- Validate sweep-generated configs programmatically
When it happens
Trigger: Passing dropout=[0.2, 0.5] with num_layers=3, or dropout=0.5 as a string/list with the wrong length via config.
Common situations: 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.
Understand the failure class
Background: Config validation failed: what "invalid value for {key}" and settings-rejection errors mean across 19 open-source libraries — this error's family across 19 libraries.
Related errors
- Unsupported argument type: {item}
- Unrecognized mapper type {mapper}
- embed_dim must be divisible by num_heads (got `embed_dim`: {
- You cannot specify both input_ids and inputs_embeds at the s
- Unsupported dim: {x.dim()}. Only 2d (T,C) or 3d (B,T,C) is s
AI-assisted analysis of hankcs/HanLP@ddb1299bdd (2026-08-27).
Data as JSON: /api/errors/14b01dbe0462b780.
Report an issue: GitHub.