Edit files in-place with open modes "e" and "eb" (and enable "a" and "ab" too) - #4752
Draft
lhoestq wants to merge 21 commits into
Draft
Edit files in-place with open modes "e" and "eb" (and enable "a" and "ab" too)#4752lhoestq wants to merge 21 commits into
lhoestq wants to merge 21 commits into
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Collaborator
|
Will have a look at it this week! Sorry for the delay |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
HfFileSystemEditFilewhich is available viahffs.open("hf://buckets/..", "eb")and its methods:edit((start, end), data)insert(loc, data)append(data)delete(loc, length)truncate(size=None)This also enables append mode "a" and "ab".
This only uploads the new data (and neighboring chunks), which enables efficient edits even on big files.
Close #4153
Related to huggingface/huggingface.js#2407
Follows huggingface/xet-core#717
Still in draft mode until huggingface/xet-core#951 is merged, but feel free to review already !
PS: Currently editing a big files still requires downloading ~64MB of data from neighboring chunks to generate verification and range hashes. Hopefully this limitation can be removed soon
Feedback on the mode name
I was thinking of naming it "mutate" for
"m"and"mb"but ended up with "edit" for"e"and"eb"Implementation details
It uses a buffer to keep the edits in memory and send them once the buffer is big enough and enough time has passed. Once ready, the buffer is sent to the Hub in a background thread.
The buffer uses
bytearrayto be able to efficiently support fast small appends.I had to implement
HfApi.edit_bucket_file()which calls hf_xet.Try it yourself
Requires hf_xet from huggingface/xet-core#951 to get the python bindings for
XetSession.new_range_upload()Some examples:
TODO