Skip to content
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

Any gotcha's with manually adding items to transformers-cache? #981

Open
flatsiedatsie opened this issue Oct 18, 2024 · 0 comments
Open
Labels
question Further information is requested

Comments

@flatsiedatsie
Copy link
Contributor

flatsiedatsie commented Oct 18, 2024

Question

For papeg.ai I've implemented that the service worker caches .wasm files from jsDelivir that Transformers.js wasn't caching itself yet.

I've been caching those filesi n the 'main' Papeg.ai cache until now, but I want to switch to saving those files in the transformers-cache instead. That would (hopefully) make it so that the .wasm files don't have to be downloaded again if I update papeg.ai (which clears the papeg.ai cache). And vice-versa: the transformers cache could be fully cleared independently of the papeg.ai cache (ideally Transformers.js would manage all this itself).

  • Is this a reasonable idea?
  • Is this in line with your plans for a future improved caching system? Or do you, for example, plan to keep wasm, onnx and config files in separate caches, like WebLLM?
  • Will Transformers.js even look for those .wasm files in transformers-cache first? With the service worker this doesn't technically matter, as requests to jsDelivir are captured anyway. But the service worker isn't always available.

Tangentially, would it be an idea to (also) store the code and wasm files on Huggingface itself? Because of EU privacy regulations, and good privacy design in general, I'd like to keep third parties that the site needs to connect to to an absolute minimum. I'd love to eliminate jsDelivir, and only rely on Github and HuggingFace. Or is there perhaps a way to tell Transformers.js where to look? Then I could host the files on Github/HuggingFace manually.

Just for fun, here's a service worker code snippet that, from now on, stores the jsDelivir files in the transformers-cache:

let target_cache = cacheName;
										if(request.url.indexOf('https://cdn.jsdelivr.net/npm/@huggingface/transformers') != -1){
	console.log("service_worker: saving to transformers-cache: ", request.url);
	target_cache = 'transformers-cache';
}

caches.open(target_cache)
.then(function(cache) {
	cache.put(request, fetch_response_clone);
})
.catch((err) => {
	console.error("service worker: caught error adding to cache: ", err);
})
@flatsiedatsie flatsiedatsie added the question Further information is requested label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant