Any gotcha's with manually adding items to transformers-cache?
Opened this issue · 0 comments
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);
})