Skip to content

KeyError: 'default' issue #17

Description

@anr2me

I was using the latest transformers (5.9.0) with python 3.13, and got this KeyError: 'default' error at:

# HACK: 强制设置为default
self.rope_type = "default"
self.max_seq_len_cached = config.max_position_embeddings
self.original_max_seq_len = config.max_position_embeddings
self.config = config
self.rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]

Where self.rope_type is hardcoded to "default", and ROPE_INIT_FUNCTIONS imported with:

from transformers.modeling_rope_utils import ROPE_INIT_FUNCTIONS

However, according to Claude, "default" key only exist on transformers ~4.40–4.42:

transformers 4.43+ use "llama3" or "dynamic"
Some other builds use "linear", "yarn"

A few suggestions from Claude are:

  • Using fallback when "default" doesn't exist:
# Try one of these based on what print() shows you
self.rope_init_fn = ROPE_INIT_FUNCTIONS.get("default") \
    or ROPE_INIT_FUNCTIONS.get("llama3") \
    or list(ROPE_INIT_FUNCTIONS.values())[0]
  • Bypass ROPE_INIT_FUNCTIONS entirely and define the init function directly:
def default_rope_init(config, device):
    base = config.rope_theta if hasattr(config, "rope_theta") else 10000.0
    dim = config.hidden_size // config.num_attention_heads
    inv_freq = 1.0 / (base ** (torch.arange(0, dim, 2, device=device).float() / dim))
    return inv_freq, 1.0

self.rope_init_fn = default_rope_init

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions