Fluiddocs
Moves, suspend and resume

Out-of-memory rescue

How Fluid saves a job that runs out of memory, so you can resume it on a larger machine without starting over.

Warnings and limits

  • Fluid rescues an out-of-memory error only when Python raises it inside a loop of your script's own code. An error inside an optimizer step, inside a library's own loop, or outside any loop is not rescued, and the job fails.
  • On Linux CPU machines Fluid caps the program's memory a little under what the machine has (a reserve of 10%, 256 MiB to 1 GiB), so running out raises a Python MemoryError that is rescued like any other, instead of the operating system killing the process; PORTAL_MEMORY_TRIPWIRE=0 in the job's environment turns the cap off. There is no cap on GPU machines: a process the operating system kills there raises no Python error, and Fluid cannot rescue it.
  • The iteration that failed runs again from its start after the resume: its side effects (a file written, a message sent) happen twice.
  • Fluid suspends the job and does not pick the larger machine: you resume it on one.
  • The checkpoint of a suspended job is kept 3 days.
  • A rescue whose checkpoint fails twice in a row for the same reason ends the job, with the capture's own message as the error.
  • A job of several ranks (--ranks) is not rescued where it stands: when a rank runs out of memory the job is suspended on its last checkpoint. See Train on several GPUs.

What counts as out of memory

  • Python's MemoryError;
  • PyTorch's OutOfMemoryError;
  • a RuntimeError that says "CUDA out of memory".

What Fluid does

  1. The error reaches your script's loop. Fluid finds the innermost loop of your own code the error passed through and makes the start of that loop's body, with the same item, the point to continue from. The frames inside it are cleared, so the memory they held (activations, gradients) is free.
  2. Fluid saves a checkpoint of the program at that point and suspends the job. Its machine is released.
  3. You resume it on a machine with more memory, or a larger GPU:
fluid resume JOB --mem 64
fluid resume JOB --gpu A100
fluid resume JOB --on SPEC

The failed iteration runs again, on the new machine, with the same item. The work before it is not done again.

When it cannot rescue

SituationWhy
The error came from inside an optimizer step (torch.optim)the weights may be half updated
The error was raised outside your script's codethere is no point of yours to continue from
No loop of your script was runningthere is no iteration to retry
The process was killed by the operating systemno Python error was raised
The job runs as several ranksthe other ranks wait inside an exchange, where they cannot be saved

In those cases the job fails as it would without Fluid. Set the oom policy off for a job with --policy oom.on=false if you prefer that it always fails at once.

On this page