Self-hosted Lightweight Huggingface Mirror Service
Olah is a self-hosted lightweight huggingface mirror service. Olah means hello in Hilichurlian.
Olah implemented the mirroring feature for huggingface resources, rather than just a simple reverse proxy.
Olah does not immediately mirror the entire huggingface website but mirrors the resources at the file block level when users download them (or we can say cache them).
Other languages: 中文
Olah has the capability to cache files in chunks while users download them. Upon subsequent downloads, the files can be directly retrieved from the cache, greatly enhancing download speeds and saving bandwidth. Additionally, Olah offers a range of cache control policies. Administrators can configure which repositories are accessible and which ones can be cached through a configuration file.
- Huggingface Data Cache
- Models mirror
- Datasets mirror
- Spaces mirror
pip install olahor:
pip install git+https://github.com/vtuber-plan/olah.git - Clone this repository
git clone https://github.com/vtuber-plan/olah.git
cd olah- Install the Package
pip install --upgrade pip
pip install -e .Olah publishes a multi-arch (linux/amd64 and linux/arm64) image to Docker Hub for every release:
docker pull xiahan2019/olah:latestSee Run with Docker for usage.
Run the command in the console:
olah-cliThen set the Environment Variable HF_ENDPOINT to the mirror site (Here is http://localhost:8090).
Linux:
export HF_ENDPOINT=http://localhost:8090Windows Powershell:
$env:HF_ENDPOINT = "http://localhost:8090"Starting from now on, all download operations in the HuggingFace library will be proxied through this mirror site.
pip install -U huggingface_hubfrom huggingface_hub import snapshot_download
snapshot_download(repo_id='Qwen/Qwen-7B', repo_type='model',
local_dir='./model_dir', resume_download=True,
max_workers=8)Or you can download models and datasets by using huggingface cli.
Download GPT2:
hf download openai-community/gpt2 --local-dir gpt2 --no-force-downloadDownload WikiText:
hf download --repo-type dataset Salesforce/wikitext --local-dir wikitext --no-force-downloadYou can check the path ./repos, in which olah stores all cached datasets and models.
Run the command in the console:
olah-cliOr you can specify the host address and listening port:
olah-cli --host localhost --port 8090Note: Please change --mirror-netloc and --mirror-lfs-netloc to the actual URLs of the mirror sites when modifying the host and port.
olah-cli --host 192.168.1.100 --port 8090 --mirror-netloc 192.168.1.100:8090The default mirror cache path is ./repos, you can change it by --repos-path parameter:
olah-cli --host localhost --port 8090 --repos-path ./hf_mirrorsNote that the cached data between different versions cannot be migrated. Please delete the cache folder before upgrading to the latest version of Olah.
In deployment scenarios, there may be high concurrent downloads, leading to Timeout errors for new connections. You can increase the number of workers to enhance concurrency in production environments:
olah-cli --workers 4Start the server with the published image (cached repositories are kept in the olah-repos volume):
docker run -d --name olah -p 8090:8090 \
-v olah-repos:/data/repos \
xiahan2019/olah:latest --host 0.0.0.0Then point your clients at it by setting HF_ENDPOINT=http://localhost:8090, the same as above.
Notes:
--host 0.0.0.0makes the server listen on all interfaces so the published port is reachable. It is required for images up to0.5.2and becomes the image default in later releases.- Each release is also tagged by version (e.g.
xiahan2019/olah:0.5.2), so you can pin one. - Other CLI flags work the same way as
olah-cli, e.g.--hf-netloc hf-mirror.comto use an intermediate mirror as the upstream. - To serve local git mirrors in addition to the proxy cache, also mount
/data/mirrors.
There is also a ready-made compose file with a configs.toml template under docker/up:
cd docker/up
docker compose up -dAdditional configurations can be controlled through a configuration file by passing the configs.toml file as a command parameter:
olah-cli -c configs.tomlThe complete content of the configuration file can be found at assets/full_configs.toml.
The first section, basic, is used to set up basic configurations for the mirror site:
[basic]
host = "localhost"
port = 8090
ssl-key = ""
ssl-cert = ""
repos-path = "./repos"
cache-size-limit = ""
cache-clean-strategy = "LRU"
metadata-cache-ttl = 600
metadata-stale-if-error = 86400
hf-scheme = "https"
hf-netloc = "huggingface.co"
hf-lfs-netloc = "cdn-lfs.huggingface.co"
mirror-scheme = "http"
mirror-netloc = "localhost:8090"
mirror-lfs-netloc = "localhost:8090"
mirrors-path = ["./mirrors_dir"]host: Sets the host address that Olah listens to.port: Sets the port that Olah listens to.ssl-keyandssl-cert: When enabling HTTPS, specify the file paths for the key and certificate.repos-path: Specifies the directory for storing cached data.cache-size-limit: Specifies cache size limit (For example, 100G, 500GB, 2TB). Olah will scan the size of the cache folder every hour. If it exceeds the limit, olah will delete some cache files.cache-clean-strategy: Specifies cache cleaning strategy (Available strategies: LRU, FIFO, LARGE_FIRST).metadata-cache-ttl: Seconds a cached repo/revision metadata response (repo visibility probe, branch → commit resolution) is reused before revalidating against Hugging Face. Visibility depends on the caller's token, so it is only reused for the same caller. A single model startup can repeat these lookups thousands of times (per file, per worker) and exhaust the Hub's API rate limit (1000 requests / 5 minutes). With the default 600, each (repo, revision) costs at most one upstream call per 10 minutes; if the upstream fails or is rate-limited, the last known value is served instead of erroring.0disables reuse: every request revalidates (pre-v0.5.3 behavior).metadata-stale-if-error: Seconds a caller's last confirmed access to a repository may still be used when Hugging Face is rate-limiting (429) or unavailable (5xx, timeouts). Such requests are then served from the cache as in offline mode; if the cache cannot answer, the upstream error is passed on. File downloads always revalidate access, so this applies to them regardless ofmetadata-cache-ttl.0disables the fallback.hf-scheme: Network protocol for the Hugging Face official site (usually no need to modify).hf-netloc: Network location of the Hugging Face official site (usually no need to modify).hf-lfs-netloc: Network location for Hugging Face official site's LFS files (usually no need to modify).mirror-scheme: Network protocol for the Olah mirror site (should match the above settings; change to HTTPS if providingssl-keyandssl-cert).mirror-netloc: Network location of the Olah mirror site (should matchhostandportsettings).mirror-lfs-netloc: Network location for Olah mirror site's LFS (should matchhostandportsettings).mirrors-path: Additional mirror file directories. If you have already cloned some Git repositories, you can place them in this directory for downloading. In this example, the directory is./mirrors_dir. To add a dataset likeSalesforce/wikitext, you can place the Git repository in the directory./mirrors_dir/datasets/Salesforce/wikitext. Similarly, models can be placed under./mirrors_dir/models/organization/repository.
The second section allows for accessibility restrictions:
[accessibility]
offline = false
[[accessibility.proxy]]
repo = "cais/mmlu"
allow = true
[[accessibility.proxy]]
repo = "adept/fuyu-8b"
allow = false
[[accessibility.proxy]]
repo = "mistralai/*"
allow = true
[[accessibility.proxy]]
repo = "mistralai/Mistral.*"
allow = false
use_re = true
[[accessibility.cache]]
repo = "cais/mmlu"
allow = true
[[accessibility.cache]]
repo = "adept/fuyu-8b"
allow = falseoffline: Sets whether the Olah mirror site enters offline mode, no longer making requests to the Hugging Face official site for data updates. However, cached repositories can still be downloaded.proxy: Determines if the repository can be accessed through a proxy. By default, all repositories are allowed. Therepofield is used to match the repository name. Regular expressions and wildcards can be used by settinguse_reto control whether to use regular expressions (default is to use wildcards). Theallowfield controls whether the repository is allowed to be proxied.cache: Determines if the repository will be cached. By default, all repositories are allowed. Therepofield is used to match the repository name. Regular expressions and wildcards can be used by settinguse_reto control whether to use regular expressions (default is to use wildcards). Theallowfield controls whether the repository is allowed to be cached.
- Administrator and user system
- OOS backend support
- Mirror Update Schedule Task
olah is released under the MIT License.