Text Generation
Transformers
Safetensors
Vietnamese
English
kent
ssm
state-space-model
recurrent
linear-time
frequency-domain
dct
swiglu
custom_code
fp16
base
Instructions to use Vi-LAB/KenT-300M-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Vi-LAB/KenT-300M-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Vi-LAB/KenT-300M-Base", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Vi-LAB/KenT-300M-Base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Vi-LAB/KenT-300M-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Vi-LAB/KenT-300M-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Vi-LAB/KenT-300M-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Vi-LAB/KenT-300M-Base
- SGLang
How to use Vi-LAB/KenT-300M-Base with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Vi-LAB/KenT-300M-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Vi-LAB/KenT-300M-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Vi-LAB/KenT-300M-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Vi-LAB/KenT-300M-Base", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Vi-LAB/KenT-300M-Base with Docker Model Runner:
docker model run hf.co/Vi-LAB/KenT-300M-Base
Commit ·
ba698bf
1
Parent(s): 9220821
Update README.md
Browse files
README.md
CHANGED
|
@@ -22,41 +22,41 @@ tags:
|
|
| 22 |
|
| 23 |
# KenT
|
| 24 |
|
| 25 |
-
KenT
|
| 26 |
-
|
| 27 |
-
>
|
| 28 |
-
|
| 29 |
-
##
|
| 30 |
-
|
| 31 |
-
- **
|
| 32 |
-
|
| 33 |
-
- **
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
- **
|
| 37 |
-
|
| 38 |
-
- **
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
- **
|
| 42 |
-
|
| 43 |
-
- **
|
| 44 |
-
|
| 45 |
-
- **
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
##
|
| 52 |
-
|
| 53 |
-
| File |
|
| 54 |
|---|---|
|
| 55 |
-
| `model.py` |
|
| 56 |
-
| `config.json` |
|
| 57 |
-
| `generate_config.json` |
|
| 58 |
-
| `infer.py` |
|
| 59 |
-
| `model.safetensors` |
|
| 60 |
|
| 61 |
## Quickstart
|
| 62 |
|
|
@@ -64,20 +64,20 @@ Chi tiết cấu hình và công thức đầy đủ không được mô tả
|
|
| 64 |
pip install torch transformers
|
| 65 |
```
|
| 66 |
|
| 67 |
-
###
|
| 68 |
|
| 69 |
```python
|
| 70 |
import torch
|
| 71 |
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
|
| 72 |
|
| 73 |
-
repo = "Vi-LAB/KenT-100M-Base" #
|
| 74 |
tok = AutoTokenizer.from_pretrained(repo)
|
| 75 |
model = AutoModelForCausalLM.from_pretrained(
|
| 76 |
repo, trust_remote_code=True, torch_dtype=torch.float16
|
| 77 |
).to("cuda").eval()
|
| 78 |
gen_cfg = GenerationConfig.from_pretrained(repo, config_file_name="generate_config.json")
|
| 79 |
|
| 80 |
-
inputs = tok("
|
| 81 |
out = model.generate(
|
| 82 |
input_ids=inputs.input_ids,
|
| 83 |
attention_mask=inputs.attention_mask,
|
|
@@ -86,42 +86,42 @@ out = model.generate(
|
|
| 86 |
print(tok.decode(out[0], skip_special_tokens=True))
|
| 87 |
```
|
| 88 |
|
| 89 |
-
|
| 90 |
|
| 91 |
```python
|
| 92 |
out = model(**inputs, use_cache=True)
|
| 93 |
-
cache = out.cache_params #
|
| 94 |
out = model(input_ids=next_token, cache_params=cache, use_cache=True)
|
| 95 |
```
|
| 96 |
|
| 97 |
-
###
|
| 98 |
|
| 99 |
-
|
| 100 |
-
|
| 101 |
|
| 102 |
```python
|
| 103 |
from infer import prefill, stream
|
| 104 |
|
| 105 |
ids = tok(open("doc.txt", encoding="utf-8").read(), return_tensors="pt").input_ids[0]
|
| 106 |
|
| 107 |
-
# 1)
|
| 108 |
logits, cache = prefill(model, ids, chunk_size=1024, max_parallel_chunks=16)
|
| 109 |
|
| 110 |
-
# 2)
|
| 111 |
for token_id in stream(model, ids, gen_cfg):
|
| 112 |
print(tok.decode([token_id]), end="", flush=True)
|
| 113 |
```
|
| 114 |
|
| 115 |
-
|
| 116 |
|
| 117 |
```bash
|
| 118 |
python infer.py --model Vi-LAB/KenT-100M-Base --prompt-file doc.txt --chunk-size 1024
|
| 119 |
```
|
| 120 |
|
| 121 |
-
`cache.clone()`
|
| 122 |
|
| 123 |
-
##
|
| 124 |
|
| 125 |
-
-
|
| 126 |
-
-
|
| 127 |
-
-
|
|
|
|
| 22 |
|
| 23 |
# KenT
|
| 24 |
|
| 25 |
+
KenT is a recurrent language model from the SSM family. Rather than stacking more layers, KenT concentrates its capacity in the **depth of the transformation inside a single cell**, and keeps temporal memory as simple as possible.
|
| 26 |
+
|
| 27 |
+
> This repo contains `trust_remote_code` code; weights are stored in **FP16**.
|
| 28 |
+
|
| 29 |
+
## Architectural Philosophy
|
| 30 |
+
|
| 31 |
+
- **One cell, no layer stacking.** KenT is a single recurrent cell; the model is not replicated into multiple layers.
|
| 32 |
+
Depth comes not from the number of layers but from a chain of transformation blocks applied in sequence inside the cell.
|
| 33 |
+
- **Invest in the transformation core.** Capacity is concentrated in the "hidden" part, where features are actually transformed,
|
| 34 |
+
rather than in the vocabulary table or in repeating the architecture. The width and depth of this core are scaled together to
|
| 35 |
+
stay balanced, rather than pushing a single dimension.
|
| 36 |
+
- **Two streams, two roles.** One stream is a representation carrying information about the current token; the other is a memory
|
| 37 |
+
stream that aggregates history. The two streams meet only through learned projections and are never mixed directly.
|
| 38 |
+
- **Frequency as a fixed foundation, learning where it's needed.** Features are processed in the cosine-coefficient space using a
|
| 39 |
+
**fixed, non-learned** operator, interleaved with nonlinear blocks. The fixed part carries built-in structure; the learned part
|
| 40 |
+
focuses solely on transforming features.
|
| 41 |
+
- **Memory via simple accumulation.** History is summarized with a cumulative average: no dedicated parameters and no implicit
|
| 42 |
+
forgetting mechanism. The decoding state has **constant** size regardless of context length.
|
| 43 |
+
- **Two separate depth axes.** The depth of feature transformation within a single step and the length of history remembered are
|
| 44 |
+
two independent axes: increasing one does not change the other.
|
| 45 |
+
- **Chunk-parallelizable.** Because memory is an associative accumulation, a long document can be split into multiple chunks,
|
| 46 |
+
processed concurrently, and then merged, yielding the same result as sequential processing.
|
| 47 |
+
|
| 48 |
+
The points above are **design hypotheses** that need to be verified experimentally, not performance guarantees.
|
| 49 |
+
Detailed configuration and full formulas are not described here.
|
| 50 |
+
|
| 51 |
+
## Repo Structure
|
| 52 |
+
|
| 53 |
+
| File | Role |
|
| 54 |
|---|---|
|
| 55 |
+
| `model.py` | Model implementation (`KentConfig`, `KentModel`, `KentForCausalLM`, `KentCache`) |
|
| 56 |
+
| `config.json` | Standard model configuration |
|
| 57 |
+
| `generate_config.json` | Default generation configuration |
|
| 58 |
+
| `infer.py` | Parallel chunked prefix loading and the generation loop |
|
| 59 |
+
| `model.safetensors` | FP16 weights |
|
| 60 |
|
| 61 |
## Quickstart
|
| 62 |
|
|
|
|
| 64 |
pip install torch transformers
|
| 65 |
```
|
| 66 |
|
| 67 |
+
### Standard text generation (`generate`)
|
| 68 |
|
| 69 |
```python
|
| 70 |
import torch
|
| 71 |
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig
|
| 72 |
|
| 73 |
+
repo = "Vi-LAB/KenT-100M-Base" # replace with a repo id or a local directory
|
| 74 |
tok = AutoTokenizer.from_pretrained(repo)
|
| 75 |
model = AutoModelForCausalLM.from_pretrained(
|
| 76 |
repo, trust_remote_code=True, torch_dtype=torch.float16
|
| 77 |
).to("cuda").eval()
|
| 78 |
gen_cfg = GenerationConfig.from_pretrained(repo, config_file_name="generate_config.json")
|
| 79 |
|
| 80 |
+
inputs = tok("Hello, today", return_tensors="pt").to("cuda")
|
| 81 |
out = model.generate(
|
| 82 |
input_ids=inputs.input_ids,
|
| 83 |
attention_mask=inputs.attention_mask,
|
|
|
|
| 86 |
print(tok.decode(out[0], skip_special_tokens=True))
|
| 87 |
```
|
| 88 |
|
| 89 |
+
The recurrent state is returned as `cache_params` (similar to other SSM models in `transformers`):
|
| 90 |
|
| 91 |
```python
|
| 92 |
out = model(**inputs, use_cache=True)
|
| 93 |
+
cache = out.cache_params # recurrent state
|
| 94 |
out = model(input_ids=next_token, cache_params=cache, use_cache=True)
|
| 95 |
```
|
| 96 |
|
| 97 |
+
### Long documents: parallel chunked prefix loading
|
| 98 |
|
| 99 |
+
When processing in batches, each row of the batch is **one chunk of the same document**; the chunks are processed
|
| 100 |
+
in parallel with the `chunked=True` flag, and the final state is returned in `cache_params`.
|
| 101 |
|
| 102 |
```python
|
| 103 |
from infer import prefill, stream
|
| 104 |
|
| 105 |
ids = tok(open("doc.txt", encoding="utf-8").read(), return_tensors="pt").input_ids[0]
|
| 106 |
|
| 107 |
+
# 1) load the prefix only, get the last token's logits and the state
|
| 108 |
logits, cache = prefill(model, ids, chunk_size=1024, max_parallel_chunks=16)
|
| 109 |
|
| 110 |
+
# 2) load the prefix, then generate (streaming)
|
| 111 |
for token_id in stream(model, ids, gen_cfg):
|
| 112 |
print(tok.decode([token_id]), end="", flush=True)
|
| 113 |
```
|
| 114 |
|
| 115 |
+
Command line:
|
| 116 |
|
| 117 |
```bash
|
| 118 |
python infer.py --model Vi-LAB/KenT-100M-Base --prompt-file doc.txt --chunk-size 1024
|
| 119 |
```
|
| 120 |
|
| 121 |
+
`cache.clone()` lets you reuse the same prefix to generate multiple different branches without reloading it.
|
| 122 |
|
| 123 |
+
## Notes
|
| 124 |
|
| 125 |
+
- Memory is a uniform cumulative average over every timestep seen; the model does not learn to forget or to select on its own.
|
| 126 |
+
- The tokenizer and weights must match `vocab_size` in `config.json`.
|
| 127 |
+
- This is a research model; please evaluate it before using it for real-world tasks.
|