lllyasviel/Fooocus · error · ValueError
{str(e)} File corrupted: {path} Fooocus has tried to move t
Error message
{str(e)}
File corrupted: {path}
Fooocus has tried to move the corrupted file to {path}.corrupted
You may try again now and Fooocus will download models again.
What it means
This ValueError is raised by Fooocus's build_loaded() wrapper (modules/patch.py:454-485), which monkey-patches checkpoint/VAE/LoRA loader functions in ldm_patched. When the underlying loader (e.g. torch.load / safetensors loading) throws any exception, the wrapper assumes the model file on disk is corrupted: it iterates the loader's string args/kwargs, renames every existing file to '<path>.corrupted' (removing a previous .corrupted backup first), and re-raises a ValueError whose text is the original exception plus 'File corrupted: <path>' and instructions to retry so Fooocus re-downloads the model. Important: the corruption diagnosis is a heuristic — ANY loader failure (not just a bad file) triggers the rename, so genuine non-corruption errors (CUDA OOM, unsupported file version, missing dependency) can also quarantine a healthy model file.
Source
Thrown at modules/patch.py:481
result = None
try:
result = original_loader(*args, **kwargs)
except Exception as e:
result = None
exp = str(e) + '\n'
for path in list(args) + list(kwargs.values()):
if isinstance(path, str):
if os.path.exists(path):
exp += f'File corrupted: {path} \n'
corrupted_backup_file = path + '.corrupted'
if os.path.exists(corrupted_backup_file):
os.remove(corrupted_backup_file)
os.replace(path, corrupted_backup_file)
if os.path.exists(path):
os.remove(path)
exp += f'Fooocus has tried to move the corrupted file to {corrupted_backup_file} \n'
exp += f'You may try again now and Fooocus will download models again. \n'
raise ValueError(exp)
return result
setattr(module, loader_name, loader)
return
def patch_all():
if ldm_patched.modules.model_management.directml_enabled:
ldm_patched.modules.model_management.lowvram_available = True
ldm_patched.modules.model_management.OOM_EXCEPTION = Exception
patch_all_precision()
patch_all_clip()
if not hasattr(ldm_patched.modules.model_management, 'load_models_gpu_origin'):
ldm_patched.modules.model_management.load_models_gpu_origin = ldm_patched.modules.model_management.load_models_gpu
ldm_patched.modules.model_management.load_models_gpu = patched_load_models_gpuView on GitHub (pinned to ae05379cc9)
Solutions
- Check the first line of the error message (the original exception, str(e)) — it names the true cause. If it is a download/unpickling/deserialization error, the file really is bad; if it is CUDA OOM or an AttributeError, the file is fine and you should restore it from the .corrupted backup.
- If the file was legit: restore it with `mv <path>.corrupted <path>` (or just let Fooocus re-download it by clicking Generate again), then fix the actual root cause (free VRAM, fix disk space, update torch) before retrying.
- If the file really is corrupt (common with blocked/redirected HuggingFace downloads): delete the .corrupted file, re-download the model manually (e.g. `huggingface-cli download` or a browser) into models/checkpoints (or models/vae, models/loras), verifying the file size matches the hub's reported size.
- Verify integrity before retry loops: compare file sizes/SHA256 against the HuggingFace repo metadata; a mismatch of a few KB vs several GB means a truncated transfer.
- If a healthy model keeps getting quarantined by an unrelated loader bug on every launch, temporarily rename the file back and patch/report the underlying exception instead of letting the wrapper loop-delete your models.
Example fix
# before: model keeps failing to load and Fooocus quarantines it
# (models/checkpoints/my_model.safetensors -> my_model.safetensors.corrupted)
# after: verify integrity and restore or re-download
import os, hashlib
path = 'models/checkpoints/my_model.safetensors'
if os.path.exists(path + '.corrupted'):
size = os.path.getsize(path + '.corrupted')
print('quarantined size:', size) # compare with HF repo size
if size > 1_000_000: # plausible full file -> restore
os.replace(path + '.corrupted', path)
else: # truncated/redirect page -> fetch again
from huggingface_hub import hf_hub_download
hf_hub_download('stabilityai/stable-diffusion-xl-base-1.0',
'sd_xl_base_1.0.safetensors', local_dir='models/checkpoints') Defensive patterns
Strategy: try-catch
Validate before calling
# Pre-flight check before pointing the pipeline at a model file
import os
def model_file_looks_valid(path, min_bytes=100_000_000):
if not os.path.exists(path):
return False, 'missing'
if path.endswith('.corrupted') or os.path.exists(path + '.corrupted'):
return False, 'previously quarantined by Fooocus'
size = os.path.getsize(path)
if size < min_bytes: # redirect pages / partial downloads are tiny
return False, f'suspicious size {size}'
with open(path, 'rb') as f:
magic = f.read(8)
if path.endswith('.safetensors') and magic[:3] not in (b'[{"', b'[ {'):
return False, 'not a safetensors container (likely HTML error page)'
return True, 'ok' Try / catch
from modules.patch import patch_all # loading happens after patch_all()
try:
# any generation / model load that can hit the quarantining loader
task = worker(*args)
except ValueError as e:
msg = str(e)
if 'File corrupted:' in msg:
original = msg.splitlines()[0] # the REAL underlying exception
if 'out of memory' in original.lower():
restore_quarantined_files(msg) # file is fine; fix VRAM instead
raise RuntimeError('OOM misreported as corruption: ' + original)
else:
# genuinely bad file: let Fooocus re-download, or fetch manually
log_quarantined_paths(msg)
else:
raise Prevention
- Download models with huggingface-cli or a resumable client and verify size/SHA256 against the hub before adding them to models/checkpoints.
- Watch the first line of the wrapped message — it is the original loader exception; treat 'File corrupted' lines as the wrapper's guess, not ground truth.
- Keep a backup of rare/community checkpoints: the wrapper renames them to .corrupted and a re-download may be impossible if the source is gone.
- Ensure enough free disk space before first launch so initial model downloads cannot be truncated.
- If you run a custom loader patch inside ldm_patched, remember ANY exception it raises will quarantine the model file it was given.
When it happens
Trigger: Calling any patched loader with a file path where loading fails: loading a truncated safetensors/checkpoint (interrupted download, disk filled mid-download), a file that is actually an HTML error page saved with a .safetensors/.ckpt name (mirror redirect), a model whose pickle/safetensors format the installed torch cannot deserialize, or any other exception thrown inside ldm_patched.modules.checkpoint.load_checkpoint / VAE / LoRA load paths. Concretely: the user selects a base model or VAE in the Fooocus UI and generation starts -> build_loaded's loader() catches the original_loader exception -> renames e.g. models/checkpoints/foo.safetensors to foo.safetensors.corrupted -> raises this ValueError.
Common situations: Interrupted or proxied downloads in regions where HuggingFace is blocked (file is a redirect page or partial), disk-full during initial model download, an older .ckpt pickled with a torch version incompatible with the runtime, a healthy file being quarantined because the real failure was an OOM or a code bug inside the loader, and moving/copying model files between machines with a filesystem that truncated them.
Related errors
- Unsupported blend mode: {mode}
- hash of {path} (url: {url}) failed to validate
- invalid style model {}
- ERROR: Could not detect model type of: {}
- error invalid scheduler
AI-assisted analysis of lllyasviel/Fooocus@ae05379cc9 (2026-08-15).
Data as JSON: /api/errors/1fe6ada0a0715dfb.
Report an issue: GitHub.