Skip to content

common : allow concurrent downloads across processes - #29312

Merged
ngxson merged 1 commit into
ggml-org:masterfrom
angt:common-allow-concurrent-downloads-across-processes
Oct 23, 2026
Merged

ngxson merged 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 3 times, most recently from 0669e78 to 09e13f3 Compare September 23, 2026 16:56
@ServeurpersoCom

ServeurpersoCom commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

I was about to send a CI fix for the test_router_download_conflicts flake and found the fix is already here: fs_write_atomic from #29642 uses a fixed "<path>.tmp", so the router and the downloading child collide on refs/main, while the unique O_EXCL tmp in this PR's safe_write_file avoids it.

@ngxson ngxson left a comment

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.

sorry forgot to review this, cc @ServeurpersoCom for a final check up before merging

Signed-off-by: Adrien Gallouët <angt@huggingface.co>
@ServeurpersoCom
ServeurpersoCom force-pushed the common-allow-concurrent-downloads-across-processes branch from 09e13f3 to 43d9ef4 Compare October 23, 2026 19:23
@ServeurpersoCom

Copy link
Copy Markdown
Contributor

Rebased

@ServeurpersoCom ServeurpersoCom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tested the router download path and concurrent -hf processes on a shared cache, including a killed winner and the previously flaky test_router_download_conflicts (15/15): all good, LGTM!

@ServeurpersoCom

Copy link
Copy Markdown
Contributor

@ngxson rebased and tested on my side, could you re-approve? The last push is mine so my approve does not cover it.

@angt

angt commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

Thanks @ServeurpersoCom!

@ngxson, we can reorganize better the download/file-lock later?
There is still a lot of refactoring to do anyway.

@ngxson

ngxson commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

yes let's reorganize it later

@ngxson
ngxson merged commit 21ec307 into ggml-org:master Oct 23, 2026
27 of 28 checks passed
auRose94 pushed a commit to auRose94/llama.cpp that referenced this pull request Oct 28, 2026
Signed-off-by: Adrien Gallouët <angt@huggingface.co>
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.

3 participants