Skip to content

Conversation

@seanses
Copy link
Collaborator

@seanses seanses commented Apr 25, 2025

This implements uploading through Xet protocol in WASM environment, and makes necessary changes to make dependent crates WASM compatible.

  1. Uploading through Xet protocol is done in hf_xet_wasm crate;
  2. Separate Cas Client trait definitions into upload and download functionality groups and disable download for WASM;
  3. Disable Cas Client request retry in WASM environment, which isn't critical for a POC (until we have a retry strategy that doesn't depends on time);
  4. Disable async CasObject deserialization;
  5. Enable in-memory global dedup;

@seanses seanses changed the base branch from main to di/wasm-compat April 25, 2025 17:30
@seanses seanses changed the base branch from di/wasm-compat to main April 28, 2025 07:07
assafvayner and others added 6 commits April 30, 2025 11:29
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.
@seanses seanses marked this pull request as ready for review June 2, 2025 16:17
@seanses seanses requested a review from assafvayner June 2, 2025 16:18
Copy link
Collaborator

@rajatarya rajatarya left a 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.)


/// Builds authenticated HTTP Client to talk to CAS.
/// Includes retry middleware with exponential backoff.
#[allow(unused_variables)]
Copy link
Collaborator

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?

Copy link
Contributor

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.

Copy link
Collaborator

@rajatarya rajatarya left a 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)]
Copy link
Collaborator

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.

Copy link
Contributor

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.

Copy link
Collaborator

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.
Copy link
Collaborator

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);
Copy link
Collaborator

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?

Copy link
Contributor

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.


static PROFILING: bool = false;

pub struct Timer {
Copy link
Collaborator

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.

}

impl XorbUploaderLocalSequential {
#[allow(dead_code)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

why need this?

Copy link
Contributor

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

Copy link
Collaborator

@rajatarya rajatarya left a 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!

@assafvayner assafvayner merged commit 9fbd234 into main Jun 25, 2025
5 checks passed
@assafvayner assafvayner deleted the wasm-poc branch June 25, 2025 19:08
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.

4 participants