KLM: Research-Grade TPU-Native Language Model Framework
Package name: klm | Author: Niranjan Kumar K. | Version: 1.0.0 | License: Apache-2.0
An advanced, scalable, research-grade language model training and inference framework optimized exclusively for Google Colab TPU accelerators using JAX and XLA, featuring a 100% backward-compatible pure-Python CPU reference implementation.
Backward compatibility:
import slmandfrom slm import *continue to work — theslmshim re-exports everything fromklm.
See the user guide, the Google Colab TPU guide, the benchmark report, and the automated test report.
Highlights
- TPU-Native JAX/XLA Engine: High-throughput training on Google Colab TPU (v2-8, v3-8, v4-8) with bfloat16 mixed precision and float32 master weights.
- Advanced Architecture: Causal multi-head attention, vectorized RoPE, numerically stable RMSNorm in float32, SwiGLU feed-forward networks, and pre-normalization.
- Sequence Packing: Static-shape sequence multi-packing with 2D block-diagonal causal masks and padding-aware loss masks.
- Multi-Device TPU Scaling: Automatic topology inspection, JAX device mesh, and
NamedShardingacross TPU cores. - Dedicated Instruction Tuning: SFT pipeline supporting QA, Alpaca-style instruction-response, multi-turn, reasoning, and math datasets with assistant-only loss masking.
- Inference Optimization: Stateful KV-caching for O(1) decoding, greedy search, temperature, top-k, nucleus top-p, and repetition penalties.
- Data Quality Intelligence: Multi-stage cleaning, unicode NFKC, mojibake repair, HTML/boilerplate stripping, SimHash deduplication, 10-domain classification, and zero-leakage disjoint splitting.
- Comprehensive Evaluation: Top-1, Top-5, Top-10 token accuracy, word accuracy, perplexity, Expected Calibration Error (ECE), and long-context position-bucket evaluation.
- Safe Migration & Recovery: Atomic checkpoint saving with SHA-256 parameter checksums and backward-compatible v4-to-v5
.knimigration.
Installation
# Base install (pure Python stdlib — no external dependencies)
pip install klm
# With TPU acceleration (Google Colab TPU)
pip install "klm[tpu]"
# With GPU acceleration (CUDA)
pip install "klm[gpu]"
# With CPU-only JAX
pip install "klm[cpu]"
Quick Start
from klm import *
# Initialize model (backend="auto" uses TPU if present, falls back to CPU)
model = klm(
vocab_size=512,
context_length=128,
d_model=64,
heads=4,
layers=2,
ff_dim=128,
learning_rate=3e-4,
weight_decay=0.01,
)
# Train on a folder of documents
report = model.train(
"folder_path",
epochs=3,
batch_size=4,
gradient_accumulation_steps=2,
checkpoint_path="models/my_model.kni",
use_advanced_cleaning=True,
)
# Fast KV-cached text generation
output = model.predict("The research showed that", max_tokens=80, temperature=0.7, top_p=0.9)
print(output)
Use model.save("models/name") and model.load("models/name") to store or restore a model. The only accepted model extension is .kni; it is added automatically when omitted.
Backward Compatibility
The slm package name is preserved as a shim. Existing code using from slm import * or import slm continues to work without any changes.
# Legacy code — still works unchanged
from slm import *
model = slm(vocab_size=512)
Metadata
Release files for build-slm 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| build_slm-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for build_slm-1.0.0-py3-none-any.whl |
Release files / build_slm-1.0.0-py3-none-any.whl
| Download URL | build_slm-1.0.0-py3-none-any.whl |
|---|---|
| Size | 62.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0cec8a35e080c307898a146de420cff98fce48d4e3e49ae40f030cda1862b9d9
|
|
BLAKE2b-256 checksum How to use checksums |
c0b80bab2636b2005f587376df3d8f20cea156ae2b62fbfc8e6fdf922fb07d92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.15.2
|
Security for build-slm 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.