fix: Windows compatibility in from_pretrained#63
Conversation
Two bugs prevented TribeModel.from_pretrained() from working on Windows:
1. Path("facebook/tribev2") stringifies to "facebook\tribev2" on Windows,
making the HuggingFace repo_id invalid. Fixed by using .as_posix().
2. config.yaml was serialized on Linux with PosixPath objects. Loading it
with yaml.UnsafeLoader on Windows raises NotImplementedError. Fixed by
registering a custom YAML constructor that maps PosixPath/WindowsPath
tags to pathlib.Path before the parent UnsafeLoader handler runs.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Hi @giteuojeff! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Summary
TribeModel.from_pretrained()fails on Windows with two separate errors. This PR fixes both.Bug 1 — Invalid repo_id due to Windows path separator
Path("facebook/tribev2")on Windows stringifies tofacebook\tribev2(backslash), which is rejected byhf_hub_downloadas an invalid repo ID.Fix: use
.as_posix()instead ofstr()to always produce forward slashes.Bug 2 —
PosixPathcannot be instantiated on Windowsconfig.yamlwas serialised on Linux and contains!!python/object/apply:pathlib.PosixPathYAML tags. Loading it withyaml.UnsafeLoaderon Windows raises:Fix: register a custom YAML constructor directly in
yaml_constructors(checked before multi-constructors) that maps bothPosixPathandWindowsPathtags topathlib.Path, which resolves correctly on any platform.Test
Verified on Windows 11 with Python 3.12, CUDA 12.4, RTX 4050:
Notes for reviewer
Pathobjects as the original code would have.WindowsPathand thepython/object/new:variants are also covered defensively.