Run this model with HF Jobs

Run Jimmi42/MonkeyOCR-Apple-Silicon on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/Jimmi42/MonkeyOCR-Apple-Silicon. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/Jimmi42/MonkeyOCR-Apple-Silicon on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
MonkeyOCR-Apple-Silicon / torch_patch.py
Your Name
Initial commit with working MLX-VLM configuration
18352e1
Raw History Blame Contribute Delete
1.53 kB
#!/usr/bin/env python3
"""
Patch for PyTorch 2.7 weights_only issue with doclayout_yolo models
This allows loading the YOLO model weights safely
"""
import torch
import torch.serialization
# Store original torch.load
_original_torch_load = torch.load
def patched_torch_load(*args, **kwargs):
"""Patched torch.load that defaults to weights_only=False for compatibility"""
# If weights_only is not specified, set it to False for compatibility
if 'weights_only' not in kwargs:
kwargs['weights_only'] = False
return _original_torch_load(*args, **kwargs)
def patch_torch_load():
"""Patch torch.load to allow doclayout_yolo classes"""
try:
# First try to add safe globals
torch.serialization.add_safe_globals([
'doclayout_yolo.nn.tasks.YOLOv10DetectionModel',
'doclayout_yolo.nn.modules.YOLOv10DetectionModel',
'ultralytics.nn.tasks.DetectionModel',
'ultralytics.nn.modules.Conv',
'ultralytics.nn.modules.C2f',
'ultralytics.nn.modules.SPPF',
'ultralytics.nn.modules.Detect',
'ultralytics.nn.modules.DFL',
])
print("✅ PyTorch safe globals added for doclayout_yolo")
except Exception as e:
print(f"⚠️ Safe globals failed: {e}")
# Also monkey-patch torch.load to default to weights_only=False
torch.load = patched_torch_load
print("✅ PyTorch load function patched for compatibility")
if __name__ == "__main__":
patch_torch_load()