File size: 882 Bytes
bdae485
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# /// script
# requires-python = ">=3.14"
# dependencies = [
#     "huggingface-hub>=1",
#     "numpy>2",
#     "safetensors>=0.8",
#     "torch>2",
# ]
#
# [[tool.uv.index]]
# url = "https://download.pytorch.org/whl/cpu"
# ///

import huggingface_hub
import safetensors
import safetensors.torch
import torch

with safetensors.safe_open(
    filename=huggingface_hub.hf_hub_download(
        repo_id="krea/Krea-2-Turbo",
        filename="transformer/diffusion_pytorch_model-00001-of-00003.safetensors",
    ),
    framework="pt",
) as sft:
    lora: dict[str, torch.Tensor] = {}
    proj: torch.Tensor = sft.get_tensor("text_fusion.projector.weight")
    lora["transformer.text_fusion.projector.lora_A.weight"] = proj
    lora["transformer.text_fusion.projector.lora_B.weight"] = proj.new_tensor([[100.0]])
    safetensors.torch.save_file(lora, "pytorch_lora_weights.safetensors")