Skip to main content

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.

LatentPort: programmable model state

Website | Get started | State operations | Supported transformations | Cookbook | API

License: Apache-2.0 PyPI

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
Qwen/Qwen3.6-35B-A3B LPCompact-Qwen3.6-35B-A3B (BF16, NF4, GGUF) — —

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

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.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for latentport 0.4.13
File Size Uploaded Provenance Actions
latentport-0.4.13.tar.gz 6.8 MB Without provenance Details for latentport-0.4.13.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for latentport 0.4.13
File Interpreter ABI Platform Actions
latentport-0.4.13-py3-none-any.whl Python 3 none any Details for latentport-0.4.13-py3-none-any.whl

Total release size: 7.8 MB

Release files / latentport-0.4.13.tar.gz

Download URL latentport-0.4.13.tar.gz
Size 6.8 MB
Tags Source
SHA-256 checksum
How to use checksums
593ce58db65510e06d06192f08e908289a834035db9559fd1007eb2a5690314e
BLAKE2b-256 checksum
How to use checksums
e4f7b725203f4cadaf021655d4d6bf9b2d49df2655aca910bdb6d99d20fbdf4c
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.13-py3-none-any.whl

Download URL latentport-0.4.13-py3-none-any.whl
Size 1.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
8b126b45251addc08d9b56e17dcb560ae386dcceb31855d84781ec5d76f6e34a
BLAKE2b-256 checksum
How to use checksums
105d828a75036895ba32888644df90ecf5889917deaf983bed205c37e11b8dbb
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.13

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page