fr0stbit3 commited on
Commit
ce2afdc
·
verified ·
1 Parent(s): 190ee1c

Upload folder using huggingface_hub

Browse files
README.md CHANGED
@@ -8,12 +8,12 @@ base_model_relation: quantized
8
  ---
9
 
10
  > **GGUF conversion** of [convaiinnovations/laya](https://huggingface.co/convaiinnovations/laya) (Apache-2.0), f16, via llama.cpp `convert_hf_to_gguf.py`.
11
- > `laya-F16.gguf` is a single file: the ModernBERT backbone (loads in llama.cpp as `modern-bert`, use `--embeddings --pooling none`) plus the decision head and config, embedded as base64 f32 metadata keys (`laya.head.*`, `laya.config`) that llama.cpp ignores. Read them with `laya_gguf.py` (`load_head(path)` returns config + head weights under the original PyTorch names); the head itself must run outside llama.cpp.
12
  > **Lightly tested:** outputs matched the original on a limited set (100 AG News + 100 DAIR Emotion samples, a few examples); may need further testing.
13
  > **Quantized files** (`laya-Q8_0.gguf`, `-Q6_K.gguf`, `-Q4_K_M.gguf`; `laya-F16.gguf` is the unquantized 16-bit original conversion) are made with `llama-quantize` from the f16 file and are **even less tested**: checked on a single example only, where Q8_0/Q6_K stayed close to f16 and Q4_K_M drifted slightly more (probabilities shifted by up to about 0.02 to 0.03, and score outputs by about 0.04). Prefer f16 or Q8_0 for anything important, and verify Q4_K_M on your own data.
14
 
15
 
16
- **Quant check** (single example: the HF README ticket "Duplicate charge on invoice 4411"; `department`=billing probability, `urgency` score 0-2, `churn_risk` noul; head weights taken from the GGUF, backbone in llama.cpp). One example only, not a benchmark.
17
 
18
  | file | size | billing p | urgency | churn |
19
  |---|---|---|---|---|
@@ -30,22 +30,22 @@ base_model_relation: quantized
30
  llama-server -m laya-F16.gguf --embeddings --pooling none -c 2048 -ub 2048 -b 2048 --port 8080
31
 
32
  # 2. python deps for the decision head + tokenizer
33
- pip install laya requests torch
34
  ```
35
 
36
  ```python
37
- # quickstart.py: llama.cpp backbone + Laya head from the same GGUF
38
  import types, requests, torch, laya
39
- from laya_gguf import load_head
40
 
41
- GGUF = "laya-F16.gguf"
42
  agent = laya.load("convaiinnovations/laya", device="cpu") # builds the head architecture + tokenizer/prompt logic
43
 
44
- # swap in the decision-head weights stored in the GGUF
45
- _, head = load_head(GGUF)
46
  sd = agent.model.state_dict()
47
  for k, v in head.items():
48
- if k in sd: sd[k].copy_(torch.from_numpy(v.copy()))
49
 
50
  # swap the PyTorch encoder for the llama.cpp server
51
  D = agent.model.encoder.config.hidden_size
 
8
  ---
9
 
10
  > **GGUF conversion** of [convaiinnovations/laya](https://huggingface.co/convaiinnovations/laya) (Apache-2.0), f16, via llama.cpp `convert_hf_to_gguf.py`.
11
+ > `laya-F16.gguf` (and the quants) hold the ModernBERT backbone only, and load in llama.cpp as `modern-bert` (use `--embeddings --pooling none`). The decision head and config are in the sibling file `laya-head.safetensors` (like an `mmproj` file); read it with `laya_head.py` (`load_head(path)` returns config + head weights under the original PyTorch names). The head itself must run outside llama.cpp.
12
  > **Lightly tested:** outputs matched the original on a limited set (100 AG News + 100 DAIR Emotion samples, a few examples); may need further testing.
13
  > **Quantized files** (`laya-Q8_0.gguf`, `-Q6_K.gguf`, `-Q4_K_M.gguf`; `laya-F16.gguf` is the unquantized 16-bit original conversion) are made with `llama-quantize` from the f16 file and are **even less tested**: checked on a single example only, where Q8_0/Q6_K stayed close to f16 and Q4_K_M drifted slightly more (probabilities shifted by up to about 0.02 to 0.03, and score outputs by about 0.04). Prefer f16 or Q8_0 for anything important, and verify Q4_K_M on your own data.
14
 
15
 
16
+ **Quant check** (single example: the HF README ticket "Duplicate charge on invoice 4411"; `department`=billing probability, `urgency` score 0-2, `churn_risk` noul; head weights from the head file, backbone in llama.cpp). One example only, not a benchmark.
17
 
18
  | file | size | billing p | urgency | churn |
19
  |---|---|---|---|---|
 
30
  llama-server -m laya-F16.gguf --embeddings --pooling none -c 2048 -ub 2048 -b 2048 --port 8080
31
 
32
  # 2. python deps for the decision head + tokenizer
33
+ pip install laya requests torch safetensors
34
  ```
35
 
36
  ```python
37
+ # quickstart.py: llama.cpp backbone + Laya head from the sibling head file
38
  import types, requests, torch, laya
39
+ from laya_head import load_head
40
 
41
+ HEAD = "laya-head.safetensors"
42
  agent = laya.load("convaiinnovations/laya", device="cpu") # builds the head architecture + tokenizer/prompt logic
43
 
44
+ # swap in the decision-head weights from the head file
45
+ _, head = load_head(HEAD)
46
  sd = agent.model.state_dict()
47
  for k, v in head.items():
48
+ if k in sd: sd[k].copy_(v)
49
 
50
  # swap the PyTorch encoder for the llama.cpp server
51
  D = agent.model.encoder.config.hidden_size
laya-F16.gguf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:8f3115641224f4290fe4f79a841c6fffcced74f446d703c2949557d9eddc68fe
3
- size 932864416
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f10551bbe259518d7b00f2b9e5d101a1d6ac557e3f977322bfa875149dd5ddc9
3
+ size 791461088
laya-Q4_K_M.gguf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:8d1e63d6c7310c3bc2ef798b1c16d0ed3d2672a3c7fece6c423e872e0a3a34a1
3
- size 413611936
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37c331ded9b71542541692c877e60452f873f430ef405c5158257e130bd890d7
3
+ size 272208608
laya-Q6_K.gguf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:08e29f56837ffedc96e674186716648ec9114838532d30e057a1c3e6ed9b3297
3
- size 485435296
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8b084f58fba1c362611f09a84dbe7b09a6eb6b40d62dce03408a1c0d7e195cc8
3
+ size 344031968
laya-Q8_0.gguf CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:4d33f31d93d6c06c162e809e0436e04af2f2fea70a564743284bf9d8583044b2
3
- size 562811296
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:76a5787a9c853d04db4ff214ae31fe2bd51aa15c8bef2fc886a3493f3c136dae
3
+ size 421407968
laya-head.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c1ec428e034614c9373ebcf3fdc255d8eafcc04be9b2f0c2ffeef92bb1361b83
3
+ size 106052840
laya_gguf.py DELETED
@@ -1,20 +0,0 @@
1
- """Read the Laya decision head out of a laya GGUF (stored as base64 f32 KV strings)."""
2
- import base64, json, sys
3
- import numpy as np
4
- from gguf import GGUFReader
5
-
6
- def _s(f): return bytes(f.parts[f.data[0]]).decode()
7
-
8
- def load_head(path):
9
- """-> (config dict, {tensor_name: np.float32 array}); names match the original PyTorch state_dict."""
10
- r = GGUFReader(path); cfg = None; head = {}
11
- for k, f in r.fields.items():
12
- if k == "laya.config": cfg = json.loads(_s(f))
13
- elif k.startswith("laya.head.") and not k.endswith(".shape"):
14
- n = k[len("laya.head."):]
15
- shape = json.loads(_s(r.fields[k + ".shape"]))
16
- head[n] = np.frombuffer(base64.b64decode(_s(f)), np.float32).reshape(shape)
17
- return cfg, head
18
-
19
- if __name__ == "__main__":
20
- cfg, h = load_head(sys.argv[1]); print(len(h), "head tensors;", list(cfg)[:5])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
laya_head.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Load the Laya decision head + config from <name>-head.safetensors (sits next to the GGUF backbone)."""
2
+ import json, sys
3
+ from safetensors import safe_open
4
+
5
+ def load_head(path):
6
+ """-> (config dict, {tensor_name: torch.float32 tensor}); names match the original PyTorch state_dict."""
7
+ with safe_open(path, "pt") as f:
8
+ cfg = json.loads(f.metadata()["laya.config"])
9
+ return cfg, {k: f.get_tensor(k) for k in f.keys()}
10
+
11
+ if __name__ == "__main__":
12
+ cfg, h = load_head(sys.argv[1]); print(len(h), "head tensors;", list(cfg)[:5])