Skip to content

Instantly share code, notes, and snippets.

@aormorningstar
aormorningstar / rotation.py
Last active February 20, 2025 06:26
Find the rotation matrix that aligns one three-dimensional vector with another.
import numpy as np
def rotation(v1, v2):
"""
Compute a matrix R that rotates v1 to align with v2.
v1 and v2 must be length-3 1d numpy arrays.
"""
# unit vectors
u = v1 / np.linalg.norm(v1)
Ru = v2 / np.linalg.norm(v2)
@akii-i
akii-i / lora_convert.py
Last active July 18, 2023 19:13
LORA format conversion from cloneofsimo lora format to AUTOMATIC1111 webui format (kohya's format)
# Convert cloneofsimo lora format to AUTOMATIC1111 webui format (kohya's format)
# Will generate extra embedding files along with the converted lora
# Usage: python lora_convert.py path_to_lora output_folder [--overwrite]
# path_to_lora_file : path to lora safetensors in cloneofsimo lora format
# output_folder : path to folder for results in AUTOMATIC1111 webui format
# overwrite : overwrite the results in output_folder
# Example: python lora_convert.py .\lora_krk.safetensors .\
from safetensors import safe_open
from safetensors.torch import save_file