Views
No views yet
1import torch
2from transformers import AutoTokenizer
3
4# Option A: load the merged checkpoint (no LoRA needed)
5state = torch.load("merged.pt", map_location="cpu")
6
7# Option B: load via the kompress package
8from kompress.model.architecture import HeadroomCompressorV2
9from kompress.model.config import V2_BASE
10import json
11
12with open("config.json") as f:
13 cfg_dict = json.load(f)
14cfg = V2_BASE # or rebuild from cfg_dict
15model = HeadroomCompressorV2(cfg)
16model.load_state_dict(torch.load("merged.pt", map_location="cpu"), strict=False)
17model.eval().cuda()
18
19tokenizer = AutoTokenizer.from_pretrained("chopratejas/kompress-v2-base")
20
21# Compress
22text = "The quick brown fox jumps over the lazy dog."
23enc = tokenizer(text, return_tensors="pt").to("cuda")
24with torch.no_grad():
25 out = model(**enc)
26scores = out["final_scores"][0] # P(keep) per subword
27keep = (scores >= 0.5)
28kept_tokens = enc["input_ids"][0][keep]
29print(tokenizer.decode(kept_tokens, skip_special_tokens=True))final_scores ∈ [0, 1] per subword. Adjust the threshold to
trade compression aggressiveness for must-keep recall.| Threshold | keep_rate | must_keep_recall | F1 | best for |
|---|---|---|---|---|
| 0.30 | 0.917 (8% drop) | 0.994 | 0.904 | Conservative |
| 0.40 | 0.867 (13% drop) | 0.987 | 0.913 | Safe |
| 0.50 (default) | 0.815 (18% drop) | 0.974 | 0.918 | Balanced |
| 0.60 | 0.765 (23% drop) | 0.950 | 0.915 | Aggressive |
| 0.70 | 0.705 (30% drop) | 0.908 | 0.898 | Very aggressive |
min_drop_ratio=0.05 filtering and
same-conversation packing.config.json # KompressV2Config + arch metadata
model.safetensors # ~600 MB — best checkpoint, LoRA merged into the encoder
merged.pt # ~600 MB — full state dict, alias for safetensors load
tokenizer.json # ModernBERT-base tokenizer
tokenizer_config.json
special_tokens_map.json
adapter/ # LoRA adapter ONLY (~30 MB), for stacking per-org adapters
adapter_config.json
adapter_model.safetensors
token_head.pt
span_conv.pt
export_coreml.py # CoreML conversion script (added for Apple Silicon optimization)
coreml/ # Compiled CoreML packages
kompress.mlpackage # Optimized ANE-ready CoreML model
README.md # this file1pip install coremltools torch transformers numpy
2python3 export_coreml.py.mlpackage in your Swift application using the MLMultiArray interface:1import CoreML
2
3// inputIds: [Int32], attentionMask: [Int32]
4let idsArray = try MLMultiArray(shape: [1, NSNumber(value: inputIds.count)], dataType: .int32)
5let maskArray = try MLMultiArray(shape: [1, NSNumber(value: attentionMask.count)], dataType: .int32)
6
7// Populate arrays and call prediction...
8let model = try kompress(configuration: MLModelConfiguration())
9let output = try model.prediction(input_ids: idsArray, attention_mask: maskArray)
10let scores = output.final_scores // per-token Float32 P(keep)chopratejas/kompress-v2-large
— larger variant (ModernBERT-large, 395M params, private/enterprise)