Skip to content

Prefix sizing from per_layer_config ignores KV head count #3478

Description

@DaoyuanLi2816

System Info

  • PEFT main: 051b2c5d
  • Reproduction is config-only; no model download or accelerator is required.

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder
  • My own task or dataset (give details below)

Reproduction

#3471 provisions prefix tuning for the largest per-layer KV footprint, but the selection loop compares only head_dim:

if layer_head_dim > head_dim:
    head_dim = layer_head_dim
    num_key_value_heads = layer_num_kv

A layer can have the same (or smaller) head dimension and more KV heads, making its total KV width larger. In that case the override is ignored. Later, _get_layer_kv_target_shape() returns the wider layer shape and get_prompt() skips that layer because the prefix was provisioned with too few heads.

Minimal reproduction:

from peft import PrefixTuningConfig, TaskType
from peft.utils.other import _prepare_prompt_learning_config

config = PrefixTuningConfig(task_type=TaskType.CAUSAL_LM, num_virtual_tokens=4)
model_config = {
    "num_hidden_layers": 2,
    "hidden_size": 1024,
    "num_attention_heads": 8,
    "num_key_value_heads": 4,
    "head_dim": 128,
    "per_layer_config": {
        1: {"head_dim": 128, "num_key_value_heads": 8},
    },
}

_prepare_prompt_learning_config(config, model_config)
print(config.num_attention_heads, config.token_dim)

Current output:

4 512

The largest per-layer KV footprint is 8 * 128 = 1024, so the prefix should be provisioned as:

8 1024

The comparison should use layer_head_dim * layer_num_kv (including ties in head_dim) and retain the head/count pair that produces the largest footprint. A focused regression can exercise _prepare_prompt_learning_config() directly without depending on a Transformers 5.15 model. I can prepare that fix if this direction matches the intended behavior of #3471.

Expected behavior

Prefix tuning should provision enough KV width for the largest effective entry in per_layer_config, so a valid layer is not skipped solely because another layer has the same head dimension but fewer KV heads.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions