-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsitecustomize.py
More file actions
42 lines (31 loc) · 1.27 KB
/
sitecustomize.py
File metadata and controls
42 lines (31 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""Python startup customizations for MeetingSecretaryAI.
This file is automatically imported by Python (via the built-in `site` module)
when it is present on `sys.path`.
We use it to improve compatibility with recent PyTorch versions where
`torch.load(..., weights_only=True)` is the default. Some third-party model
checkpoints (notably pyannote/Lightning) include OmegaConf container types in
metadata, which require being added to PyTorch's safe unpickling allowlist.
This does NOT disable `weights_only` and does not opt into arbitrary code
execution; it only adds specific, commonly used OmegaConf container classes to
the safe globals.
"""
from __future__ import annotations
def _configure_torch_safe_globals() -> None:
try:
import torch
except Exception:
return
add_safe_globals = getattr(getattr(torch, "serialization", None), "add_safe_globals", None)
if add_safe_globals is None:
return
try:
from omegaconf.dictconfig import DictConfig
from omegaconf.listconfig import ListConfig
except Exception:
return
try:
add_safe_globals([DictConfig, ListConfig])
except Exception:
# Best-effort only; if this fails we fall back to default behavior.
return
_configure_torch_safe_globals()