From 943eae12118f1cb2ddb6c96c038103e777c833b1 Mon Sep 17 00:00:00 2001 From: Kohya S Date: Thu, 19 Jan 2023 22:04:16 +0900 Subject: [PATCH] Add LoRA weights checking script --- networks/check_lora_weights.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 networks/check_lora_weights.py diff --git a/networks/check_lora_weights.py b/networks/check_lora_weights.py new file mode 100644 index 00000000..1140e3b3 --- /dev/null +++ b/networks/check_lora_weights.py @@ -0,0 +1,31 @@ +import argparse +import os +import torch +from safetensors.torch import load_file + + +def main(file): + print(f"loading: {file}") + if os.path.splitext(file)[1] == '.safetensors': + sd = load_file(file) + else: + sd = torch.load(file, map_location='cpu') + + values = [] + + keys = list(sd.keys()) + for key in keys: + if 'lora_up' in key: + values.append((key, sd[key])) + print(f"number of LoRA-up modules: {len(values)}") + + for key, value in values: + print(f"{key},{torch.mean(torch.abs(value))}") + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument("file", type=str, help="model file to check / 重みを確認するモデルファイル") + args = parser.parse_args() + + main(args.file)