Spaces:
Sleeping

Speech2Face / s2f /model_state.py
ProgramComputer's picture
Super-squash branch 'main' using huggingface_hub
5a5e72e
Raw History Blame Contribute Delete
681 Bytes
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()