-
Notifications
You must be signed in to change notification settings - Fork 51
wasm poc #272
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
wasm poc #272
Conversation
This PR makes the cas_client crate compile into WASM (at least with wasm-pack). It separates out download & upload traits and functions when necessary to then target_family block the downloads path (easy way out). There's other generally necessary changes particularly having to do with async_trait that are added. --------- Co-authored-by: seanses <[email protected]>
Adds a CI build test on hf_xet_wasm.
rajatarya
left a comment
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.
(Partially completed, will continue with latest.)
cas_client/src/http_client.rs
Outdated
|
|
||
| /// Builds authenticated HTTP Client to talk to CAS. | ||
| /// Includes retry middleware with exponential backoff. | ||
| #[allow(unused_variables)] |
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.
What is considered unused? Can this warning be removed?
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.
I'll remove these. It only gives this error when linting in webassembly where the retry config arg is not used.
rajatarya
left a comment
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.
Overall this is great, thank you @seanses and @assafvayner for putting this together!
The vast majority of my comments are asking for more documentation/comments/explanation. It will be hard for future you or anyone new to the repo to remember the context under which all the WASM changes were made, and that makes maintaining them without documentation risky. The more comments now the better.
I think with ~60m of effort to add comments to this PR it will be ready to merge.
Again, great work on this - really appreciate the effort.
| pub struct SessionMiddleware(String); | ||
|
|
||
| #[async_trait::async_trait] | ||
| #[cfg_attr(not(target_family = "wasm"), async_trait::async_trait)] |
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.
A comment explaining the compilation flag changes would be helpful here - they both look so similiar but I imagine have very different behaviors.
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.
this is explained in hf_xet_wasm README.md; there's too many occurrences in other places to state it everywhere.
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.
My main concern is that the wasm crate isn't something most xet-core maintainers will need to read/understand. So it might make sense to repeat or reference the message in wasm readme in a comment, something like: "# see hf_xet_wasm README.md for context
| # hf_xet_wasm: xet-core for WebAssembly | ||
|
|
||
| This crate enables functionality to use the xet upload protocol from the browser with the use of a wasm based binary replicating the functionality of the `hf_xet` python library. | ||
| Functionality included but not limited to chunking, global deduplication, xorb formation, xorb upload, shard formation, shard upload. |
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.
I would rephrase this to be explicit about what is included and what is missing - so future maintainers can understand what to expect from the rest of the repo. Something like:
hf_xet_wasm has: chunking, global deduplication, xorb formation, xorb upload, shard formation, shard upload
hf_xet_wasm is missing: complete download support (xorbs, shards, chunk caching)
|
|
||
| pub async fn finalize(self: Arc<Self>) -> Result<()> { | ||
| // Register the remaining xorbs for upload. | ||
| let data_agg = take(&mut *self.current_session_data.lock().await); |
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.
How is take() different from just self.current_session_data.lock().await;? In other places in this impl the lock is received with a .lock().await - how come this code does a take() on top of that?
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.
https://doc.rust-lang.org/std/mem/fn.take.html
take replaces the value being referenced with a default, more importantly moving out the value referenced to use in the current scope.
hf_xet_wasm/src/wasm_timer.rs
Outdated
|
|
||
| static PROFILING: bool = false; | ||
|
|
||
| pub struct Timer { |
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.
nit: I'd rename this to LoggingTimer or ConsoleLogTimer because nothing in the implementation (and no comments) indicate that it is a helper object to time operations in JS and report them to the console.
hf_xet_wasm/src/xorb_uploader.rs
Outdated
| } | ||
|
|
||
| impl XorbUploaderLocalSequential { | ||
| #[allow(dead_code)] |
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.
why need this?
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.
was used for linting, removing the macro it and letting the warning stick
rajatarya
left a comment
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.
Love the changes, let's merge!
This implements uploading through Xet protocol in WASM environment, and makes necessary changes to make dependent crates WASM compatible.