| """Resumable large-folder upload to a Hugging Face mirror. |
| |
| Works around two mirror-side issues with the LFS multipart-completion endpoint |
| (hf-mirror.org): an incomplete SSL chain and intermittent 504 gateway timeouts. |
| - SSL: inject a requests session with verify=False via configure_http_backend. |
| - 504: rely on upload_large_folder's built-in retry loop. |
| """ |
|
|
| import os |
| import warnings |
|
|
| import urllib3 |
| import requests |
| from requests.adapters import HTTPAdapter |
| from urllib3.util.retry import Retry |
|
|
| warnings.filterwarnings("ignore") |
| urllib3.disable_warnings() |
|
|
| |
| |
| |
| os.environ.setdefault("HF_ENDPOINT", "https://hf-mirror.com") |
| os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = "0" |
|
|
| from huggingface_hub import configure_http_backend, HfApi |
|
|
|
|
| def _backend() -> requests.Session: |
| session = requests.Session() |
| session.verify = False |
| |
| |
| |
| retry = Retry( |
| total=10, |
| connect=10, |
| read=10, |
| status=10, |
| backoff_factor=2, |
| status_forcelist=(429, 500, 502, 503, 504), |
| allowed_methods=False, |
| respect_retry_after_header=True, |
| raise_on_status=False, |
| ) |
| adapter = HTTPAdapter(max_retries=retry) |
| session.mount("https://", adapter) |
| session.mount("http://", adapter) |
| return session |
|
|
|
|
| configure_http_backend(backend_factory=_backend) |
|
|
| IGNORE_PATTERNS = [ |
| "runs/*", |
| "data/*", |
| "checkpoints_tmp/*", |
| |
| |
| "checkpoints/Wan-AI/*", |
| "checkpoints/DiffSynth-Studio/*", |
| "*/__pycache__/*", |
| "*/.cache/*", |
| "src/fastwam.egg-info/*", |
| "*.log", |
| "PyTorch", |
| "gcc", |
| ".git/*", |
| ] |
|
|
| if __name__ == "__main__": |
| api = HfApi() |
| api.upload_large_folder( |
| repo_id="jwfanDL/fastwam", |
| folder_path=".", |
| repo_type="model", |
| ignore_patterns=IGNORE_PATTERNS, |
| num_workers=1, |
| print_report=True, |
| ) |
|
|