# /// 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")