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
Upload 4 files
Browse files
README.md
CHANGED
|
@@ -10,10 +10,6 @@ tags:
|
|
| 10 |
- dct
|
| 11 |
- swiglu
|
| 12 |
- custom_code
|
| 13 |
-
- base
|
| 14 |
-
datasets:
|
| 15 |
-
- HuggingFaceFW/fineweb-edu
|
| 16 |
-
- wikimedia/wikipedia
|
| 17 |
---
|
| 18 |
|
| 19 |
# KenT-300M-Base
|
|
@@ -29,7 +25,7 @@ H_i[t+1] = (1 - A_i) ⊙ H_i[t] + A_i ⊙ u_i # Learnable EMA Matrix, A = si
|
|
| 29 |
|
| 30 |
S = Σ_i H_i[t+1] # Add
|
| 31 |
y = S · D # "DCT-II Proj (D)" (DCT ngược)
|
| 32 |
-
out = y + SwiGLU(RMSNorm(y))
|
| 33 |
logits = LM_head(RMSNorm_f(out)) # tied với embedding
|
| 34 |
```
|
| 35 |
|
|
@@ -48,12 +44,10 @@ D là ma trận DCT-II trực chuẩn cố định (hàng = tần số, vector h
|
|
| 48 |
EMA khởi tạo theo cấp số nhân từ 0.5 (tap đầu, feature đầu) đến 0.01 (tap cuối, feature cuối); vẫn học được.
|
| 49 |
EMA chạy FP32 bằng affine-scan log-depth, kết quả bằng đúng hồi quy tuần tự.
|
| 50 |
|
| 51 |
-

|
| 52 |
-
|
| 53 |
```python
|
| 54 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 55 |
tok = AutoTokenizer.from_pretrained("Vi-LAB/KenT-300M-Base", trust_remote_code=True)
|
| 56 |
model = AutoModelForCausalLM.from_pretrained("Vi-LAB/KenT-300M-Base", trust_remote_code=True)
|
| 57 |
```
|
| 58 |
|
| 59 |
-
Hoặc `python infer.py --model Vi-LAB/KenT-300M-Base --prompt "Today the weather is"`.
|
|
|
|
| 10 |
- dct
|
| 11 |
- swiglu
|
| 12 |
- custom_code
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
# KenT-300M-Base
|
|
|
|
| 25 |
|
| 26 |
S = Σ_i H_i[t+1] # Add
|
| 27 |
y = S · D # "DCT-II Proj (D)" (DCT ngược)
|
| 28 |
+
out = x[t] + y + SwiGLU(RMSNorm(y)) # 2 skip: sau phép chiếu D và từ đầu vào gốc x[t]
|
| 29 |
logits = LM_head(RMSNorm_f(out)) # tied với embedding
|
| 30 |
```
|
| 31 |
|
|
|
|
| 44 |
EMA khởi tạo theo cấp số nhân từ 0.5 (tap đầu, feature đầu) đến 0.01 (tap cuối, feature cuối); vẫn học được.
|
| 45 |
EMA chạy FP32 bằng affine-scan log-depth, kết quả bằng đúng hồi quy tuần tự.
|
| 46 |
|
|
|
|
|
|
|
| 47 |
```python
|
| 48 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 49 |
tok = AutoTokenizer.from_pretrained("Vi-LAB/KenT-300M-Base", trust_remote_code=True)
|
| 50 |
model = AutoModelForCausalLM.from_pretrained("Vi-LAB/KenT-300M-Base", trust_remote_code=True)
|
| 51 |
```
|
| 52 |
|
| 53 |
+
Hoặc `python infer.py --model Vi-LAB/KenT-300M-Base --prompt "Today the weather is"`.
|
config.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
| 19 |
"pad_token_id": 50256,
|
| 20 |
"bos_token_id": 50256,
|
| 21 |
"eos_token_id": 50256,
|
| 22 |
-
"dtype": "
|
| 23 |
"ema_alpha_first": 0.5,
|
| 24 |
"ema_alpha_last": 0.01,
|
| 25 |
"use_gradient_checkpointing": false
|
|
|
|
| 19 |
"pad_token_id": 50256,
|
| 20 |
"bos_token_id": 50256,
|
| 21 |
"eos_token_id": 50256,
|
| 22 |
+
"dtype": "bfloat16",
|
| 23 |
"ema_alpha_first": 0.5,
|
| 24 |
"ema_alpha_last": 0.01,
|
| 25 |
"use_gradient_checkpointing": false
|
infer.py
CHANGED
|
@@ -28,8 +28,8 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
|
|
| 28 |
# --------------------------------------------------------------------------- #
|
| 29 |
def load(model_id: str, device: Optional[str] = None, dtype: Optional[torch.dtype] = None):
|
| 30 |
device = device or ("cuda" if torch.cuda.is_available() else "cpu")
|
| 31 |
-
if dtype is None: #
|
| 32 |
-
dtype = torch.
|
| 33 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 34 |
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
|
| 35 |
model = model.to(device=device, dtype=dtype).eval()
|
|
|
|
| 28 |
# --------------------------------------------------------------------------- #
|
| 29 |
def load(model_id: str, device: Optional[str] = None, dtype: Optional[torch.dtype] = None):
|
| 30 |
device = device or ("cuda" if torch.cuda.is_available() else "cpu")
|
| 31 |
+
if dtype is None: # BF16 trên GPU; CPU dùng FP32 vì nhiều phép FP16 chậm/không hỗ trợ
|
| 32 |
+
dtype = torch.bfloat16 if device.startswith("cuda") else torch.float32
|
| 33 |
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
| 34 |
model = AutoModelForCausalLM.from_pretrained(model_id, trust_remote_code=True)
|
| 35 |
model = model.to(device=device, dtype=dtype).eval()
|
model.py
CHANGED
|
@@ -11,7 +11,7 @@ Mỗi bước nhận ĐÚNG MỘT token x[t] (vector 1 x D); lịch sử nằm h
|
|
| 11 |
|
| 12 |
S = sum_i H_i[t+1] # Add
|
| 13 |
y = S · D # "DCT-II Proj (D)": DCT ngược (D trực chuẩn, D^T D = I)
|
| 14 |
-
out = y + SwiGLU( RMSNorm(y) )
|
| 15 |
logits = LM_head( RMSNorm_f(out) ) # head buộc chung trọng số với embedding
|
| 16 |
|
| 17 |
Quy ước hàng: x là vector hàng nên DCT-II là x·D^T (D[k, i] = α_k cos(π(i+½)k/D), hàng = tần số k, cột = vị trí i)
|
|
@@ -22,7 +22,7 @@ bằng DCT ngược.
|
|
| 22 |
toàn mô hình chỉ là H shape (n+1, D): O(1) theo độ dài chuỗi.
|
| 23 |
|
| 24 |
EMA là hồi quy tuyến tính theo từng kênh nên song song hóa được theo thời gian bằng affine-scan log-depth
|
| 25 |
-
(Hillis-Steele): kết quả bằng đúng hồi quy tuần tự. EMA và RMSNorm chạy ở FP32; trọng số lưu ở
|
| 26 |
|
| 27 |
RMSNorm cuối (`norm_f`) trước LM head không có trong sơ đồ; thêm vào để logits ổn định.
|
| 28 |
"""
|
|
@@ -417,7 +417,8 @@ class KentModel(KentPreTrainedModel):
|
|
| 417 |
# --- Add -> DCT-II Proj (D) -> RMSNorm -> SwiGLU -> Add
|
| 418 |
s = h.sum(dim=2).to(feats[0].dtype)
|
| 419 |
y = idct2(s)
|
| 420 |
-
|
|
|
|
| 421 |
y = self.norm_f(y) # (1, K*C, D) nếu chunked
|
| 422 |
if chunked:
|
| 423 |
y = y.reshape(1, b * t, d)
|
|
|
|
| 11 |
|
| 12 |
S = sum_i H_i[t+1] # Add
|
| 13 |
y = S · D # "DCT-II Proj (D)": DCT ngược (D trực chuẩn, D^T D = I)
|
| 14 |
+
out = x[t] + y + SwiGLU( RMSNorm(y) ) # RMSNorm -> SwiGLU -> Add: skip lấy sau phép chiếu D VÀ skip từ đầu vào gốc x[t]
|
| 15 |
logits = LM_head( RMSNorm_f(out) ) # head buộc chung trọng số với embedding
|
| 16 |
|
| 17 |
Quy ước hàng: x là vector hàng nên DCT-II là x·D^T (D[k, i] = α_k cos(π(i+½)k/D), hàng = tần số k, cột = vị trí i)
|
|
|
|
| 22 |
toàn mô hình chỉ là H shape (n+1, D): O(1) theo độ dài chuỗi.
|
| 23 |
|
| 24 |
EMA là hồi quy tuyến tính theo từng kênh nên song song hóa được theo thời gian bằng affine-scan log-depth
|
| 25 |
+
(Hillis-Steele): kết quả bằng đúng hồi quy tuần tự. EMA và RMSNorm chạy ở FP32; trọng số lưu ở BF16.
|
| 26 |
|
| 27 |
RMSNorm cuối (`norm_f`) trước LM head không có trong sơ đồ; thêm vào để logits ổn định.
|
| 28 |
"""
|
|
|
|
| 417 |
# --- Add -> DCT-II Proj (D) -> RMSNorm -> SwiGLU -> Add
|
| 418 |
s = h.sum(dim=2).to(feats[0].dtype)
|
| 419 |
y = idct2(s)
|
| 420 |
+
x0 = feats[0].reshape(1, b * t, d) if chunked else feats[0] # đầu vào gốc x[t] (embedding)
|
| 421 |
+
y = x0 + y + self.out_mlp(self.out_norm(y)) # Add: skip sau D + skip đầu vào gốc
|
| 422 |
y = self.norm_f(y) # (1, K*C, D) nếu chunked
|
| 423 |
if chunked:
|
| 424 |
y = y.reshape(1, b * t, d)
|