SIGN IN SIGN UP

fix(staging): Windows symlink WinError 1314 — hardlink staging on the model's drive

Staging linked weights into a temp dir via os.symlink. On Windows that needs
Developer Mode or admin (else WinError 1314 "a required privilege is not held"),
so non-elevated users crashed at pipeline build. The temp dir also defaulted to
the system drive (C:), a different volume than the model (e.g. D:), which ruled
out hardlinks and forced symlinks.

Two-part fix:
- format_adapters/tools/fs_util.py: new link_or_copy(src, dst) — hardlink ->
  symlink -> copy. Windows hardlinks need NO privilege (only same volume) and
  cost zero extra disk; symlink covers cross-volume / Linux; copy is the last
  resort. Used at every weight-staging site in hf_layout.py (transformer alias,
  main weight, sharded fan-out, index.json) and zimage_bfl_remap.py.
- format_adapters/factory.py: _choose_staging_root() now stages on the model's
  volume on Windows (so the hardlink path is taken), keeping $QUANTFUNC_CACHE_DIR
  override and the Linux system-temp default unchanged.

Result: no Developer Mode, no admin, no re-download — staging hardlinks the
already-downloaded weights instantly.

Validated: 11/11 Linux unit tests (fallback chain + staging-root selection) and
7/7 on a real Windows Server 2022 / NTFS box — same-volume link_or_copy uses a
hardlink even with os.symlink force-failed (the exact non-admin 1314 condition),
and _choose_staging_root resolves to the model's drive.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Y
yejianhui committed
35477a67e325284e854187c41c7b9f5699fd97b6
Parent: 4cbd632