FastAPI server wrapping chopratejas/kompress-v2-base for token-level importance scoring and context compression.
Drop low-scoring tokens before sending prompts to an LLM. The model is a ModernBERT-base + LoRA + span-conv head, exported as INT8 ONNX (~261 MB) for fast CPU inference.
/compress — keep top-N% most important tokens, return reconstructed text/score — return per-token importance scores as JSON/reload — switch INT8 ↔ FP32 at runtime/health — model status + load time# 1. Create venv
python -m venv ~/venvs/kompress
source ~/venvs/kompress/bin/activate
# 2. Install this package (editable)
cd kompress-api-server
pip install -e .
# 3. Download the model (INT8 only — ~261 MB)
huggingface-cli download chopratejas/kompress-v2-base \
--include "onnx/kompress-int8-wo.onnx" "*tokenizer*" "*config*"
If you prefer FP32 (~573 MB, slightly more accurate):
huggingface-cli download chopratejas/kompress-v2-base \
--include "onnx/*.onnx" "*tokenizer*" "*config*"
# Option 1: CLI entry point (after `pip install -e .`)
kompress-api-server --port 7777
# Option 2: uvicorn directly
python -m uvicorn kompress_api.server:app --host 0.0.0.0 --port 7777 --reload
# Option 3: programmatic
python -c "from kompress_api.server import app; import uvicorn; uvicorn.run(app, port=7777)"
OpenAPI docs at http://localhost:7777/docs.
GET /health{
"status": "ok",
"version": "1.0.0",
"model": "chopratejas/kompress-v2-base",
"quant": "int8",
"model_loaded": true,
"load_time_s": 0.34
}
POST /compresscurl -X POST http://localhost:7777/compress \
-H "Content-Type: application/json" \
-d '{
"text": "The quick brown fox jumps over the lazy dog.",
"keep_ratio": 0.5,
"max_length": 512
}'
Response:
{
"compressed": " quick brown fox over lazy dog",
"n_total": 12,
"n_kept": 8,
"kept_pct": 66.7
}
POST /scorecurl -X POST http://localhost:7777/score \
-H "Content-Type: application/json" \
-d '{"text": "Hello world from Kompress API", "max_length": 64}'
Response:
{
"tokens": [
{"i": 0, "tok": "[CLS]", "id": 50281, "score": 0.605244, "special": true},
{"i": 1, "tok": "Hello", "id": 12092, "score": 0.907625, "special": false},
{"i": 2, "tok": "\u0120world", "id": 1533, "score": 0.970307, "special": false},
...
]
}
POST /reload?quant=fp32Swap quantization at runtime:
curl -X POST "http://localhost:7777/reload?quant=fp32"
import httpx
with httpx.Client(base_url="http://localhost:7777") as c:
r = c.post("/compress", json={
"text": "long prompt here...",
"keep_ratio": 0.4,
})
r.raise_for_status()
print(r.json()["compressed"])
pip install -e ".[dev]"
pytest tests/ -v
The test suite hits a running server (set KOMPRESS_URL=http://localhost:7777).
max_length up to 2048.model.load().kompress-api-server/
├── pyproject.toml
├── README.md
├── src/
│ └── kompress_api/
│ ├── __init__.py
│ ├── model.py # core ONNX + tokenizer wrapper
│ └── server.py # FastAPI app
├── tests/
│ └── test_api.py
└── examples/
├── requests_examples.py
└── basic.sh
MIT.
Model: see chopratejas/kompress-v2-base for upstream terms.
2 commits
Python
100.0%
FastAPI server wrapping chopratejas/kompress-v2-base for token-level importance scoring and context compression.
Drop low-scoring tokens before sending prompts to an LLM. The model is a ModernBERT-base + LoRA + span-conv head, exported as INT8 ONNX (~261 MB) for fast CPU inference.
/compress — keep top-N% most important tokens, return reconstructed text/score — return per-token importance scores as JSON/reload — switch INT8 ↔ FP32 at runtime/health — model status + load time# 1. Create venv
python -m venv ~/venvs/kompress
source ~/venvs/kompress/bin/activate
# 2. Install this package (editable)
cd kompress-api-server
pip install -e .
# 3. Download the model (INT8 only — ~261 MB)
huggingface-cli download chopratejas/kompress-v2-base \
--include "onnx/kompress-int8-wo.onnx" "*tokenizer*" "*config*"
If you prefer FP32 (~573 MB, slightly more accurate):
huggingface-cli download chopratejas/kompress-v2-base \
--include "onnx/*.onnx" "*tokenizer*" "*config*"
# Option 1: CLI entry point (after `pip install -e .`)
kompress-api-server --port 7777
# Option 2: uvicorn directly
python -m uvicorn kompress_api.server:app --host 0.0.0.0 --port 7777 --reload
# Option 3: programmatic
python -c "from kompress_api.server import app; import uvicorn; uvicorn.run(app, port=7777)"
OpenAPI docs at http://localhost:7777/docs.
GET /health{
"status": "ok",
"version": "1.0.0",
"model": "chopratejas/kompress-v2-base",
"quant": "int8",
"model_loaded": true,
"load_time_s": 0.34
}
POST /compresscurl -X POST http://localhost:7777/compress \
-H "Content-Type: application/json" \
-d '{
"text": "The quick brown fox jumps over the lazy dog.",
"keep_ratio": 0.5,
"max_length": 512
}'
Response:
{
"compressed": " quick brown fox over lazy dog",
"n_total": 12,
"n_kept": 8,
"kept_pct": 66.7
}
POST /scorecurl -X POST http://localhost:7777/score \
-H "Content-Type: application/json" \
-d '{"text": "Hello world from Kompress API", "max_length": 64}'
Response:
{
"tokens": [
{"i": 0, "tok": "[CLS]", "id": 50281, "score": 0.605244, "special": true},
{"i": 1, "tok": "Hello", "id": 12092, "score": 0.907625, "special": false},
{"i": 2, "tok": "\u0120world", "id": 1533, "score": 0.970307, "special": false},
...
]
}
POST /reload?quant=fp32Swap quantization at runtime:
curl -X POST "http://localhost:7777/reload?quant=fp32"
import httpx
with httpx.Client(base_url="http://localhost:7777") as c:
r = c.post("/compress", json={
"text": "long prompt here...",
"keep_ratio": 0.4,
})
r.raise_for_status()
print(r.json()["compressed"])
pip install -e ".[dev]"
pytest tests/ -v
The test suite hits a running server (set KOMPRESS_URL=http://localhost:7777).
max_length up to 2048.model.load().kompress-api-server/
├── pyproject.toml
├── README.md
├── src/
│ └── kompress_api/
│ ├── __init__.py
│ ├── model.py # core ONNX + tokenizer wrapper
│ └── server.py # FastAPI app
├── tests/
│ └── test_api.py
└── examples/
├── requests_examples.py
└── basic.sh
MIT.
Model: see chopratejas/kompress-v2-base for upstream terms.
2 commits
Python
100.0%