Skip to content
Dashboard

Download Model Weights and Files

When building serverless applications with fal, you may need to download model weights, files, and datasets from external sources.

Downloading Files

You can download files from external sources using the download_file function. This function handles downloading files from URLs with built-in caching and error handling.

This is particularly useful for downloading datasets, configuration files, or any external resources your application needs.

from fal.toolkit import download_file, FAL_PERSISTENT_DIR
class MyApp(fal.App):
def setup(self):
path = download_file(
"https://example.com/myfile.txt",
FAL_PERSISTENT_DIR / "mydir",
)
...

Downloading Model Weights

You can download model weights from external sources using the download_model_weights function. This function is specifically designed for downloading model weights and provides several useful features:

  • Predefined storage location: Automatically stores weights in an optimized directory structure
  • Smart caching: Avoids re-downloading weights that are already present unless forced
  • Authentication support: Supports custom request headers for private repositories

This function is particularly useful for downloading pre-trained model weights from Hugging Face, custom model repositories, or private storage locations.

from fal.toolkit import download_model_weights
class MyApp(fal.App):
def setup(self):
path = download_model_weights(
"https://example.com/myfile.txt",
# Optional: force download even if the weights are already present
force=False,
# Optional: specify request headers
request_headers={
"Authorization": "Bearer <token>",
},
)
...