Skip to content

Commit 5034a98

Browse files
jamt9000claude
andcommitted
fix: Restore PyTorch 2.11 compatibility for torch.hub and checkpoint loading
PyTorch 2.11.0 changed the default for trust_repo in torch.hub.load() from None to "check", which raises an error in non-interactive CI environments. Pass trust_repo=True explicitly in torch.hub tests. Also explicitly pass weights_only=False to load_state_dict_from_url and torch.load since our checkpoints contain config dicts alongside weights. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7e2f447 commit 5034a98

3 files changed

Lines changed: 7 additions & 7 deletions

File tree

.github/workflows/pyright.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Set up Python
1616
uses: actions/setup-python@v5
1717
with:
18-
python-version: '3.11'
18+
python-version: '3.13'
1919

2020
- name: Install dependencies
2121
run: |

detoxify/detoxify.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def get_model_and_tokenizer(
3838
def load_checkpoint(model_type="original", checkpoint=None, device="cpu", huggingface_config_path=None):
3939
if checkpoint is None:
4040
checkpoint_path = MODEL_URLS[model_type]
41-
loaded = torch.hub.load_state_dict_from_url(checkpoint_path, map_location=device)
41+
loaded = torch.hub.load_state_dict_from_url(checkpoint_path, map_location=device, weights_only=False)
4242
else:
43-
loaded = torch.load(checkpoint, map_location=device)
43+
loaded = torch.load(checkpoint, map_location=device, weights_only=False)
4444
if "config" not in loaded or "state_dict" not in loaded:
4545
raise ValueError(
4646
"Checkpoint needs to contain the config it was trained \

tests/test_torch_hub.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55

66
def test_torch_hub_models():
7-
result = torch.hub.list("unitaryai/detoxify", skip_validation=True)
7+
result = torch.hub.list("unitaryai/detoxify", skip_validation=True, trust_repo=True)
88

99

1010
def test_torch_hub_bert():
11-
model = torch.hub.load("unitaryai/detoxify", "toxic_bert", skip_validation=True)
11+
model = torch.hub.load("unitaryai/detoxify", "toxic_bert", skip_validation=True, trust_repo=True)
1212
del model
1313
gc.collect()
1414

1515

1616
def test_torch_hub_roberta():
17-
model = torch.hub.load("unitaryai/detoxify", "unbiased_toxic_roberta", skip_validation=True)
17+
model = torch.hub.load("unitaryai/detoxify", "unbiased_toxic_roberta", skip_validation=True, trust_repo=True)
1818
del model
1919
gc.collect()
2020

2121

2222
def test_torch_hub_multilingual():
23-
model = torch.hub.load("unitaryai/detoxify", "multilingual_toxic_xlm_r", skip_validation=True)
23+
model = torch.hub.load("unitaryai/detoxify", "multilingual_toxic_xlm_r", skip_validation=True, trust_repo=True)
2424
del model
2525
gc.collect()

0 commit comments

Comments
 (0)