Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/transformers/core_model_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,12 @@ def __init__(self, source_patterns: str | list[str], target_patterns: str | list
for i, source_pattern in enumerate(self.source_patterns):
group_name = f"g{i}"
pattern = source_pattern.replace(".*.", r"\..*\.")
# Auto-anchor leaf-style patterns (those ending with an identifier char) at a key
# boundary, so e.g. ``experts.gate_up_proj`` does not also match
# ``experts.gate_up_proj_scale_inv``. Skip patterns that already end in an explicit
# anchor (``$``) or that intentionally end on a separator (``\.``) for prefix renames.
if pattern and (pattern[-1].isalnum() or pattern[-1] == "_"):
pattern = f"{pattern}(?=$|\\.)"
Comment on lines +658 to +663

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo we should allow it in case models need to replace anything that starts with "prefix", and the issue is in the regex of MoE in conversion mapping. We need to add an explicit /. in regex instead

in any case cc @Cyrilvallez to decide on it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah and probably error out? this is a good example where there's inteded vs not intended and we should probably not I think assume user wants one of the two

branches.append(f"(?P<{group_name}>{pattern})")
self.compiled_sources = re.compile("|".join(branches))

Expand Down
Loading