Skip to content
Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,4 @@ test-results/
# AI agent local setup artifacts
/.agents/skills
/.claude/skills
*.bak
7 changes: 7 additions & 0 deletions src/transformers/core_model_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,14 @@ def convert_and_load_state_dict_in_model(
pattern_to_converter = {k: converter for converter in converters for k in converter.source_patterns}

state_dict = sorted(state_dict.items(), key=lambda kv: dot_natural_key(kv[0]))
import gc as _gc
_tensor_count = 0
for original_key, tensor in state_dict:
_tensor_count += 1
if _tensor_count % 1000 == 0:
_gc.collect()
if torch.cuda.is_available():
torch.cuda.empty_cache()
# 1. Rename the key according to all renaming pattern and optional weight converter patterns
renamed_key, source_pattern = rename_source_key(
original_key, renamings, converters, prefix, meta_model_state_dict
Expand Down
Loading
Loading