You have hundreds of LoRA and checkpoint .safetensors files sitting on disk. Here's something most people never realize: you can "open" any of them with plain Python — no PyTorch, no safetensors library, no GPU — just Python's built-in modules. In seconds you'll know the base model, the dtype, the layer count, even how it was trained — all read from just the first few KB of the file.
✅ The code in this article was tested on a real LoRA (Beauty.safetensors) — the actual output is shown below.
📌 Note: this is a desktop tool — it reads files on your machine via a path. That means it can't run inside TensorArt's cloud ComfyUI workflow (its sandbox gives no file-system or free-Python access), but it runs perfectly in local ComfyUI or any terminal.
🧠 THE CONCEPT, IN 2 MINUTES
The .safetensors format is refreshingly simple:
[ 8 bytes ] header length (little-endian unsigned 64-bit integer)
[ N bytes ] header = JSON: every tensor (name, shape, dtype)
[ the rest ] raw weight data
That's it! Because the header is plain JSON, you can read it without loading any weights — even a 20 GB file only needs its first few hundred KB touched. This is exactly why safetensors became the standard: it's safe (unlike pickle, it can't execute hidden code) and fast to inspect.
🐍 THE COMPLETE SCRIPT (COPY-PASTE, RUNS AS-IS)
Save as check_:
"""Dissect a .safetensors file without PyTorch — pure standard library."""
import json, struct, sys
def read_header(path):
with open(path, "rb") as f:
n = struct.unpack("<Q", (8))[0] # first 8 bytes = header length
header = json.loads((n).decode("utf-8")) # header = JSON
meta = header.pop("__metadata__", {}) # training metadata, separated
return header, meta
path = sys.argv[1] if len(sys.argv) > 1 else "model.safetensors"
hdr, meta = read_header(path)
print("── SUMMARY ──────────────────────────────")
print(f"Tensor count : {len(hdr)}")
dtypes = {}
for t in hdr.values():
dtypes[t["dtype"]] = dtypes.get(t["dtype"], 0) + 1
print(f"Dtypes : {dtypes}")
base = (meta.get("ss_base_model_version")
or meta.get("modelspec.architecture", "?"))
print(f"Base model : {base}")
if meta.get("ss_network_module"):
print(f"Trainer : {meta['ss_network_module']} "
f"(rank={meta.get('ss_network_dim', '?')}, "
f"alpha={meta.get('ss_network_alpha', '?')})")
name, info = next(iter(hdr.items()))
print(f"Example tensor : {name} {info['shape']} {info['dtype']}")
📝 CREATING THE FILE (BEGINNER-FRIENDLY)
Never created a Python file before? Two ways — pick one:
Option A — Notepad (already on Windows):
1. Open Notepad (Start → type "notepad")
2. Paste the script above
3. File → Save As → navigate to a folder (e.g. D:\tools)
4. In the save dialog:
- File name: check_ — type it WITH QUOTES ("check_") so Notepad doesn't append .txt
- Save as type: change to All Files (*.*)
- Encoding: UTF-8
⚠️ The classic beginner trap: ending up with check_.txt. If that happens, rename the file and delete the .txt part.
Option B — VS Code (nicer, free): install VS Code (), open a folder, create a new file named check_, paste, Ctrl+S. Done — no quoting tricks needed.
▶️ RUNNING IT VIA POWERSHELL
1. Open PowerShell (Start → type "powershell" → Enter)
2. First, make sure Python exists:
python --version
If you see something like Python 3.11.x you're good. If Windows opens the Microsoft Store instead, either install Python from there (one click) or grab it from — and tick "Add Python to PATH" during install.
3. Go to the folder where you saved the script, then run it with the path to any .safetensors file:
cd "D:\tools"
python check_ "D:\ComfyUI\models\loras\Beauty.safetensors"
Two small rules:
- Always quote paths that contain spaces (most model folders do)
- Drag-and-drop trick: type "python check_ " then DRAG the model file from Explorer into the PowerShell window — its full path gets pasted for you, quotes included 💡
REAL OUTPUT FROM MY OWN FILE
── SUMMARY ──────────────────────────────
Tensor count : 792
Dtypes : {'F16': 792}
Base model : krea2
Trainer : networks.lora_krea2 (rank=64, alpha=32.0)
Example tensor : lora_unet_blocks_0_attn_gate.alpha [] F16
Done in a fraction of a second — without loading a single weight.
🔍 WHY IS THIS ACTUALLY USEFUL?
1. Check a LoRA's base model before you use it. The ss_base_model_version metadata tells you whether the LoRA targets SDXL, Flux, or Krea2. Pair it with the wrong base model and your output gets wrecked — now you can verify in seconds.
2. Catch "lying" filenames. A file can be NAMED sdxl and be anything else. Metadata can't lie — it was written by the trainer at creation time.
3. Read the training history. ss_network_dim (rank), ss_network_alpha, learning rate, epochs — it's all recorded. Perfect for comparing two training runs of the same concept.
4. Instantly inspect community files. Grabbed a LoRA from a friend or a Discord? One command tells you what's inside.
5. Foundation for automation. This 30-line script scales up: scan your entire LoRA folder and generate a spreadsheet of every base model you own (leave it as an exercise — or wait for part 2 😉).
🧩 BONUS: DISSECTING LORA KEYS
Ever wondered why some keys read lora_unet_... and others lora_te_...? Try this:
from collections import Counter
prefix = Counter(k.split("_")[1] for k in hdr if k.startswith("lora_"))
print("Distribution:", dict(prefix))
unet = weights for the image model; te1/te2 (text encoders) = weights for prompt understanding. If a LoRA only contains text-encoder weights, it won't change the visual style much.
⚠️ LIMITATIONS
- This reads structure + metadata, not the weight values. To inspect actual tensors (e.g., hunting NaNs), you'll need the safetensors library or PyTorch.
- Metadata is written by the trainer — if the file has been re-merged or baked since, metadata may be altered or missing.
🎁 WRAPPING UP
safetensors is an honest format: what you see in the header is what's in the file. With 30 lines of standard-library Python, you can peek inside any model file — fast, safe, and with nothing to install.
Compatibility Note
This Python script is designed for local ComfyUI installations and terminal environments. It requires access to the local filesystem to read ".safetensors" files. TensorArt Cloud ComfyUI may not support this workflow because of its sandbox restrictions.
If you use TensorArt's cloud environment, check its available tools and supported workflow features before attempting to run the script.
Comment if you want PART 2: a folder scanner that turns all your LoRAs into a tidy spreadsheet (base model, rank, dtype, size) — automatically! 🚀



