ultralytics/ultralytics · critical · MemoryError
Insufficient free disk space {fmt_bytes(free)} < {fmt_bytes(
Error message
Insufficient free disk space {fmt_bytes(free)} < {fmt_bytes(int(file_bytes * sf))} required, Please free {fmt_bytes(int(file_bytes * sf - free))} additional disk space and try again. What it means
Raised by check_disk_space() (ultralytics/utils/downloads.py) when free space on the target filesystem is below file_bytes * sf (sf defaults to 1.5, a 50% safety margin) and hard=True. It raises MemoryError — chosen deliberately so download retries do not swallow it (safe_download re-raises MemoryError immediately). The message quantifies free vs required bytes and the shortfall.
Source
Thrown at ultralytics/utils/downloads.py:249
"""
total, _used, free = shutil.disk_usage(path or Path.cwd()) # bytes
# A filesystem that cannot report usage returns 0 total blocks; free == 0 against a valid total is genuinely
# full and must still be caught, since `free` counts blocks available to an unprivileged process.
if not total or file_bytes * sf < free:
return True # sufficient space
def fmt_bytes(b):
if b < (1 << 20): # without a KB tier every value under 51 KB renders "0.0 MB", hiding how full the disk is
return f"{b / (1 << 10):.1f} KB"
return f"{b / (1 << 20):.1f} MB" if b < (1 << 30) else f"{b / (1 << 30):.3f} GB"
# Insufficient space
text = (
f"Insufficient free disk space {fmt_bytes(free)} < {fmt_bytes(int(file_bytes * sf))} required, "
f"Please free {fmt_bytes(int(file_bytes * sf - free))} additional disk space and try again."
)
if hard:
raise MemoryError(text)
LOGGER.warning(text)
return False
def get_google_drive_file_info(link: str) -> tuple[str, str | None]:
"""Retrieve the direct download link and filename for a shareable Google Drive file link.
Args:
link (str): The shareable link of the Google Drive file.
Returns:
url (str): Direct download URL for the Google Drive file.
filename (str | None): Original filename of the Google Drive file. If filename extraction fails, returns None.
Examples:
>>> from ultralytics.utils.downloads import get_google_drive_file_info
>>> link = "https://drive.google.com/file/d/1cqT-cJgANNrhIHCrEufUYhQ4RqiWG_lJ/view?usp=drive_link"
>>> url, filename = get_google_drive_file_info(link)View on GitHub (pinned to 0449ea011c)
Solutions
- Free at least the shortfall stated in the message (it includes the 1.5x margin)
- Point download_dir / output paths at a larger volume and retry
- Prune caches: docker system prune, pip cache purge, remove old runs/datasets
- If you control the call, use hard=False to get a warning + False return instead
Example fix
# before
safe_download(url='https://.../coco.zip', file='coco.zip') # MemoryError on full disk
# after
from ultralytics.utils.downloads import check_disk_space
if not check_disk_space('https://.../coco.zip', '/data', sf=1.5):
raise SystemExit('insufficient disk, freeing space before download')
safe_download(url='https://.../coco.zip', file='/data/coco.zip') Defensive patterns
Strategy: validation
Validate before calling
from ultralytics.utils.downloads import check_disk_space
if not check_disk_space(url='https://example.com/big.zip', path=Path('/data'), sf=1.5):
raise SystemExit('free disk space before downloading (need file size x1.5)') Try / catch
try:
safe_download(url=url, file=f)
except MemoryError as e:
raise SystemExit(f'out of disk: {e} — free space or change download dir') from e Prevention
- Pre-check free space (>=1.5x expected payload) before large downloads
- Point caches/downloads at large volumes, not container overlay or /tmp tmpfs
- Prune old runs and datasets periodically in automation
When it happens
Trigger: Downloading large weights or datasets (e.g. COCO) to a nearly full disk or small tmpfs/容器 volume; exporting to a constrained workspace; setting hard=True when calling check_disk_space yourself.
Common situations: Docker containers with small writable layers; CI runners with low free disk; /tmp tmpfs limits; long-lived workstations where datasets accumulated.
Related errors
- '{k}={v}' is of invalid type {type(v).__name__}. Valid '{k}'
- Downloaded {success_count}/{len(image_records)} images from
- 'source=0' webcam not supported in Colab and Kaggle notebook
- Dataset '{name}' images not found, missing path '{next(x for
- Multi-XPU training requires XCCL, which is not available in
AI-assisted analysis of ultralytics/ultralytics@0449ea011c (2026-08-15).
Data as JSON: /api/errors/1b81210154b4e89d.
Report an issue: GitHub.