Skip to content

common : allow concurrent downloads across processes - #29312

Open
angt wants to merge 1 commit into
ggml-org:masterfrom
angt:common-allow-concurrent-downloads-across-processes
Open

angt wants to merge 1 commit into
ggml-org:masterfrom
angt:common-allow-concurrent-downloads-across-processes

Conversation

@angt

@angt angt commented Sep 23, 2026

Copy link
Copy Markdown
Member

Overview

This PR adds cross-process locking to the download path, so multiple processes (including the hf tool) can download the same file without corrupting it.

Additional information

Supersedes #28803

Requirements

@angt
angt requested a review from a team as a code owner September 23, 2026 12:23
Comment thread common/file-lock.h Outdated
Comment on lines +6 to +9
// Cross-process exclusive lock (flock on POSIX, LockFileEx on Windows).
// The constructor only stores the path: acquire() opens the lock file and
// waits out contention, so code that never acquires the lock (pure cache
// reads) works on a read-only cache.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to clean up comments per AGENTS.md

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I literally asked to add some comments and to be verbose (mostly to help the LLM itself) because locking correctly is actually hard. The model often failed without being driven correctly...
But maybe it became too verbose at some points. I'll do a pass

Comment thread common/file-lock.h

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we don't need a new cpp/h file for it, better to just move it to download.cpp as a private struct

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file locking mechanism is generic enough and already used in two places: download and hf-cache (which is why it was moved out of download). Also it could be useful elsewhere, like modelscope, docker or when not downloading at all.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it could be useful elsewhere, like modelscope, docker or when not downloading at all.

other model sources must eventually call download.h to download the actual file, so I think it should still part of the download.h

when not downloading at all.

when not downloading at all, we never need to lock anything because we should never write anything

@angt
angt force-pushed the common-allow-concurrent-downloads-across-processes branch 2 times, most recently from cf7ddeb to 0669e78 Compare September 23, 2026 16:06
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
@angt
angt force-pushed the common-allow-concurrent-downloads-across-processes branch from 0669e78 to 09e13f3 Compare September 23, 2026 16:56

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants