Spaces:
Sleeping
Sleeping
File size: 681 Bytes
5a5e72e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | from __future__ import annotations
import hashlib
from typing import Any
def need(ok: Any, message: str) -> None:
if not ok:
raise ValueError(message)
def reloaded_variables_hash(model: Any) -> str:
h = hashlib.sha256()
scope = model.name + "/"
for v in model.variables:
path = str(getattr(v, "path", v.name))
need(
path and not path.startswith(scope),
"Reloaded model variable path must be nonempty and omit the model scope",
)
a = v.numpy()
h.update((scope + path).encode())
h.update(str((a.shape, str(a.dtype))).encode())
h.update(a.tobytes())
return h.hexdigest()
|