laya-weights 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,75 @@
1
+ """Offline weights for laya's English checkpoint (convaiinnovations/laya, repo root).
2
+
3
+ Installing this package makes `laya.load()` / `laya.Router()` use these files instead of the
4
+ Hugging Face Hub (see `_hook.py`). The safetensors file ships split across the
5
+ `laya-weights-part-NN` packages, because PyPI rejects files over 100 MB; it is rebuilt once,
6
+ verified against its SHA-256, into a writable cache directory (laya edits the tokenizer config
7
+ in place, and site-packages may be read-only).
8
+
9
+ python -m laya_weights # rebuild ahead of time, e.g. in a Docker build; prints the path
10
+ LAYA_WEIGHTS_HOME=/some/dir # where the rebuilt checkpoint lives (default ~/.cache/laya-weights)
11
+ """
12
+ import fnmatch
13
+ import hashlib
14
+ import importlib
15
+ import json
16
+ import os
17
+ import shutil
18
+ import uuid
19
+
20
+ _HERE = os.path.dirname(os.path.abspath(__file__))
21
+ with open(os.path.join(_HERE, "_manifest.json")) as _f:
22
+ MANIFEST = json.load(_f)
23
+
24
+ REPO = MANIFEST["repo"]
25
+ REVISION = MANIFEST["revision"]
26
+
27
+
28
+ def home() -> str:
29
+ return os.environ.get("LAYA_WEIGHTS_HOME") or os.path.join(os.path.expanduser("~"), ".cache", "laya-weights")
30
+
31
+
32
+ def covers(repo_id, revision=None, allow_patterns=None, repo_type=None, local_dir=None) -> bool:
33
+ """True when a snapshot_download call asks for nothing these bundled files cannot answer."""
34
+ if repo_id != REPO or repo_type not in (None, "model") or local_dir:
35
+ return False
36
+ if revision not in (None, "main", *MANIFEST["revisions"]):
37
+ return False # an explicit other revision may hold different weights
38
+ if not allow_patterns:
39
+ return False # a full snapshot includes files we do not ship
40
+ if isinstance(allow_patterns, str):
41
+ allow_patterns = [allow_patterns]
42
+ files = MANIFEST["files"] + ["model.safetensors"]
43
+ return all(fnmatch.filter(files, p) for p in allow_patterns)
44
+
45
+
46
+ def path() -> str:
47
+ """Directory holding the full checkpoint, rebuilt from the part packages on first call."""
48
+ snapshots = os.path.join(home(), "snapshots")
49
+ # Named <...>/snapshots/<sha> so laya's snapshot_revision() reports the commit, as for a Hub cache.
50
+ dest = os.path.join(snapshots, REVISION)
51
+ if os.path.isdir(dest):
52
+ return dest
53
+ os.makedirs(snapshots, exist_ok=True)
54
+ tmp = os.path.join(snapshots, ".tmp-" + uuid.uuid4().hex)
55
+ try:
56
+ shutil.copytree(os.path.join(_HERE, "files"), tmp)
57
+ digest = hashlib.sha256()
58
+ with open(os.path.join(tmp, "model.safetensors"), "wb") as out:
59
+ for name in MANIFEST["parts"]:
60
+ part = os.path.join(os.path.dirname(importlib.import_module(name).__file__), "chunk")
61
+ with open(part, "rb") as f:
62
+ for block in iter(lambda: f.read(1 << 24), b""):
63
+ digest.update(block)
64
+ out.write(block)
65
+ if digest.hexdigest() != MANIFEST["model_sha256"]:
66
+ raise RuntimeError("laya-weights: rebuilt model.safetensors fails its SHA-256 check; "
67
+ "reinstall with `pip install --force-reinstall laya-weights`")
68
+ try:
69
+ os.rename(tmp, dest) # atomic: dest only ever exists complete
70
+ except OSError:
71
+ if not os.path.isdir(dest): # not a lost race with another process
72
+ raise
73
+ finally:
74
+ shutil.rmtree(tmp, ignore_errors=True)
75
+ return dest
@@ -0,0 +1,3 @@
1
+ import laya_weights
2
+
3
+ print(laya_weights.path())
laya_weights/_hook.py ADDED
@@ -0,0 +1,47 @@
1
+ """Imported at interpreter startup by laya_weights.pth.
2
+
3
+ Waits for huggingface_hub to be imported, then wraps `huggingface_hub.snapshot_download` so a
4
+ request for the bundled laya checkpoint returns the local copy. Everything else, including other
5
+ repos, other revisions and unfiltered snapshots, goes to the real function unchanged. laya does
6
+ `from huggingface_hub import snapshot_download` at call time, so it picks up the wrapper.
7
+ """
8
+ import importlib.util
9
+ import sys
10
+
11
+
12
+ def _wrap(hf):
13
+ real = hf.snapshot_download
14
+
15
+ def snapshot_download(repo_id, *args, **kwargs):
16
+ import laya_weights
17
+ if not args and laya_weights.covers(repo_id, kwargs.get("revision"), kwargs.get("allow_patterns"),
18
+ kwargs.get("repo_type"), kwargs.get("local_dir")):
19
+ return laya_weights.path()
20
+ return real(repo_id, *args, **kwargs)
21
+
22
+ snapshot_download.__wrapped__ = real
23
+ hf.snapshot_download = snapshot_download
24
+
25
+
26
+ class _Finder:
27
+ def find_spec(self, name, path=None, target=None):
28
+ if name != "huggingface_hub":
29
+ return None
30
+ sys.meta_path.remove(self)
31
+ spec = importlib.util.find_spec(name)
32
+ if spec is None or spec.loader is None:
33
+ return spec
34
+ exec_module = spec.loader.exec_module
35
+
36
+ def patched(module):
37
+ exec_module(module)
38
+ _wrap(module)
39
+
40
+ spec.loader.exec_module = patched
41
+ return spec
42
+
43
+
44
+ if "huggingface_hub" in sys.modules:
45
+ _wrap(sys.modules["huggingface_hub"])
46
+ elif not any(isinstance(f, _Finder) for f in sys.meta_path):
47
+ sys.meta_path.insert(0, _Finder())
@@ -0,0 +1,26 @@
1
+ {
2
+ "repo": "convaiinnovations/laya",
3
+ "revision": "55cf4c4ebb4ebe31b2550e8bdf3bd21b99753851",
4
+ "revisions": [
5
+ "55cf4c4ebb4ebe31b2550e8bdf3bd21b99753851",
6
+ "e333cb7c823cd1787276228260f56d02fbf5180b"
7
+ ],
8
+ "files": [
9
+ "encoder/config.json",
10
+ "rl_agent_config.json",
11
+ "tokenizer/tokenizer.json",
12
+ "tokenizer/tokenizer_config.json"
13
+ ],
14
+ "parts": [
15
+ "laya_weights_part_00",
16
+ "laya_weights_part_01",
17
+ "laya_weights_part_02",
18
+ "laya_weights_part_03",
19
+ "laya_weights_part_04",
20
+ "laya_weights_part_05",
21
+ "laya_weights_part_06",
22
+ "laya_weights_part_07",
23
+ "laya_weights_part_08"
24
+ ],
25
+ "model_sha256": "891102d372688fc2a094dac56a384bc537b87c63f21f9f3dac0be2b7cbc8d86c"
26
+ }
@@ -0,0 +1,84 @@
1
+ {
2
+ "architectures": [
3
+ "ModernBertForMaskedLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 50281,
8
+ "classifier_activation": "gelu",
9
+ "classifier_bias": false,
10
+ "classifier_dropout": 0.0,
11
+ "classifier_pooling": "mean",
12
+ "cls_token_id": 50281,
13
+ "decoder_bias": true,
14
+ "deterministic_flash_attn": false,
15
+ "dtype": "float32",
16
+ "embedding_dropout": 0.0,
17
+ "eos_token_id": 50282,
18
+ "global_attn_every_n_layers": 3,
19
+ "gradient_checkpointing": false,
20
+ "hidden_activation": "gelu",
21
+ "hidden_size": 1024,
22
+ "initializer_cutoff_factor": 2.0,
23
+ "initializer_range": 0.02,
24
+ "intermediate_size": 2624,
25
+ "layer_norm_eps": 1e-05,
26
+ "layer_types": [
27
+ "full_attention",
28
+ "sliding_attention",
29
+ "sliding_attention",
30
+ "full_attention",
31
+ "sliding_attention",
32
+ "sliding_attention",
33
+ "full_attention",
34
+ "sliding_attention",
35
+ "sliding_attention",
36
+ "full_attention",
37
+ "sliding_attention",
38
+ "sliding_attention",
39
+ "full_attention",
40
+ "sliding_attention",
41
+ "sliding_attention",
42
+ "full_attention",
43
+ "sliding_attention",
44
+ "sliding_attention",
45
+ "full_attention",
46
+ "sliding_attention",
47
+ "sliding_attention",
48
+ "full_attention",
49
+ "sliding_attention",
50
+ "sliding_attention",
51
+ "full_attention",
52
+ "sliding_attention",
53
+ "sliding_attention",
54
+ "full_attention"
55
+ ],
56
+ "local_attention": 128,
57
+ "max_position_embeddings": 8192,
58
+ "mlp_bias": false,
59
+ "mlp_dropout": 0.0,
60
+ "model_type": "modernbert",
61
+ "norm_bias": false,
62
+ "norm_eps": 1e-05,
63
+ "num_attention_heads": 16,
64
+ "num_hidden_layers": 28,
65
+ "pad_token_id": 50283,
66
+ "position_embedding_type": "absolute",
67
+ "repad_logits_with_grad": false,
68
+ "rope_parameters": {
69
+ "full_attention": {
70
+ "rope_theta": 160000.0,
71
+ "rope_type": "default"
72
+ },
73
+ "sliding_attention": {
74
+ "rope_theta": 10000.0,
75
+ "rope_type": "default"
76
+ }
77
+ },
78
+ "sep_token_id": 50282,
79
+ "sparse_pred_ignore_index": -100,
80
+ "sparse_prediction": false,
81
+ "tie_word_embeddings": true,
82
+ "transformers_version": "5.0.0",
83
+ "vocab_size": 50368
84
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "encoder": "answerdotai/ModernBERT-large",
3
+ "head_layers": 2,
4
+ "max_len": 512,
5
+ "head_max_len": 192,
6
+ "max_prefixes": 6,
7
+ "act_costs": {
8
+ "escalate": 0.5
9
+ },
10
+ "cost_wrong_act": 3.0,
11
+ "amp_dtype": "bf16",
12
+ "model_name": "rl-agent",
13
+ "temperature": [
14
+ 1.6369030475616455,
15
+ 1.2514300346374512,
16
+ 1.983399510383606
17
+ ],
18
+ "temperature_by_options": {
19
+ "choice:3-5": 1.7601518630981445,
20
+ "choice:6-10": 1.0000158548355103,
21
+ "score:3-5": 1.2514300346374512,
22
+ "noul:2": 1.983399510383606,
23
+ "choice:11+": 0.10058280825614929,
24
+ "choice:2": 1.9063563346862793
25
+ },
26
+ "training": {
27
+ "updates": 7313,
28
+ "epochs_completed": 1,
29
+ "hours": 1.96,
30
+ "world_size": 1,
31
+ "fine_tuned_from_checkpoint": true
32
+ }
33
+ }