Hugging Face Hub Integration¶
Erasus can push unlearned models to the Hugging Face Hub and pull them for further use. Install the optional dependency:
pip install erasus[hub]
# or
pip install huggingface_hub datasets
Usage¶
Push an unlearned model¶
from erasus.integrations import HuggingFaceHub
hub = HuggingFaceHub(token="hf_...") # or set HF_TOKEN env var
hub.push_model(
model=unlearned_model,
repo_id="username/my-unlearned-model",
unlearning_info={
"strategy": "gradient_ascent",
"selector": "herding",
"epochs": 5,
"forget_size": 1000,
"elapsed_time": 120.5,
"metrics": {"mia_auc": 0.52, "accuracy": 0.91},
},
create_model_card=True,
)
This creates a repo (or updates it), uploads model.pt, unlearning_info.json,
and a generated README model card.
Pull a model and metadata¶
path = hub.pull_model("username/my-unlearned-model", filename="model.pt")
info = hub.pull_unlearning_info("username/my-unlearned-model")
Load Hugging Face datasets¶
dataset = HuggingFaceHub.load_dataset("locuslab/TOFU", split="forget10")
loader = HuggingFaceHub.dataset_to_dataloader(dataset, batch_size=32)
Deployment checklist¶
Token: Create a token at https://huggingface.co/settings/tokens and set
HF_TOKENor passtoken=...toHuggingFaceHub().Repo:
repo_idmust be"org_or_user/repo_name". The Hub creates the repo on first push if it does not exist.Optional deps: Use
pip install erasus[hub]orerasus[full]sohuggingface_hub(and optionallydatasets) are installed.