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

Add local dir parameter #887

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

BBC-Esq
Copy link
Contributor

@BBC-Esq BBC-Esq commented Jan 28, 2025

This PR adds a new local_dir parameter to provide more flexible control over model downloads.

A lot of people like to actually see the native files and work with them that way rather than HF's weird "cache" structure and naming.

Key Changes

  • Added local_dir parameter to both load() and download_models() methods
  • When specified, downloads preserve repository structure in the target directory
  • Added precedence handling: local_dir takes priority over other download location parameters

Usage Example

# Download to specific directory, maintaining repo structure
chat.load(source="huggingface", local_dir="path/to/dir")

# Download to specific directory with local source
chat.load(source="local", local_dir="path/to/dir")

Download Configuration Guide

The source parameter along with cache_dir and local_dir control how and where model files are downloaded:

Source: "huggingface"

Downloads directly from the Hugging Face repository:

Parameters Behavior Repo Structure?
(default) Downloads to ~/.cache/huggingface using HF's cache system No
cache_dir="path" Downloads to specified path using HF's cache system No
local_dir="path" Downloads to specified path preserving repository structure Yes

Source: "local"

Downloads from GitHub releases instead of Hugging Face:

Parameters Behavior Repo Structure?
(default) Downloads to current directory No
cache_dir="path" Downloads to specified path No
local_dir="path" Downloads to specified path preserving repository structure Yes

Source: "custom"

Uses existing files from a specified path:

Parameters Behavior Repo Structure?
custom_path Uses existing files at the specified path n/a
+cache_dir cache_dir parameter is ignored n/a
+local_dir local_dir parameter is ignored n/a

Repository Structure

When "Repo Structure?" is:

  • Yes: Files are downloaded maintaining the original repository's directory structure
  • No: Files are downloaded using a flattened or cache-specific structure
  • n/a: Uses files exactly as they exist in the custom path

Parameter Precedence and Usage Examples

  • Parameter precedence (highest to lowest):
  • local_dir (if specified, takes precedence over all other parameters)
  • cache_dir (used if local_dir is not specified)
  • Default location (used if neither local_dir nor cache_dir specified):
    • ~/.cache/huggingface (when source="huggingface")
    • Current directory (when source="local")

@github-actions github-actions bot changed the base branch from main to dev January 28, 2025 16:12
Copy link
Member

@fumiama fumiama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use custom_path for all those functions and add some enum or bool params to indicate its function in order to reduce the complexity.

@fumiama fumiama added enhancement New feature or request good first issue Good for newcomers labels Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants