Skip to content

Commit 05f287d

Browse files
committed
fix
1 parent fce79da commit 05f287d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/transformers/core_model_loading.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,9 @@ def convert_and_load_state_dict_in_model(
435435
prefix = model.base_model_prefix
436436
tp_plan = tp_plan or {} # {glob_pattern: plan_obj_or_key}
437437
device_map = device_map or {"": "cpu"} # {exact_target_key: device}
438+
# Here, we first sort by number of submodules, then length of the full string, to make sure to match correctly
438439
device_map_regex = re.compile(
439-
"|".join(rf"({k})" for k in sorted(device_map.keys(), key=lambda x: x.count("."), reverse=True))
440+
"|".join(rf"({k})" for k in sorted(device_map.keys(), key=lambda x: (x.count("."), len(x)), reverse=True))
440441
)
441442
dtype_plan = dtype_plan or {} # {glob_pattern: dtype}
442443
weight_mapping = weight_mapping or {} # {glob_pattern: WeightConverter}

0 commit comments

Comments
 (0)