i made this script to make my LoRA compatible with nunchaku LoRA loader, as it couldn't handle the text encoder weights from kohya_ss with "train_t5xxl: true".
This script filters a LoRA .safetensors file to keep only the U-Net weights, removing any text encoder weights. Useful for sharing or optimizing LoRA files for inference.
script.py: Main script to filter LoRA weights.WINDOWS-install.bat: Sets up a Python virtual environment and installs dependencies (Windows).WINDOWS-start.bat: Activates the environment and runs the script (Windows).inspect-lora.py: (Optional) Script to inspect LoRA keys.lora_keys.txt: (Optional) Example output of LoRA keys.
- open cmd and
git clone https://github.com/tazztone/lora-remove-te-weights - Place your LoRA file(s) (e.g.,
m1r4.safetensors) in thePUT-SAFETENSORS-HEREfolder. - Run
WINDOWS-install.batto set up the environment and install dependencies. - Run
WINDOWS-start.batto process your files.
- Place your LoRA file (e.g.,
m1r4.safetensors) in this directory or the correct folder. - Edit
script.pyto set the correct input/output filenames or folder if needed. - (Recommended) Use a Python virtual environment.
- Install dependencies:
pip install torch safetensors numpy
- Run the script:
python script.py
- A new file (e.g.,
m1r4_unet_only.safetensors) containing only U-Net weights.
- Do not commit large model files (
.safetensors) to GitHub. - Add your virtual environment and model files to
.gitignore(see below).
MIT