Spot interruptions and checkpoints
What Fluid does when a provider takes a machine back, what a checkpoint holds, and what it cannot carry.
Warnings and limits
- Notice before a machine is taken: AWS spot 2 minutes, AWS Fargate Spot 2 minutes, Google Cloud spot 120 s (25 s when Google refuses the longer notice), Azure spot VMs 20 s (the event names a time 22 to 27 s out, and Fluid's daemon sees it within a second), Modal GPU sandboxes 5 s. Azure Container Apps, Lambda, on-demand machines and your own machines give none: a Container Apps stop ends the replica at once, and progress since the job's last checkpoint is lost.
- A checkpoint must be paused, saved and uploaded inside the notice. A program that cannot pause in time (one long native call, a large state on a short notice) can lose its work.
- Fluid warns you when a single-machine job's state is too large for its spot offer to save within the notice. A brand-new job is placed on spot with that warning. Once its state has been measured (while it runs, or from its checkpoint when it is suspended), a spot offer whose notice cannot save it is left out of its later placements, and a job running on spot whose state grows past what its notice can save is moved to an on-demand machine (the
spot.move_when_overpolicy, on by default). A job pinned to an exact spot machine is warned, not moved. - Fluid checks at a job's first pause point, and every 10 minutes after, whether a checkpoint could carry its state (the checkpoint check, setting
capture_probe). A job that holds something a checkpoint cannot carry gets a warning naming it: Fluid cannot move or suspend such a job, and cannot save it on a notice, so its work since the last checkpoint is at risk until the script is changed. The check cannot fix this for you. - On a Spot notice, a single-machine job that saves its checkpoint waits for you to resume it. A Google Cloud G2 Spot group can move all ranks together during the notice. See G2 Spot groups.
- A suspended job's checkpoint is kept 3 days. Fluid warns 18 hours before it expires; after that the job fails with "the checkpoint expired".
- A checkpoint cannot carry an open file outside the working directory, a socket in use, a thread, another process, a file outside the working directory, or a native object such as a numba
jitclassinstance,cfuncorstencil. A move or suspension you ask for is refused when the job holds one, with the value's name, and the job stays where it is; a spot checkpoint fails. An in-memoryStringIOorBytesIO, and a closed socket, move. - A pause waits for a pause point. A long native call, a running thread, an open file outside the working directory, a child process,
os.walk, afinallyblock, asyncio or a comprehension in progress keeps the program from pausing until it ends, so does a library call that is working on a file outside the working directory (a download, a model being read from the library's cache), and a function numba compiled is one native call; the job's events say why (pause). A spot checkpoint that cannot pause inside the notice loses the work since the last checkpoint. - Without a region, Modal places a sandbox anywhere, so a move of a large state can pause longer than between two machines in one region.
What happens on a notice
For a single-machine job with the Spot policy enabled, Fluid takes these steps.
- The provider tells the machine it will be taken. Fluid's daemon on the machine sees the notice and reports it at once.
- Fluid asks your program to pause at its next safe point: a point between statements, in your script's own code, where its state can be saved. It keeps the last minute of the notice for saving and uploading.
- The program's state is saved as a checkpoint and uploaded to storage, encrypted with a key of the job's own.
- The machine is released and the job is
suspended. The pool that reclaimed it is left out of new placements for 30 minutes. - You resume the job when you choose, on a machine you choose:
fluid resume JOB
fluid resume JOB --gpu L4
fluid resume JOB --on SPECIt continues from the statement after the safe point. No completed work is done again.
If the daemon loses contact with Fluid during a notice, it saves the checkpoint on its own. A job is called lost only when its state is gone for certain: a provider that once says the machine is gone, or a store that cannot be read for a moment, does not end it. While its daemon does not answer, the job keeps its state with the time its daemon was last heard, and each event says what Fluid waits for: a provider that says the machine is gone must say so again at the next check, about a minute later, with the daemon still silent, and the loss is declared no sooner than 10 minutes of silence (2 minutes past a notice's deadline). A suspend or move asked meanwhile is refused with the same words, never with "the job goes on". An Azure VM's bill ends when Azure's records say it evicted or deleted the VM, not when Fluid declares the loss, and so does a checkpoint the eviction cut short; a checkpoint that is incomplete is said to be not resumable and is kept for inspection.
G2 Spot groups
With the Spot policy enabled, a preemption notice on any machine in a Google Cloud g2-standard-96 (L4) Spot group triggers one attempt to move the whole job. Fluid requests the same number of replacement Spot machines on the pinned connection and in the same zone. The earliest notice deadline among the source machines limits the attempt.
All ranks must pause at the same collective boundary. Fluid checkpoints every rank, restores each machine's assigned ranks on its replacement, and compares the restored state fingerprints with the checkpoint. Only then can it commit the move and let the replacement group continue. If the move fails or the deadline passes before that commit, the job fails and Fluid releases the source machines and any replacements. The failed job has no suspended checkpoint for fluid resume. See Train across machines.
What a checkpoint holds
- objects reachable from your script's globals and from the locals of each paused function, with shared references kept;
- tensors and arrays, put back on a GPU when the new machine has one. An array and a tensor that share memory (
torch.from_numpy,tensor.numpy()) still share it on the new machine: what you write through one, the other reads; - memory maps. A
numpy.memmapover a file in the working directory is opened over that file again on the new machine, read-only or written through as before, and so is a tensor fromtorch.from_file(shared=True). A read-only map over a file anywhere else arrives in memory. One your program can write, over a file outside the working directory, is refused with its variable's name: keep the file in the working directory; - functions and classes your program defined, a numba-compiled one as its Python function, compiled again on the new machine, where it reads the globals it uses as they are then (numba froze them when it compiled the function, at its first call or at the decorator for one given a signature: a global a kernel reads must not change after that);
- hooks your program registered on its tensors (
register_hook,register_post_accumulate_grad_hook), on its modules and on its optimizers, and the ones it registered with torch for every module or every optimizer (register_module_forward_hook,register_optimizer_step_post_hookand their like). They are registered again on the new machine, in the same order. A hook that holds something a checkpoint cannot carry is named by the checkpoint check, like any other value; - loop positions: iterators, DataLoader positions and tqdm bars. A loop part way through a set or a dict goes on over the members it had left, each once;
- how strings hash: every process of a job starts with the same hash seed (see Run a job), so
hash("name")gives the same number before and after a move; - random number generators (Python, NumPy, torch) and torch's numeric settings;
- interpreter settings your program changed: logging, warnings filters, print options, the decimal context, signal handlers;
- files of the working directory that your program has open: a log you append to, an output file, a file you read. Each is opened again where the job lands, in the same mode and at the same place, and never emptied. Fluid flushes what you wrote before it packs the working directory. A zip archive open for reading and an SQLite connection to a database in the working directory travel too, the connection once its transaction is committed. See Open files for what does not;
- the current directory,
sys.path, environment variable changes, and the files in the working directory. A pause waits while your program is in a directory outside the working directory (afteros.chdir): only the working directory travels, so return to it before the next pause point. A checkpoint never holds the value of a stored secret or of a variable with a credential's name such asHF_TOKEN: the new machine starts your program with the job's--envvariables and its secrets again.
Fluid compares content fingerprints before the destination takes over. For a single-machine move, it keeps a checkpoint whose restored fingerprint differs for diagnosis.
Open files
A file your program has open travels when it is a regular file under the working directory, opened with open().
- It comes back where you stood in it. Same name, same mode, same position. A file opened with
"w"is not emptied again, and nothing is created: if the file is missing where the job lands, the move is refused and the job stays where it is. - Text files keep their encoding and the way they treat line ends. One exception: inside
for line in f:over a text file Python cannot say the position, so a pause waits for that loop to end. Read withreadline(), or open the file in binary, to pause inside. with open(...) as f:does not hold a pause.- Not carried, and a pause waits while you hold one: a file outside the working directory, a file under a name the working directory leaves behind (such as
.cache), a pipe, a socket, a terminal or a device, a file that was deleted or replaced after you opened it, a file you hold a lock on, a temporary file, a memory map, a compressed file (gzip.open). A binary file you are reading also waits while bytes just ahead of your position were overwritten after Python buffered them, until you have read past them. - A buffered file's buffer size is the default where the job lands.
SQLite:
- A connection made with
sqlite3.connectto a database file under the working directory is opened again where the job lands, read-only if it was, with its row factory, isolation level and settings such asPRAGMA foreign_keys. - A pause waits while a transaction is open. Commit or roll back and it goes on.
- Not carried: a database in memory, a database file under a name the working directory leaves behind (such as
.cache), an attached database, temporary tables, a connection with a function, a collation or a callback registered on it, or one made by a library's own wrapper.total_changescounts from the reopening.
What a checkpoint cannot carry
- the process itself: open files outside the working directory or that are no regular file (a pipe, a device), sockets, locks, pipes, shared memory, other threads and processes, network requests in flight, and native objects such as a numba
jitclassinstance,cfuncorstencil. A pause waits while your program holds one of them in a global or a paused local. When a checkpoint finds one only after the pause was taken, and one function alone holds it (an evaluation that builds its own environments), Fluid lets the job run on and takes the checkpoint once that function has returned, for up to 15 seconds; the move's event then says where the first try failed.--env PORTAL_CAPTURE_LATER_S=0turns that off, and another number is the seconds it waits; - a native call in progress: one long C, CUDA or Rust call, a function numba compiled, or a library's own loop, runs to its end before the program can pause;
- files outside the working directory, and installed packages (the new machine installs your requirements again);
- a generator expression, coroutine or comprehension partway through, or code inside an
exceptorfinallyblock; - an exception's traceback;
- a change your program makes to one of its own modules after importing it: a function of
helpers.pyreplaced from the script (helpers.load = my_load), or a method of one of its classes replaced. The new machine imports the module from its file again, where the change is not. The checkpoint is refused with the module's name, and the job goes on where it is. Make the change in the module's own file. A method that a library or your program adds to a class travels when it is a plain function; - the order in which a set or a frozenset gives its members. A set is made again from its members on the new machine and can give them in another order than before, with the same hash seed too. Every member arrives once and a dict keeps its order. When the order matters, sort before iterating:
for name in sorted(names).
When a move leaves something of your program's behind without failing (an environment variable your program set or changed itself whose name looks like a credential's, a file the working directory does not carry, the state of a GPU's random generator on a machine without one), the job's "moved to" or "resumed on" event ends with "not carried:" and names what it was. The variables you gave with --env and your stored secrets are given again to every machine the job runs on, so they are not named there.
Imports run again on the new machine: their side effects outside your program's state (a network call, a file written outside the working directory) happen twice, and a warning a library raises while it is imported is raised again there. Results on a different GPU model can differ in the last bits.
Where a checkpoint can be restored
A single-machine checkpoint can be restored on a different provider, in a different region, on another machine type or GPU model. An explicit multi-node live move restores the same rank and node counts on a destination group. Supported groups use on-demand AWS EC2 GPU machines or GCE machines of one type, g2-standard-96 (L4), a2-highgpu-8g (40 GB A100) or a2-ultragpu-8g (80 GB A100). Every checkpoint depends on what your program had loaded when it was taken. Fluid checks the conditions below before the new machine takes over.
If the destination fails a restore check during a move you requested, the job keeps running on the source. A suspended job keeps its checkpoint for a machine that fits. During a G2 Spot interruption, a failed restore ends the group as described above.
| The new machine needs | Why | If it does not |
|---|---|---|
| The Python version the job ran on (3.12 for a 3.12 job) | Objects are rebuilt by Python's own code | Refused: capsule needs Python 3.12, this is 3.11. Fluid builds the job's environment itself, so this holds on every machine it starts. |
| The same versions of the libraries the program's state uses | A model, an optimizer or a dataset is rebuilt by its library's code | Refused: module dependency mismatch names the library and both versions. Fluid installs your requirements again from the job's lock, so they match unless the lock could not be met there. |
| The same PyTorch version. Its CPU and CUDA builds count as the same | A pause inside a library continues in that library's code, found again by name and content | A job moves between a CPU machine and a GPU machine, and between CUDA versions, of one PyTorch version. Another PyTorch version is refused. |
| A GPU, for a job whose tensors are on one, with room for them | Tensors go back on a GPU | A move to a CPU machine is refused when you ask for it. A smaller GPU is checked against the most memory PyTorch reserved, plus 10%. A different GPU model is allowed, and results can differ in the last bits. |
| Enough GPUs per machine for the local ranks | Each GPU rank keeps its own device | Refused. The number of nodes and ranks stays fixed. |
| Your project's code as it was | Functions and classes are compared with the ones that were paused | The working directory travels in the checkpoint, so this holds. A file of your project changed on the new machine by something else is refused: module identity mismatch. |
What a checkpoint does not bring to the new machine, and what happens then:
- Files outside the working directory. A library's downloads (models, datasets, tokenizers under
~/.cache) are fetched again when the program asks for them, which costs time and needs the network. To have a job's Hugging Face Hub files fetched before it goes on, so a later load does not depend on the Hub answering then, see a script that asks the Hub again after a move. A file your own script wrote outside the working directory, such as a checkpoint saved to/tmpor to your home directory, is not on the new machine: reading it there fails. Keep every file your program reads again inside the working directory. - What is brought anyway. The rows of a Hugging Face dataset (its Arrow files travel in the checkpoint). Code a library fetched and loaded, such as an
evaluatemetric or a model'strust_remote_codefiles, up to 512 KB a file and 8 MB in all; past that the new machine must have the same files, or the restore is refused. Empty directories outside the working directory that your program's objects hold the path of are made again. NLTK data in your home directory is downloaded again before the job goes on; if it cannot be downloaded there, the restore is refused. - A file lock that is held, an open file outside the working directory, a thread, a child process. A pause waits until the program lets go of it. See What a checkpoint cannot carry.
- A call that cannot be paused in. One long native call, or a library the frameworks list marks
waits, runs to its end before the job can pause. A job of one process takes no checkpoints while it runs (a job of several ranks does, see Several GPUs), so a spot notice that arrives during such a call, and is shorter than what is left of it, loses the work since the job started or last landed. Run such a job on an on-demand machine.
A refused restore says which condition failed, in the job's events. What a move left behind that Fluid knows of is named at the end of the "moved to" or "resumed on" event ("not carried:"), and the job's pause events name what a pause waits for. One thing is not listed there: files your script wrote outside the working directory. Fluid does not watch what a program writes, so it cannot name them.
Long notices, short notices
A checkpoint takes the time to reach a safe point plus the time to save and upload the state. On AWS's 2 minutes that is enough for most jobs. On a notice of 30 s or less (Google Cloud's 25 s fallback, Azure spot VMs' 20 s), a large state may not make it: prefer on-demand machines for such jobs, or keep the state small. The plan warns when a spot offer's notice cannot save the job's state. fluid explain JOB shows what happened at each notice.
The checkpoint check
A notice is the worst moment to learn that a checkpoint is impossible. So at a job's first pause point, and then every 10 minutes (the setting capture_probe_every_min), Fluid's daemon walks the job's live state the way a checkpoint would, without saving anything, and reports what a checkpoint could not carry. The script pauses for the walk (5 seconds in all; a larger state is reported as partially checked) and goes on. The check never holds up a notice or a move: a pause asked for while it runs stops it at once and is taken at the same pause point, within a fraction of a second.
What you see:
fluid runandfluid logs -fprint the warning as a note when it appears; the console's run page shows it as a banner, and the Overview line "Checkpoint check" says when the last check passed;fluid status JOBand the MCP'sstatus(job)carry it ascarry(ok,problems,blocked,warning);fluid explain JOBlists it as awarndecision (policyspoton a spot machine,checkpointelsewhere).- A problem names the value as your script knows it, its type and why:
A checkpoint of this job cannot carry digest (_hashlib.HASH: TypeError: cannot pickle '_hashlib.HASH' object). Fluid cannot move or suspend it while it holds them, and it cannot be saved on a notice. If this spot machine is reclaimed (its notice is 120 s), its work since the last checkpoint would be lost. Create them again after a pause point instead of keeping them across one (checked at train.py:42 in train).One warning per machine and problem; an all-clear event follows once a later check passes. - A script that passes no pause point for 30 seconds (a socket or a running thread held in a global, one long native call) is reported as blocked, with the reasons the pause points gave.
What the check does not do: it never moves or suspends the job for this, because a job that holds such a value cannot be moved or suspended at all. The fix is in the script: create the object after a pause point instead of keeping it across one, close files and sockets when they are not in use, or hold them inside a with block that ends before the next loop iteration.
Settings: capture_probe is on by default. full also rehearses a real checkpoint on the machine's disk (deleted after) and reports its size and the time it took, which is the most faithful test of a job's checkpoint; it costs that time and disk at every check, so use it to try a job out rather than for every run. The rehearsal runs on on-demand machines only: a real checkpoint cannot be cut short, so on a spot machine (or one whose purchase model the daemon was not told) the check runs without it, and the plan and the job's events say so. off skips the check. A job's own environment variable PORTAL_CAPTURE_PROBE overrides the setting for that job, and PORTAL_CAPTURE_PROBE_EVERY_S its interval.
Limits of the check: a script that stops its own child process only when a real pause is wanted (portal.runtime.rt.pending()) looks blocked to the check while that child runs, since the check wants no pause; a value whose pickling has side effects runs them at every check, as it would at every move.
State size and spot
For single-machine jobs, what a Spot machine can save within its notice is a bound Fluid measured per provider, machine class and storage route (R x (notice - t0) x 0.5; the plan's notice field and the sentence under each spot offer say it). A brand-new job is placed on spot with a warning when the memory it asks for is above that bound, because what it asks for is a guess. Once Fluid has measured the job's state, the measure decides:
- The bound depends on the machine's size. Fluid takes a named type's vCPUs from its own catalog, else from the provider's listing of the type (EC2's instance types, Azure's SKUs, Lambda's instance types); a size Fluid cannot look up is sized as its default class, and the offer's note and the plan say so.
- The state's size is a measure with a name. Fluid takes a checkpoint's bytes when it has them (a suspended job's checkpoint as stored, the check's rehearsal, the last move's capsule, each with a tenth added for growth since); otherwise the memory the daemon reports (resident and GPU memory), which overstates a checkpoint, so that figure must be a quarter over the bound before Fluid moves on it alone. Every warning, plan line and event says which figure it used ("its checkpoint as stored", "its resident and GPU memory now", "what it asked for").
- A resume, a move, and the cheaper and return policies leave out every spot offer whose notice cannot save that state. The job's events say
spot aws c7i.large (us-east-1) skipped: this job's state (12.0 GB, its checkpoint as stored) exceeds what its 120 s notice can save (about 7.9 GB), and a plan (fluid move JOB --plan) sayswould not use spot ...under the D6 line. An exact--onis your choice and is kept, with the warning. - A job running on spot whose measured state grows past what its notice can save is moved to the cheapest on-demand machine that fits: the spot policy provisions it ahead and moves the job once it is ready (
fluid explain JOB:provisionthenmoveunderspot, the event naming the figure, what it is and the notice's bound). The measure is taken again at every check, so a job that grows after its first warning is caught. Turn this off withspot.move_when_over: false; a job pinned to an exact spot machine is warned and left where it is. - A job that asks for spot only and finds no spot offer that can save its state stays suspended; its event names the way out: resume it with
--onan exact machine, spot or on-demand (fluid resume JOB --on SPEC).fluid prices --no-spotlists on-demand offers with their specs.