AM-Core's picture
Upload folder using huggingface_hub
9c37cfa verified
from pathlib import Path
import cloudpickle
import dill
ROOT = Path(__file__).resolve().parent
class BenignCanary:
def __reduce__(self):
# Relative marker path: resolves under the current working directory during load.
marker = Path("logs") / "serialization_canary_loaded.txt"
return (marker.write_text, ("serialization canary was loaded\n",))
obj = BenignCanary()
(ROOT / "canary_cloudpickle.pkl").write_bytes(cloudpickle.dumps(obj, protocol=5))
(ROOT / "canary_dill.pkl").write_bytes(dill.dumps(obj, protocol=5))
print("rewrote portable canaries")
for p in [ROOT / "canary_cloudpickle.pkl", ROOT / "canary_dill.pkl"]:
print(p.name, p.stat().st_size)