You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running in a Node.js environment, it looks like there's an edge case where the unavailability of a caching system causes an error when loading model files. The problematic code:
Specifically, in a Node.js environment, getModelFile() attempts to download the respective model.onnx (or equivalent) file, store it in a cache and return the path to it. In cases where caching is disabled or unavailable and a remote model is to be loaded, cache stays undefined and the cache.match() call throws an error.
Simple repro (just setting useFSCache to be false):
import*astransformersfrom'@huggingface/transformers';transformers.env.useFSCache=false;transformers.pipeline("sentiment-analysis").then(asyncpipe=>{console.log(awaitpipe('Doesn\'t work when cache is unavailable!'))})
raises TypeError: Cannot read properties of undefined (reading 'match').
File system availability for caching might be an okay assumption to make here, but I feel like it should still be checked for. The function does make allowances for it in most places, it's just this last piece that seems to miss it.
As a possible suggestion, the response variable already contains the downloaded model file, so in cases where caching is unavailable, it might make sense to just pass the buffer back. Seems like it's passed directly to ONNX.InferenceSession.create(), which accepts both buffers and paths. Happy to raise a PR if that's acceptable.
The text was updated successfully, but these errors were encountered:
PrafulB
changed the title
[Transformers.js] Missing check for caching system availability when getting model files
Missing check for caching system availability when getting model files
Apr 10, 2025
PrafulB
changed the title
Missing check for caching system availability when getting model files
Missing check for caching availability when getting model files
Apr 10, 2025
When running in a Node.js environment, it looks like there's an edge case where the unavailability of a caching system causes an error when loading model files. The problematic code:
Specifically, in a Node.js environment,
getModelFile()
attempts to download the respective model.onnx (or equivalent) file, store it in a cache and return the path to it. In cases where caching is disabled or unavailable and a remote model is to be loaded,cache
stays undefined and thecache.match()
call throws an error.Simple repro (just setting
useFSCache
to befalse
):raises
TypeError: Cannot read properties of undefined (reading 'match')
.File system availability for caching might be an okay assumption to make here, but I feel like it should still be checked for. The function does make allowances for it in most places, it's just this last piece that seems to miss it.
As a possible suggestion, the
response
variable already contains the downloaded model file, so in cases where caching is unavailable, it might make sense to just pass the buffer back. Seems like it's passed directly toONNX.InferenceSession.create()
, which accepts both buffers and paths. Happy to raise a PR if that's acceptable.The text was updated successfully, but these errors were encountered: