Skip to content

fix: Windows compatibility in from_pretrained#63

Open
giteuojeff wants to merge 1 commit into
facebookresearch:mainfrom
giteuojeff:fix/windows-compatibility
Open

fix: Windows compatibility in from_pretrained#63
giteuojeff wants to merge 1 commit into
facebookresearch:mainfrom
giteuojeff:fix/windows-compatibility

Conversation

@giteuojeff
Copy link
Copy Markdown

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 to facebook\tribev2 (backslash), which is rejected by hf_hub_download as an invalid repo ID.

Fix: use .as_posix() instead of str() to always produce forward slashes.

Bug 2 — PosixPath cannot be instantiated on Windows

config.yaml was serialised on Linux and contains !!python/object/apply:pathlib.PosixPath YAML tags. Loading it with yaml.UnsafeLoader on Windows raises:

NotImplementedError: cannot instantiate 'PosixPath' on your system

Fix: register a custom YAML constructor directly in yaml_constructors (checked before multi-constructors) that maps both PosixPath and WindowsPath tags to pathlib.Path, which resolves correctly on any platform.

Test

Verified on Windows 11 with Python 3.12, CUDA 12.4, RTX 4050:

from tribev2 import TribeModel
model = TribeModel.from_pretrained("facebook/tribev2", cache_folder="./cache")
# Loads successfully — no errors

Notes for reviewer

  • No behaviour change on Linux/macOS; the custom constructor produces the same Path objects as the original code would have.
  • WindowsPath and the python/object/new: variants are also covered defensively.

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>
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 12, 2026

Hi @giteuojeff!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants