dhenneberger1 commited on
Commit
a12ddfd
·
verified ·
1 Parent(s): 95bb832

Add int4 (Q4-style, mixed-precision) RT-J checkpoints + model card

Browse files
README.md ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-nc-sa-4.0
3
+ base_model: stanford-star/rt-j
4
+ tags:
5
+ - relational-deep-learning
6
+ - relational-databases
7
+ - tabular
8
+ - tabular-classification
9
+ - tabular-regression
10
+ - foundation-model
11
+ - in-context-learning
12
+ - quantized
13
+ - int4
14
+ - relational-transformer
15
+ datasets:
16
+ - stanford-star/the-join
17
+ - stanford-star/relbench
18
+ ---
19
+
20
+ # RT-J — int4 (Q4-style, mixed-precision) quantized checkpoints
21
+
22
+ Int4 quantizations of [stanford-star/rt-j](https://huggingface.co/stanford-star/rt-j),
23
+ the Relational Transformer foundation model for in-context learning over
24
+ relational databases. Produced and consumed by the
25
+ [RelativeDB](https://github.com/RelativeDB) native inference engine
26
+ (`cpp/rt_quantize --type q4`). Weights stay **quantized-resident** at
27
+ inference: the engine's CPU (Accelerate / portable SIMD) and Metal/MPS
28
+ kernels dequantize inside the GEMM, so DRAM weight traffic is the int4
29
+ payload.
30
+
31
+ Sibling repos: [rt-j-int8](https://huggingface.co/RelativeDB/rt-j-int8) ·
32
+ [rt-j-fp16](https://huggingface.co/RelativeDB/rt-j-fp16)
33
+
34
+ | File | Task head | Size |
35
+ |---|---|---|
36
+ | `classification/model.q4.safetensors` | classification / ranking (logits — apply sigmoid) | 64 MB |
37
+ | `regression/model.q4.safetensors` | regression / forecasting (normalized values) | 64 MB |
38
+
39
+ (vs. 171 MB bf16 upstream, 342 MB fp32 in memory.)
40
+
41
+ ## Quantization format
42
+
43
+ Plain safetensors — no custom container:
44
+
45
+ - Most **transformer-block projections** (`wq/wk/wv/wg`, `ffn.w1/w3`) are
46
+ uint4 in groups of 32 along the input dim: fp16 `(scale, min)` pair per
47
+ group in a `<name>.q4_scale` companion (`U8` payload, two nibbles/byte,
48
+ low nibble = even index): `W[o,i] ≈ nibble * scale + min`. Group ranges
49
+ are chosen by a min-MSE clip search (shrink grid 1.0→0.8).
50
+ - The **residual-writing projections** (`wo`, `ffn.w2`) stay int8 with
51
+ per-row fp32 scales (`I8` + `<name>.q_scale`) — the Q4_K_M recipe:
52
+ their error lands directly on the residual stream every block.
53
+ - The value/col-name **encoders, decoder head, norms, biases and mask
54
+ embeddings stay fp32** — input-side error would propagate through all
55
+ 12 blocks.
56
+
57
+ ## Accuracy
58
+
59
+ Measured on the RelativeDB golden batch (B=5, S=16) against the PyTorch
60
+ reference; identical on CPU and Metal/MPS:
61
+
62
+ | Metric | fp32 | int4 |
63
+ |---|---|---|
64
+ | `yhat` max abs. error vs. torch | 3.9e-3 | 1.5e-1 |
65
+ | `yhat` mean abs. error | 5.1e-4 | 2.4e-2 |
66
+ | target-score sign / ranking | preserved | preserved |
67
+
68
+ Int4 is the aggressive end for an 86M-param model: per-score drift is a few
69
+ hundredths. Use int8 when scores must track fp32 tightly; use int4 when
70
+ footprint/bandwidth dominates.
71
+
72
+ ## Usage (RelativeDB native engine)
73
+
74
+ ```bash
75
+ # direct path (looser golden gate for int4)
76
+ ./build/rt_test testdata classification/model.q4.safetensors --tol 100 --device mps
77
+
78
+ # via the Java / Python / Rust bindings: place the .q4 file next to the fp32
79
+ # checkpoint (or point at a directory containing it) and opt in with
80
+ export RELATIVEDB_RT_QUANTIZED=q4
81
+ ```
82
+
83
+ The C ABI (`rt_model_load`) accepts these files directly — the format is
84
+ auto-detected from the tensor dtypes. Quantized checkpoints currently run on
85
+ the CPU and Metal/MPS backends (CUDA is fp32-only).
86
+
87
+ ## Reproduce
88
+
89
+ ```bash
90
+ cmake -B build -S cpp && cmake --build build -j
91
+ ./build/rt_quantize <rt-j>/classification/model.safetensors classification/model.q4.safetensors --type q4
92
+ ./build/rt_quantize <rt-j>/regression/model.safetensors regression/model.q4.safetensors --type q4
93
+ ```
94
+
95
+ ## License & attribution
96
+
97
+ Derivative of [stanford-star/rt-j](https://huggingface.co/stanford-star/rt-j)
98
+ (Stanford STAR lab), redistributed under the same **CC-BY-NC-SA-4.0**
99
+ license. Architecture and training details are described in the upstream
100
+ model card; only the weight storage format differs here.
classification/config.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "codename": "rt-j-clf",
3
+ "name": "RT-J Classifier",
4
+ "task_type": "clf",
5
+ "checkpoint_file": "model.q4.safetensors",
6
+ "embedding_model": "all-MiniLM-L12-v2",
7
+ "d_text": 384,
8
+ "model": {
9
+ "num_blocks": 12,
10
+ "d_model": 512,
11
+ "d_text": 384,
12
+ "num_heads": 8,
13
+ "d_ff": 2048,
14
+ "materialize_attn_masks": true
15
+ },
16
+ "provenance": {
17
+ "run_id": "pjbmgvu2",
18
+ "swa_step": 58000,
19
+ "project": "2026-04-17",
20
+ "recipe": "real_mixed_v6_5_486t"
21
+ }
22
+ }
classification/model.q4.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be6e82c5861d38c399383989e554a22a167f4e50900e15d5ec2068237d8fe623
3
+ size 64023356
regression/config.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "codename": "rt-j-reg",
3
+ "name": "RT-J Regressor",
4
+ "task_type": "reg",
5
+ "checkpoint_file": "model.q4.safetensors",
6
+ "embedding_model": "all-MiniLM-L12-v2",
7
+ "d_text": 384,
8
+ "model": {
9
+ "num_blocks": 12,
10
+ "d_model": 512,
11
+ "d_text": 384,
12
+ "num_heads": 8,
13
+ "d_ff": 2048,
14
+ "materialize_attn_masks": true
15
+ },
16
+ "provenance": {
17
+ "run_id": "fsuj4wdl",
18
+ "swa_step": 18000,
19
+ "project": "2026-04-17",
20
+ "recipe": "real_mixed_v6_5_486t"
21
+ }
22
+ }
regression/model.q4.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:57004f5da01b0c0e10ed530407edc9498a5f0f70e826d9f36acca9d618bf4c97
3
+ size 64023356