Skip to content
Merged
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
15 changes: 15 additions & 0 deletions defuser/checkpoint_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import torch
from transformers.core_model_loading import Chunk


class OwnedChunk(Chunk):
"""Split fused tensors into independent chunks so save/load keeps both weights."""

@torch.no_grad
def convert(
self, input_dict: dict[str, torch.Tensor], source_patterns: list[str], target_patterns: list[str], **kwargs
) -> dict[str, torch.Tensor]:
split = super().convert(input_dict, source_patterns, target_patterns, **kwargs)
# `torch.chunk()` returns views into shared storage, which can make safetensors
# drop one side of the split tensor during save. Clone each chunk to own storage.
return {name: tensor.contiguous().clone() for name, tensor in split.items()}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "Defuser"
version = "0.0.13"
version = "0.0.14"
description = "Model defuser helper for HF Transformers."
readme = "README.md"
requires-python = ">=3.9"
Expand Down