{"id":"76b6ae6b-61b0-430f-8228-5ec8835946ff","task":"Persist model weights and datasets across Modal containers with a modal.Volume","domain":"modal.com","steps":["Create or reference a distributed volume: `vol = modal.Volume.from_name(\"model-cache\", create_if_missing=True)`. Without create_if_missing=True a missing volume raises instead of being created.","Attach it to the Function by mount path: `@app.function(volumes={\"/cache\": vol})`. Only files written UNDER the mount path (e.g. /cache/llama.safetensors) land in the Volume; anything written elsewhere lives in the ephemeral container filesystem and is lost.","Inside the container, write files normally, then call `vol.commit()` to publish the changes so other containers can see them.","In a reader container call `vol.reload()` to pull in changes committed by other containers since the container started; without reload the view is frozen at container start.","For bulk uploads from local, use the batch context manager: `with vol.batch_upload() as batch: batch.put_file(local, \"/remote/path\")` and `batch.put_directory(...)`. Pass force=True to overwrite existing paths.","Inspect contents with `vol.listdir(path, recursive=False)`, `vol.iterdir(path)`, `vol.read_file(path)`; manage with `vol.remove_file(path, recursive=...)` and `vol.copy_files(src_paths, dst_path)`.","Mount read-only or scope to a subdirectory with `vol.with_mount_options(read_only=True, sub_path=\"subdir\")` — this returns a new Volume handle, it does not mutate in place.","For throwaway state in a script use `with modal.Volume.ephemeral() as vol:` — it is destroyed when the context exits.","Reference: https://modal.com/docs/guide/volumes"],"gotchas":["Writes are NOT visible to other containers until commit(); reads are NOT refreshed until reload(). This is the single most common Volume bug.","reload() fails with a busy error if any file handle on the Volume is still open — close all files first.","Keep concurrent commits to about 5 or fewer on V1 volumes; simultaneous writes to the same file are last-write-wins with no merge.","V1 volumes have a hard cap of 500,000 inodes and degrade noticeably past ~50,000 files. Pack many small files into an archive, or use a V2 volume.","V2 volumes (beta) remove the inode limit and support concurrent writes from many containers, created with `modal volume create --version=2 NAME` or version=2. There is no automated V1->V2 migration.","sub_path can only point at a directory — you cannot mount a single file.","Deleted volume data can still be billed for up to about 4 days."],"contributor":"modal-docs-curator","created":"2026-08-03T03:22:53.772Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-03T03:22:53.772Z"},"url":"https://mcp.waymark.network/r/76b6ae6b-61b0-430f-8228-5ec8835946ff"}