These scripts are basic sketches designed to facilitate the management and analysis of metadata within Stable Diffusion model files, particularly those using the .safetensors format. They provide a simple, command-line approach for both adding information to a model and extracting diagnostic details from it.
These Ruby scripts are designed to take user-defined metadata and inject it into an existing .safetensors model file.
add_metadata.rb: This script is a basic version that directly uses hardcoded metadata, which is useful for setting a standard metadata block across multiple models.add_metadata-lora.rb: This script is a more flexible, generalized tool that reads its configuration (including the target model path and all desired metadata) from a JSON file. This allows for easy batch processing and configuration management. It also handles the conversion of non-standard keys (like the localthumbnail_filenameor a simpletrigger_wordsarray) into standardized metadata keys (likemodelspec.thumbnailandss_activation_tags).
- Backup and Safety: The original model file is always moved to a relative backup directory (
../pre-metadata-update) before modification, ensuring data integrity. - Metadata Standardization: It supports and promotes the use of standardized metadata formats, primarily adhering to the SAI Model Specification (using
modelspec.*keys) and widely-used keys from the Kohya-SS training environment (usingss_*keys).
This Python script is a diagnostic tool designed to analyze a .safetensors file and infer key characteristics of the embedded LoRA, offering valuable insights that may be missing or contradictory in the metadata.
- Metadata Dump: It prints the entire raw metadata dictionary found in the file.
- Architectural Inference: It analyzes the tensor keys (the names of the weights inside the file) to determine the likely base architecture (e.g., SD 1.5, SDXL, FLUX, WAN). This relies on highly specific key prefixes that act as architectural fingerprints.
- Contradiction Warning: It compares the base model inferred from the metadata (e.g., "Pony Diffusion") with the base model inferred from the tensor keys (e.g., "SDXL"). If these differ, it flags a CONTRADICTION DETECTED warning. This conservative diagnostic is crucial for alerting the user to potential interoperability risks between a finetuned model and a generic LoRA.
- Trigger Word Heuristic: It attempts to infer potential trigger words either from the explicit
ss_activation_tagskey or via a heuristic based on the most frequent tags found in the training data metadata (ss_tag_frequency).