diff --git a/.gitignore b/.gitignore index 922c797..b164ad0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ __pycache__ .venv meta + +# using prettier for formatting the markdown +.prettierrc diff --git a/README.md b/README.md index 5e83b5f..b073fc6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # LoRA inspector + - [LoRA inspector](#lora-inspector) - [Install](#install) - [Usage](#usage) @@ -9,12 +10,19 @@ - [Development](#development) - [Future](#future) - [Reference](#reference) - + -Inspect LoRA files for meta info (and hopefully quantitative analysis of the LoRA weights) +Inspect LoRA files for meta info (and hopefully quantitative analysis of the +LoRA weights) - view training parameters -- extract metadata to be stored (we can store it in json currently) +- extract metadata to be stored (we can store it in JSON currently) + +--- + +_NOTE_ this is a work in progress and not meant for production use. _NOTE_ + +--- ## Install @@ -27,7 +35,11 @@ torch safetensors ``` -Can install them using `pip install torch safetensors`, make a venv/conda with them, or add this script to your training directory (to access the dependencies). +Can install them one of the following: + +- `pip install torch safetensors`, +- make/use with a venv/conda +- add this script to your training directory (to access the dependencies). ## Usage @@ -116,7 +128,9 @@ network dim/rank: 8.0 alpha: 4.0 module: networks.lora ### Save meta -We also have support for saving the meta that is extracted and converted from strings. We can then save those to a JSON file. These will save the metadata into `meta/alorafile.safetensors-{session_id}.json` in the meta directory. +We also have support for saving the meta that is extracted and converted from +strings. We can then save those to a JSON file. These will save the metadata +into `meta/alorafile.safetensors-{session_id}.json` in the meta directory. ```bash $ python lora-inspector.py ~/loras/alorafile.safetensors --save_meta @@ -135,7 +149,7 @@ network dim/rank: 8.0 alpha: 4.0 module: networks.lora ## Development -Formatted using [`black`](https://github.com/psf/black). +Formatted using [`black`](https://github.com/psf/black). ## Future diff --git a/parsers.py b/parsers.py deleted file mode 100644 index 75e2bf1..0000000 --- a/parsers.py +++ /dev/null @@ -1,118 +0,0 @@ -import json -from datetime import datetime -from typing import Callable - - -def to_datetime(str: str): - return datetime.fromtimestamp(float(str)) - - -parsers: dict[str, Callable] = { - "int": int, - "float": float, - "json": json.loads, - "bool": bool, - "dt": to_datetime, - "str": str, -} - - -schema: dict[str, str] = { - "ss_learning_rate": "float", - "ss_max_bucket_reso": "int", - "ss_text_encoder_lr": "float", - "ss_epoch": "int", - "ss_unet_lr": "float", - "ss_seed": "int", - "ss_max_train_steps": "int", - "ss_sd_model_name": "str", - "ss_new_vae_hash": "str", - "ss_resolution": "str", - "ss_full_fp16": "bool", - "ss_vae_hash": "str", - "ss_gradient_checkpoint": "bool", - "ss_output_name": "bool", - "ss_bucket_info": "json", - "sshs_model_hash": "str", - "sshs_legacy_hash": "str", - "ss_caption_dropout_rate": "float", - "ss_caption_dropout_every_n_epochs": "int", - "ss_caption_tag_dropout_rate": "float", - "ss_sd_scripts_commit_hash": "str", - "ss_gradient_checkpointing": "bool", - "ss_training_finished_at": "dt", - "ss_vae_name": "str", - "ss_total_batch_size": "int", - "ss_batch_size_per_device": "int", - "ss_color_aug": "bool", - "ss_flip_aug": "bool", - "ss_lr_warmup_steps": "int", - "ss_network_module": "str", - "ss_lr_scheduler": "str", - "ss_num_epochs": "int", - "ss_mixed_precision": "str", - "ss_shuffle_caption": "bool", - "ss_training_started_at": "dt", - "ss_v2": "bool", - "ss_keep_tokens": "bool", - "ss_random_crop": "bool", - "ss_cache_latents": "bool", - "ss_gradient_accumulation_steps": "int", - "ss_clip_skip": "int", - "ss_dataset_dirs": "json", - "ss_training_comment": "str", - "ss_network_alpha": "float", - "ss_network_dim": "float", - "ss_reg_dataset_dirs": "json", - "ss_num_batches_per_epoch": "int", - "ss_num_reg_images": "int", - "ss_max_token_length": "int", - "ss_sd_new_model_hash": "int", - "ss_face_crop_aug_range": "str", - "ss_min_bucket_reso": "int", - "ss_bucket_no_upscale": "bool", - "ss_prior_loss_weight": "float", - "ss_network_args": "json", - "ss_enable_bucket": "bool", - "ss_num_train_images": "int", - "ss_lowram": "bool", - "ss_optimizer": "str", - "ss_tag_frequency": "json", - "ss_session_id": "str", - "ss_max_grad_norm": "float", - "ss_noise_offset": "float", -} - - -def parse_item(key: str, value: str) -> int | float | bool | datetime | str | None: - if key not in schema: - print(f"invalid key in schema {key}") - return value - - if schema[key] == "int" and value == "None": - return None - - if schema[key] == "float" and value == "None": - return None - - print(key) - return parsers[schema[key]](value) - - -def parse(entries: dict[str, str]): - results = {} - for k in entries.keys(): - v = entries[k] - results[k] = parse_item(k, v) - return results - - -# if __name__ == "__main__": -# with open("meta/last.safetensors.json") as f: -# loaded: dict[str, str] = json.load(f) -# results = {} -# for (k, v) in parse(loaded): -# # v = loaded[k] -# results[k] = v -# -# print(json.dumps(results, default=str))