Skip to content

ascorbic/transformer-fun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤗 Transformers.js on Netlify

Deploy to Netlify

Overview

This repo contains examples of using the transformers.js library to run Hugging Face models in Netlify functions. The examples are in the netlify/functions folder.

Limitations

  • Functions have a max execution time of 10 seconds. This includes downloading and caching the model on first run.
  • Models need to be small enough to fit in the function's temporary directory, which is 512MB.
  • Cold starts will be slower as it downloads the model into the cache. Subsequent invocations will be faster.

Examples

Image classification demo

The netlify/functions folder contains examples showing:

Each example imports a small model from Hugging Face and shows how to call it in a Netlify function handler.

Caching

To avoid downloading the model every invocation, the examples cache the model in the /tmp directory. The cached model is reused on subsequent invocations.

The cache is persisted across invocations, but not guaranteed to persist for long periods of time. Expect to re-download the model every few hours/days.

Performance

First invocation will be slow (a few seconds) as it downloads and caches the model. After that invocations should complete very quickly.

Keep computation using the model lightweight to avoid timeout issues. Do as much preprocessing outside of the function handler.

Additional Resources

Deploy to Netlify

Releases

No releases published

Packages

No packages published