-
Notifications
You must be signed in to change notification settings - Fork 24.9k
HF component update to not use fsspec components #159405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Update HF components to not inherit from fsspec components and instead use filesystem writer/reader. The reason is because there doesn't seem to be much of a need for fsspec, since users are using mounted storage. Using local storage will allow for performance improvements because we can take advantage of the safe_open API provided by HF safetensors, which is signifcant performance wins over reading bytes and converting to tensors which is what we are doing now. Differential Revision: [D78993550](https://our.internmc.facebook.com/intern/diff/D78993550/) [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/159405
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit d3a9c53 with merge base 93da995 ( UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This pull request was exported from Phabricator. Differential Revision: D78993550 |
) | ||
super().__init__( | ||
path=path, | ||
serialization_format=SerializationFormat.SAFETENSORS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safe open cannot use file like API of fsspec? That is surprising to me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya it requires a path unfortunately and doesn't take the file-like API.
Update HF components to not inherit from fsspec components and instead use filesystem writer/reader. The reason is because there doesn't seem to be much of a need for fsspec, since users are using mounted storage. Using local storage will allow for performance improvements because we can take advantage of the safe_open API provided by HF safetensors, which is signifcant performance wins over reading bytes and converting to tensors which is what we are doing now. Differential Revision: [D78993550](https://our.internmc.facebook.com/intern/diff/D78993550/) cc H-Huang awgu wanchaol fegin fduwjj wz337 wconstab d4l3k pragupta [ghstack-poisoned]
Pull Request resolved: #159405 Update HF components to not inherit from fsspec components and instead use filesystem writer/reader. The reason is because there doesn't seem to be much of a need for fsspec, since users are using mounted storage. Using local storage will allow for performance improvements because we can take advantage of the safe_open API provided by HF safetensors, which is signifcant performance wins over reading bytes and converting to tensors which is what we are doing now. ghstack-source-id: 300108423 @exported-using-ghexport Differential Revision: [D78993550](https://our.internmc.facebook.com/intern/diff/D78993550/)
This pull request was exported from Phabricator. Differential Revision: D78993550 |
Update HF components to not inherit from fsspec components and instead use filesystem writer/reader. The reason is because there doesn't seem to be much of a need for fsspec, since users are using mounted storage. Using local storage will allow for performance improvements because we can take advantage of the safe_open API provided by HF safetensors, which is signifcant performance wins over reading bytes and converting to tensors which is what we are doing now. Differential Revision: [D78993550](https://our.internmc.facebook.com/intern/diff/D78993550/) cc H-Huang awgu wanchaol fegin fduwjj wz337 wconstab d4l3k pragupta [ghstack-poisoned]
Pull Request resolved: #159405 Update HF components to not inherit from fsspec components and instead use filesystem writer/reader. The reason is because there doesn't seem to be much of a need for fsspec, since users are using mounted storage. Using local storage will allow for performance improvements because we can take advantage of the safe_open API provided by HF safetensors, which is signifcant performance wins over reading bytes and converting to tensors which is what we are doing now. ghstack-source-id: 300168979 @exported-using-ghexport Differential Revision: [D78993550](https://our.internmc.facebook.com/intern/diff/D78993550/)
This pull request was exported from Phabricator. Differential Revision: D78993550 |
@@ -52,7 +52,7 @@ | |||
__all__ = ["HuggingFaceStorageWriter", "HuggingFaceStorageReader"] | |||
|
|||
|
|||
class HuggingFaceStorageWriter(FsspecWriter): | |||
class HuggingFaceStorageWriter(FileSystemWriter): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ankitageorge If any user needs the FSSpec based component, they should be able to write a wrapper extending the HuggingFaceStorageWriter. Could you please confirm if thats the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ya if they write a class to inherit from both HuggingFaceStorageWriter and FsspecWriter, then it should work.
@@ -52,7 +52,7 @@ | |||
__all__ = ["HuggingFaceStorageWriter", "HuggingFaceStorageReader"] | |||
|
|||
|
|||
class HuggingFaceStorageWriter(FsspecWriter): | |||
class HuggingFaceStorageWriter(FileSystemWriter): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this be backward compatible? Its a very new feature so probably no major adoption yet but we enabled a few partners to start using the FSSpec component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only usage I could find is torchtune, but considering it's being deprecated I think it is okay. The flow will just go back to users having to download files from HF hub before running, which was the old experience.
Update HF components to not inherit from fsspec components and instead use filesystem writer/reader. The reason is because there doesn't seem to be much of a need for fsspec, since users are using mounted storage. Using local storage will allow for performance improvements because we can take advantage of the safe_open API provided by HF safetensors (30s vs 4s for load of 8b model), which is signifcant performance wins over reading bytes and converting to tensors which is what we are doing now. Also, we can use the official methods provided by HF instead of relying on reading the metadata by bytes and loading it Differential Revision: [D78993550](https://our.internmc.facebook.com/intern/diff/D78993550/) cc H-Huang awgu wanchaol fegin fduwjj wz337 wconstab d4l3k pragupta [ghstack-poisoned]
This pull request was exported from Phabricator. Differential Revision: D78993550 |
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
Starting merge as part of PR stack under #159681 |
Starting merge as part of PR stack under #159406 |
Reading the bytes and converting to tensors is much slower than using safe_open. For a 8B model across 8 ranks, took ~30s to load before this change and ~4s after. Differential Revision: [D78994259](https://our.internmc.facebook.com/intern/diff/D78994259/) Pull Request resolved: #159406 Approved by: https://github.com/saumishr ghstack dependencies: #159405
Get rid of the logic to read the metadata from the header of the safetensors file manually and use the functions as part of safe_open() to get the metadata. This is much cleaner and allows us to not rely on our own custom methods to get metadata, but use safetensors provided APIs Differential Revision: [D79460272](https://our.internmc.facebook.com/intern/diff/D79460272/) Pull Request resolved: #159681 Approved by: https://github.com/saumishr ghstack dependencies: #159405, #159406
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Stack from ghstack (oldest at bottom):
Update HF components to not inherit from fsspec components and instead use filesystem writer/reader. The reason is because there doesn't seem to be much of a need for fsspec, since users are using mounted storage. Using local storage will allow for performance improvements because we can take advantage of the safe_open API provided by HF safetensors (30s vs 4s for load of 8b model), which is signifcant performance wins over reading bytes and converting to tensors which is what we are doing now. Also, we can use the official methods provided by HF instead of relying on reading the metadata by bytes and loading it
Differential Revision: D78993550
cc @H-Huang @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @pragupta