lllyasviel/Fooocus · error · OSError
hash of {path} (url: {url}) failed to validate
Error message
hash of {path} (url: {url}) failed to validate What it means
download_file() fetches a file over HTTP and, when a SHA-256 digest is supplied, recomputes the hash of the on-disk file and compares it to the expected value. On mismatch it raises OSError naming the path and URL. This catches both corrupted/interrupted downloads and upstream files that changed after the digest was pinned.
Source
Thrown at ldm_patched/k_diffusion/utils.py:47
return expanded.detach().clone() if expanded.device.type == 'mps' else expanded
def n_params(module):
"""Returns the number of trainable parameters in a module."""
return sum(p.numel() for p in module.parameters())
def download_file(path, url, digest=None):
"""Downloads a file if it does not exist, optionally checking its SHA-256 hash."""
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
if not path.exists():
with urllib.request.urlopen(url) as response, open(path, 'wb') as f:
shutil.copyfileobj(response, f)
if digest is not None:
file_digest = hashlib.sha256(open(path, 'rb').read()).hexdigest()
if digest != file_digest:
raise OSError(f'hash of {path} (url: {url}) failed to validate')
return path
@contextmanager
def train_mode(model, mode=True):
"""A context manager that places a model into training mode and restores
the previous mode on exit."""
modes = [module.training for module in model.modules()]
try:
yield model.train(mode)
finally:
for i, module in enumerate(model.modules()):
module.training = modes[i]
def eval_mode(model):
"""A context manager that places a model into evaluation mode and restores
the previous mode on exit."""View on GitHub (pinned to ae05379cc9)
Solutions
- Delete the cached file at `path` and retry so it is downloaded fresh.
- Verify the remote file actually changed (recompute sha256 of a fresh copy); if it legitimately changed, update the pinned `digest`.
- Check free disk space / network stability if the file is truncated (size much smaller than expected).
- If the URL is dead or redirected, update the url argument along with the digest.
Example fix
# before
download_file('ckpt/vgg16.pth', URL, digest='oldhash...') # OSError: hash failed
# after (re-download then re-pin)
!rm ckpt/vgg16.pth
download_file('ckpt/vgg16.pth', URL) # inspect, then:
digest = hashlib.sha256(open('ckpt/vgg16.pth','rb').read()).hexdigest()
download_file('ckpt/vgg16.pth', URL, digest=digest) Defensive patterns
Strategy: retry
Validate before calling
def sha256_of(path):
h = hashlib.sha256()
with open(path, 'rb') as f:
for chunk in iter(lambda: f.read(1 << 20), b''):
h.update(chunk)
return h.hexdigest()
if path.exists() and digest is not None and sha256_of(path) != digest:
path.unlink() # force clean re-download Try / catch
for attempt in range(3):
try:
p = download_file(path, url, digest=digest)
break
except OSError as e:
if 'failed to validate' not in str(e):
raise
Path(path).unlink(missing_ok=True) # corrupt cache; retry fresh
else:
raise RuntimeError(f'hash validation failed after retries: {path}') Prevention
- On hash failure, delete the cached file and retry the download once.
- Pin digests from a trusted manifest and update them deliberately when upstreams re-release.
- Download to a temp file and atomically rename after hashing to avoid partial-file caches.
When it happens
Trigger: A partial download caused by a dropped connection (the file exists so it is not re-fetched, then fails hashing); a previously downloaded file corrupted on disk; the remote asset at `url` was replaced so the pinned digest no longer matches.
Common situations: Pretrained-weight bootstrap in k-diffusion training scripts; shared caches where another process wrote to the same path; mirrors/CDNs serving different bytes; disk-full truncation during first download.
Related errors
- Order {order} too high for step {i}
- eta must be 0 for reverse sampling
- order should be 2 or 3
- sigma_min and sigma_max must not be 0
- solver_type must be 'heun' or 'midpoint'
AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15).
Data as JSON: /api/errors/935fa91a18f02899.
Report an issue: GitHub.