LatentPort
LatentPort makes LLM internal states programmable.
Created by Simon P. Villani.
Capture a model's working memory as a reusable snapshot. Use it to continue inference, transfer memory to a compatible model, compact attention memory, combine contexts, or branch and save state for later use.
Website | Get started | State operations | Supported transformations | Cookbook | API
Get started
Install the base package with Python 3.11 or later.
python -m pip install latentport
The example uses BF16. After setting up CUDA-enabled PyTorch and the CUDA build environment, install the backend and check readiness. Platform requirements and other backend options are in the installation guide.
python -m pip install --no-build-isolation "latentport[bf16]"
latentport doctor --backend bf16
Read a prompt into working memory and use the snapshot to start a session.
LatentPort downloads the pinned model on first use if needed. Set
LATENTPORT_HOME to choose its cache directory.
import latentport as lp
with lp.load_model("Qwen/Qwen3.5-4B", backend="bf16") as model:
state = model.capture([("user", "The ticket is red.")])
with model.session(state) as session:
print(session.ask("What color is the ticket?").text)
State operations
| Operation | API | Purpose |
|---|---|---|
| Capture | model.capture(context) |
Read context into a reusable inference snapshot. |
| Transfer | bridge.translate(state) |
Translate a snapshot for a compatible target model without replaying the source context. |
| Compact | state.compact() |
Reduce the attention key/value (KV) storage used by a snapshot. |
| Combine | model.combine(left, right) |
Continue the left state by replaying the right context. |
| Append | model.append(state, text) |
Process new input from an existing state. |
| Fork | state.fork(2) |
Create independent branches that share immutable snapshot storage. |
| Save / load | state.save(path) / lp.State.load(path) |
Persist and restore a snapshot without reading the original prompt again. |
Snapshots record the exact model and runtime that created them. They contain prompt-derived tensors and conversation text, so protect them like the original conversation. State ownership and persistence
Transfer working memory
A bridge lets the target model continue from the source model's working memory.
Pass the bridge repository to lp.load() to select the model pair.
Supported bridges
import latentport as lp
with lp.load("latentport/LPBridge-Qwen3.5-4b-Qwen3.5-9b", backend="bf16") as port:
state = port.source.capture([("user", "The ticket is red.")])
transferred = port.bridge.translate(state)
with port.target.session(transferred) as session:
print(session.ask("What color is the ticket?").text)
Compact working memory
LPCompact uses a learned selector to reduce attention KV storage while preserving original token positions, recurrent state and convolution state. After capturing a long history, compact its snapshot and continue with the same open model.
compacted = state.compact()
with model.session(compacted) as session:
print(session.ask("What should we do next?").text)
By default, compaction retains one eighth of attention KV once the snapshot has at least 65,536 retained positions. Compaction guide
Supported transformations
Each bridge is directional and requires dense source state with complete alignment metadata. Its model card specifies supported checkpoints, backends and transfer boundaries.
| Source model | Target model | Bridge repository |
|---|---|---|
| Qwen3.5-4B | Qwen3.5-9B | latentport/LPBridge-Qwen3.5-4b-Qwen3.5-9b |
| Qwen3.5-4B | Qwen3.8-27B | latentport/LPBridge-Qwen3.5-4b-Qwen3.8-27b |
For compaction, pass the base model ID to lp.load_model(). The runtime matches
the selector to the snapshot. For combination, pass an LPCombine profile ID to
lp.load_model() and use two snapshots from the same model and runtime. All six
profiles support retained-token replay with BF16, NF4 and GGUF. Cache-only replay
(method="cache") depends on the profile and backend.
| Base model ID | LPCompact selector | LPCombine profile ID | LPCombine cache-only backends |
|---|---|---|---|
Qwen/Qwen3.5-4B |
LPCompact-Qwen3.5-4B | latentport/LPCombine-Qwen3.5-4B |
BF16, NF4 |
Qwen/Qwen3.5-9B |
LPCompact-Qwen3.5-9B | latentport/LPCombine-Qwen3.5-9B |
BF16, NF4 |
Qwen/Qwen3.8-27B |
LPCompact-Qwen3.8-27B | latentport/LPCombine-Qwen3.8-27b |
NF4 |
Qwen/Qwen3.8-Flash-Next |
LPCompact-Qwen3.8-Flash-Next | latentport/LPCombine-Qwen3.8-Flash-Next |
BF16 |
google/gemma-4-31B-it |
LPCompact-Gemma-4-31B-it | latentport/LPCombine-Gemma-4-31B-it |
BF16 |
Qwen/Qwen3-14B |
LPCompact-Qwen3-14B | latentport/LPCombine-Qwen3-14B |
BF16 |
For a standalone GGUF model, pass the file as model_path. For split
checkpoints, keep the shards together and pass the first file. Runtime
requirements depend on the model and operation.
Compaction compatibility · Combination API
Validation and performance
Published measurements describe specific checkpoints, hardware and workloads.
- Transfer. The historical resident 4B-to-27B test measured a 2.19x paired time-to-first-token speedup at approximately 16K tokens against the native 27B model. Methodology · Results
- Compact. At 128K context, 8x compaction reduced attention KV from 4 GiB to 512 MiB on Qwen3.5-4B/9B and from 8 GiB to 1 GiB on Qwen3.8-27B. Compaction results · Backend validation
Demos and documentation
- Chat through a supported bridge with the chat example.
- Query two saved snapshots with the combination example.
- Set up the native or Docker browser demo with the installation guide.
- Try context transfer, specialist branches and repair checks in the memory transplant demo.
- Explore cached conversations, branching, persistence and append in the state demos.
- Find usage recipes and backend contracts in the cookbook and API reference.
- Native integration and contributing.
Report reproducible issues at GitHub Issues.
Include python -m latentport doctor, exact model identities and a minimal example
with private prompts and credentials removed.
Project
LatentPort is an independent AI research project. It began with a September 2026 paper, LatentPort: Beyond KV Cache. Research directions include learned optimisation, combination and automatic policy selection.
Original research code | Transformation models | Python package
License
The LatentPort runtime and transformation weights are Apache-2.0. Base models retain their upstream licenses, and llama.cpp retains its MIT license. See LICENSE and the notices supplied with model and native downloads.
Metadata
Release files for latentport 0.4.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| latentport-0.4.11.tar.gz | 6.8 MB | Without provenance | Details for latentport-0.4.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| latentport-0.4.11-py3-none-any.whl | Python 3 | none | any | Details for latentport-0.4.11-py3-none-any.whl |
Total release size: 7.8 MB
Release files / latentport-0.4.11.tar.gz
| Download URL | latentport-0.4.11.tar.gz |
|---|---|
| Size | 6.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5d77385b58cf15013cc685c21f2be983e0720e468ee3c9bfc3b750291be82756
|
|
BLAKE2b-256 checksum How to use checksums |
d0c08f4bda37479ee5f12a0ba46856e6cd5d90b3400409375986bb8e9286d605
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Release files / latentport-0.4.11-py3-none-any.whl
| Download URL | latentport-0.4.11-py3-none-any.whl |
|---|---|
| Size | 1.0 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
040523dbe78f73bbabc8b30c279ecd65aff50d9d7f5c2f86bb0ef9a5694613ed
|
|
BLAKE2b-256 checksum How to use checksums |
cb02bd133e38cbbf346174517104cb614d04542fedfa3221a23714f5d5e1c931
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Security for latentport 0.4.11
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.