Skip to main content

Why a skops File Changes Every Time You Save the Same Model

· 7 min read
Jagdish Kumawat
Founder @ Dewiride

Save the same scikit-learn model twice with skops and you get two files with different SHA-256 hashes, even though nothing about the model changed. That matters to any tool that decides whether something changed by hashing files. This guide opens the two files, shows the two reasons they differ, and compares the models the reliable way: by what they predict. It uses skops 0.16.0 with scikit-learn 1.9.1.

The Example​

A tiny LinearRegression learns y = 2x from three points. A script saves it twice, to first.skops and second.skops, and prints the start of each file's SHA-256 hash.

Prerequisites​

  • scikit-learn and skops in your project, for example with uv add scikit-learn skops. This guide uses skops 0.16.0 and scikit-learn 1.9.1 on Python 3.15.2.

Step 1: Save the Same Model Twice​

save_twice.py
import hashlib
from pathlib import Path

import skops.io as sio
from sklearn.linear_model import LinearRegression

model = LinearRegression().fit([[1], [2], [3]], [2, 4, 6])

for name in ("first.skops", "second.skops"):
sio.dump(model, name)
digest = hashlib.sha256(Path(name).read_bytes()).hexdigest()
print(name, digest[:16])

The save_twice.py script in a macOS-style code window: a LinearRegression fitted on three points, then a loop that saves it with skops.io.dump to first.skops and second.skops and prints the first 16 characters of each file's SHA-256 hash.

Terminal
uv run python save_twice.py
Output
first.skops 7f41d4cf14e1a00b
second.skops 286595b6004fac75

The terminal after uv run python save_twice.py: first.skops 7f41d4cf14e1a00b and second.skops 286595b6004fac75, two different hashes.

The same model, saved a moment apart, gave two different hashes.

Step 2: Look Inside the Two Files​

A skops file is a zip file. This script lists each one's entries and the date and time stored with each:

inside.py
import zipfile

for name in ("first.skops", "second.skops"):
with zipfile.ZipFile(name) as archive:
print(name)
for entry in archive.infolist():
print(" ", entry.filename, entry.date_time)
Output
first.skops
4557892240.npy (2026, 11, 30, 17, 59, 16)
4308029008.npy (2026, 11, 30, 17, 59, 16)
4557891856.npy (2026, 11, 30, 17, 59, 16)
4556894736.npy (2026, 11, 30, 17, 59, 16)
schema.json (2026, 11, 30, 17, 59, 16)
second.skops
4557892240.npy (2026, 11, 30, 17, 59, 16)
4308029008.npy (2026, 11, 30, 17, 59, 16)
4557891856.npy (2026, 11, 30, 17, 59, 16)
4556894736.npy (2026, 11, 30, 17, 59, 16)
schema.json (2026, 11, 30, 17, 59, 16)

The terminal after uv run python inside.py: both files hold four .npy entries with long numeric names and a schema.json, all stamped 2026-11-30 17:59:16.

Each file holds the model's arrays as .npy entries, plus a schema.json that describes the model. The arrays' names are long numbers, and every entry carries the time it was saved. Within this one run, the names and times match. So something else differs.

Step 3: Find What Differs​

This script compares each entry's bytes between the two files:

compare_members.py
import zipfile

with zipfile.ZipFile("first.skops") as first, zipfile.ZipFile("second.skops") as second:
for name in first.namelist():
same = first.read(name) == second.read(name)
print(f"{name:20} {'same bytes' if same else 'different'}")
Output
4557892240.npy same bytes
4308029008.npy same bytes
4557891856.npy same bytes
4556894736.npy same bytes
schema.json different

The model's numbers are identical. Only schema.json differs, and inside it, skops records __id__ values, numbers that it takes from Python's id() of the objects it saves. Listing a few of them from each file:

Output
first.skops __id__ values: [4307166464, 4308029008, 4324069600] ...
second.skops __id__ values: [4308029008, 4324069600, 4324069600] ...

Python's id() reference explains why they move: an object's id is "unique and constant for this object during its lifetime. Two objects with non-overlapping lifetimes may have the same id() value." Objects created while saving get new ids each time.

Step 4: Save Again, in a New Run​

Running save_twice.py a second time, a few seconds later, changed both the hashes and the entries:

Output
first.skops fda41295c9da823b
second.skops 27516b5ab32ef906
Output (inside.py, first lines)
first.skops
4562430608.npy (2026, 11, 30, 17, 59, 34)
4312387152.npy (2026, 11, 30, 17, 59, 34)

Each array's name is also an id() number, so the names changed in the new run, and the time moved on to 17:59:34. Python's zipfile reference explains the time: when an entry is written by name, "the date and time is set to the current date and time."

So a skops file changes on every save for two reasons: ids that differ between saves, and the time of saving.

Compare the Models, Not the Files​

To check that two saved models are the same model, load them and compare what they hold and what they predict:

compare.py
import skops.io as sio

first = sio.load("first.skops")
second = sio.load("second.skops")

print("first: ", first.coef_, first.intercept_)
print("second:", second.coef_, second.intercept_)
print("Same predictions:", (first.predict([[10]]) == second.predict([[10]])).all())
Output
first: [2.] 1.3322676295501878e-15
second: [2.] 1.3322676295501878e-15
Same predictions: True

The terminal after uv run python compare.py: both models have the coefficient 2 and the same tiny intercept, and Same predictions: True.

Both files hold the same model. sio.load loaded them without a list of trusted types, because LinearRegression uses only types skops trusts by default.

Common Mistakes​

MistakeWhat happensDo this instead
Deciding a model changed because its file's hash changedEvery save gives a new hash, so the model always looks changedCompare predictions, or the model's numbers
Expecting the same file from the same code on two computersThe ids and the save time differ there tooCompare the models' outputs

Troubleshooting​

SymptomLikely causeFix
A tool that tracks files by hash reports the model as changed after a retrain with identical resultsskops writes new ids and a new time on every saveJudge the model by its metrics and predictions, not by the file's hash

FAQ​

Is the model inside really identical?​

Here, yes: the four .npy arrays were byte-for-byte the same, and both models gave the same coefficient and the same prediction.

Does this make skops less safe?​

No. The ids are labels inside the file; loading still checks every type against the trusted list, which is what skops is for.

Conclusion​

Two saves of the same LinearRegression gave two different SHA-256 hashes, because skops's schema.json records Python object ids and every zip entry carries the save time. The arrays inside were identical, and both models predicted the same. When you need to know whether a model changed, compare the models, not the files.

Additional Resources​