Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -14,9 +14,36 @@ LOCAL_CKPT = snapshot_download(
|
|
14 |
repo_id="AbstractPhil/bert-beatrix-2048",
|
15 |
revision="main",
|
16 |
local_dir="bert-beatrix-2048",
|
17 |
-
local_dir_use_symlinks=False
|
18 |
)
|
19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
handler, full_model, tokenizer = create_handler_from_checkpoint(LOCAL_CKPT)
|
21 |
full_model = full_model.eval().cuda()
|
22 |
|
|
|
14 |
repo_id="AbstractPhil/bert-beatrix-2048",
|
15 |
revision="main",
|
16 |
local_dir="bert-beatrix-2048",
|
17 |
+
local_dir_use_symlinks=False,
|
18 |
)
|
19 |
|
20 |
+
cfg_path = Path(LOCAL_CKPT) / "config.json"
|
21 |
+
with open(cfg_path) as f:
|
22 |
+
cfg = json.load(f)
|
23 |
+
|
24 |
+
auto_map = cfg.get("auto_map", {})
|
25 |
+
changed = False
|
26 |
+
for k, v in auto_map.items():
|
27 |
+
# v looks like "AbstractPhil/bert-beatrix-2048--modeling_hf_nomic_bert.…"
|
28 |
+
if "--" in v:
|
29 |
+
auto_map[k] = PurePosixPath(v.split("--", 1)[1]).as_posix()
|
30 |
+
changed = True
|
31 |
+
|
32 |
+
if changed:
|
33 |
+
cfg["auto_map"] = auto_map
|
34 |
+
with open(cfg_path, "w") as f:
|
35 |
+
json.dump(cfg, f, indent=2)
|
36 |
+
print("🔧 Patched auto_map → now points to local modules only")
|
37 |
+
|
38 |
+
# also drop any *previously* imported remote modules in this session
|
39 |
+
for name in list(sys.modules):
|
40 |
+
if name.startswith("transformers_modules.AbstractPhil.bert-beatrix-2048"):
|
41 |
+
del sys.modules[name]
|
42 |
+
|
43 |
+
# ------------------------------------------------------------------
|
44 |
+
# 1. normal load via BERTHandler ---------------------------------
|
45 |
+
# ------------------------------------------------------------------
|
46 |
+
from bert_handler import create_handler_from_checkpoint
|
47 |
handler, full_model, tokenizer = create_handler_from_checkpoint(LOCAL_CKPT)
|
48 |
full_model = full_model.eval().cuda()
|
49 |
|