Inspect-Lora: Tool for Examining LoRA Model Metadata
On this page

Inspect-Lora: Examining LoRA Model Metadata

LoRA models often contain valuable metadata that provides insights into how they were trained. The Inspect-Lora PowerShell function helps you extract, view, and save this metadata from .safetensors files. This tool is essential for anyone working with AI models who needs to understand model parameters, verify training configurations, or organize their model collection.

What This Tool Does

The Inspect-Lora function performs several useful tasks:

  1. Reads the embedded metadata from a .safetensors file
  2. Pretty-prints the metadata to the console in a readable format
  3. Saves the metadata as a separate JSON file next to the original LoRA file
  4. Handles any JSON formatting within the metadata

This makes it easy to quickly examine LoRA files and maintain a searchable record of your models’ parameters.

Installation Requirements

Before using this tool, ensure you have:

  • PowerShell 5.1 or higher
  • Python 3.6 or higher
  • The safetensors Python package installed

You can install the required Python package with:

pip install safetensors

Usage Examples

Basic Usage

To inspect a single LoRA file:

Inspect-Lora .\path\to\your\file.safetensors

Recursive Processing

To process all LoRA files in a directory and its subdirectories:

Get-ChildItem -Path "E:\projects\yiff_toolkit" -Filter "*.safetensors" -Recurse | 
  ForEach-Object {Inspect-Lora -filePath $_.FullName}

Viewing Without Saving

If you only want to view the metadata without saving it:

Inspect-Lora -filePath .\path\to\your\file.safetensors -saveJson:$false

The Code

Here’s the full PowerShell function:

<#
  The Inspect-Lora function takes a file path as input and uses Python to read the metadata from
  a .safetensors file. It then pretty-prints the metadata contents to the console and saves it
  next to the LoRA. The file path must be a valid path to a .safetensors file.

  Usage Examples:
  Inspect-Lora .\path\to\your\file.safetensors

  Recursively:
  Get-ChildItem -Path "E:\projects\yiff_toolkit" -Filter "*.safetensors" -Recurse | ForEach-Object {Inspect-Lora -filePath $_.FullName}
#>
function Inspect-Lora {
  param (
    [Parameter(Mandatory = $true, Position = 0)]
    [string]$filePath,
    [Parameter(Mandatory = $false, Position = 1)]
    [switch]$saveJson = $true
  )
  $escapedFilePath = $filePath -replace '\\', '\\\\'
  $pythonCommand = "import safetensors, json, pprint; metadata = safetensors.safe_open('" + $escapedFilePath + "', 'np').metadata(); pprint.pprint({k: json.loads(v) if v and v[0] in '[{' else v for k, v in metadata.items()}) if metadata is not None else {}"
  Start-Process python -ArgumentList "-c", "`"$pythonCommand`"" -NoNewWindow
  if ($saveJson) {
    $output = Invoke-Expression "python -c `"$pythonCommand`""
    $outputJsonPath = [IO.Path]::ChangeExtension($filePath, 'json')
    $output | Out-File $outputJsonPath -Force
  }
}

Example Output

When you run the Inspect-Lora function on a LoRA file, you’ll see output similar to this:

{
  "ss_batch_size_per_device": "4",
  "ss_bucket_no_upscale": "True",
  "ss_cache_latents": "True",
  "ss_clip_skip": "2",
  "ss_dataset_dirs": "{...}",
  "ss_learning_rate": "0.0001",
  "ss_max_train_steps": "2000",
  "ss_network_alpha": "4",
  "ss_network_dim": "32",
  "ss_network_module": "networks.lora",
  "ss_noise_offset": "0.0",
  "ss_optimizer": "AdamW8bit",
  "ss_resolution": "1024,1024",
  "ss_sdxl": "True",
  "ss_text_encoder_lr": "0.0001",
  "ss_training_comment": "training..."
}

This metadata reveals important information about the LoRA model, such as:

  • Training resolution (ss_resolution)
  • Learning rate (ss_learning_rate)
  • Network dimensions (ss_network_dim)
  • Whether it’s an SDXL model (ss_sdxl)
  • Number of training steps (ss_max_train_steps)

How It Works

The function uses a Python one-liner to:

  1. Import the necessary Python modules (safetensors, json, pprint)
  2. Open the .safetensors file and extract its metadata
  3. Parse any JSON strings within the metadata
  4. Pretty-print the result to the console
  5. Optionally save the output to a JSON file

The Python code is executed directly from PowerShell, making this a convenient cross-language utility.

Integration with Other Tools

This tool works well with other utilities in our toolkit:

For a complete LoRA workflow, check our LoRA Training Guide.

Troubleshooting

Common issues and solutions:

  • Error: No module named ‘safetensors’ - Install the missing Python package with pip install safetensors
  • No metadata displayed - Some LoRA files don’t contain metadata or use a different format
  • Permission errors - Ensure you have read/write access to both the LoRA file and its directory

Conclusion

The Inspect-Lora function is a valuable tool for anyone working with LoRA models. By extracting and saving metadata, it helps you understand model parameters, organize your collection, and troubleshoot issues. Whether you’re a model creator or simply a collector, this utility makes it easy to peek inside your .safetensors files and understand what makes them tick.

For more dataset and model management tools, explore our complete toolkit.