plato-maps
Minimal, closed-form Plato's Key maps for cross-model LLM representation transfer — as easy to use and share as LoRAs.
Note:
plato-mapsis an independent, unofficial open-source implementation inspired by Hazy Research's blog post Plato's Key (Vivien Cheng, Jerry Liu, Morris Yau, and Chris Ré, Nov 2026).
No training loops. No gradients. Just an orthogonal (or semi-orthogonal) Procrustes rotation and a single global scale factor stored in .safetensors with full provenance metadata.
One-liner usage
from plato_maps import Map
# Load a precomputed map from Hugging Face Hub and translate a donor key:
z_b = Map.from_hub("your-org/plato-map-qwen-to-llama")(z_a)
Or fit and apply in one line from paired hidden states:
z_b = Map.fit(keys_a, keys_b)(z_a)
Installation
Core library (minimal dependencies: torch, safetensors, numpy):
pip install plato-maps
With Hugging Face Transformers support (for extract_keys and the demo):
pip install "plato-maps[transformers]"
Load a precomputed map
Maps are saved as standard .safetensors files with human-readable header metadata (source_model, target_model, source_layer, target_layer, in_dim, out_dim, scale, r2, cosine_similarity, etc.):
from plato_maps import Map
# From Hugging Face Hub (auto-discovers map.safetensors or the unique .safetensors file)
key_map = Map.from_hub("your-org/plato-map-qwen2.5-to-llama3.1")
# Or specify a filename explicitly:
# key_map = Map.from_hub("your-org/plato-maps", filename="qwen7b_l14_to_llama8b_l16.safetensors")
# Or from a local file
key_map = Map.load("qwen_to_llama.safetensors")
print(key_map)
print(key_map.metadata)
# Translate any (..., in_dim) tensor or numpy array (no gradients)
z_recipient = key_map(z_donor)
Fit your own map
Use extract_keys to pull paired hidden states from any two Hugging Face Transformers models, then fit in closed form via thin SVD:
from transformers import AutoModelForCausalLM, AutoTokenizer
from plato_maps import Map, extract_keys
prompts = [
"The capital of Japan",
"The capital of Italy",
"The capital of Brazil",
# ... ~100–1,000 diverse anchor prompts
]
donor_tok = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-1.5B")
donor = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-1.5B").eval()
recip_tok = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-0.5B")
recip = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-0.5B").eval()
keys_a = extract_keys(donor, donor_tok, prompts, layer=14, position="last")
keys_b = extract_keys(recip, recip_tok, prompts, layer=12, position="last")
key_map = Map.fit(
keys_a,
keys_b,
source_model="Qwen/Qwen2.5-1.5B",
target_model="Qwen/Qwen2.5-0.5B",
source_layer=14,
target_layer=12,
extraction="hidden_states[layer], position=last",
)
key_map.save("qwen1.5b_to_qwen0.5b.safetensors")
Chaining & PCA compression
Chain maps across models (A -> B -> C)
Maps compose analytically in closed form without requiring paired data between A and C:
map_ab = Map.load("a_to_b.safetensors")
map_bc = Map.load("b_to_c.safetensors")
map_ac = map_ab.compose(map_bc) # Exact: map_ac(z) == map_bc(map_ab(z))
Low-rank / PCA compression
Shrink map size and apply latency by compressing to rank k (R_k = U @ Vh, stored as compact (d_b, k) and (k, d_a) factors in .safetensors):
# Option 1: Compress a fitted map to top-k cross-covariance components
small_map = key_map.compress(k=256)
small_map.save("qwen_to_llama_r256.safetensors")
# Option 2: Fit directly in k-dimensional per-model PCA subspaces
pca_map = Map.fit(keys_a, keys_b, pca_dim=256)
Reproduce the Germany → Paris fact-swap demo
In the classic Plato's Key demonstration, prompting a recipient LLM with "The capital of Germany is" yields "Berlin". Swapping in a rotated hidden state from a separate donor LLM at "France" flips the recipient's answer to "Paris":
import torch
from plato_maps import Map, extract_keys
# 1. Load a precomputed map (or fit one with Map.fit(keys_a, keys_b))
key_map = Map.load("qwen1.5b_to_qwen0.5b.safetensors")
# 2. Extract the donor's hidden state at "France" and translate it to the recipient's space
z_france = extract_keys(donor, donor_tok, ["The capital of France"], layer=14, position="last")[0]
z_swapped = key_map(z_france)
# 3. Inject z_swapped at the "Germany" token while running the recipient model
inputs = recip_tok("The capital of Germany is", return_tensors="pt").to(recip.device)
germany_idx = inputs["input_ids"][0].tolist().index(recip_tok.encode(" Germany", add_special_tokens=False)[-1])
def swap_hook(_module, _inp, output):
h = output[0].clone() if isinstance(output, tuple) else output.clone()
h[:, germany_idx, :] = z_swapped.to(device=h.device, dtype=h.dtype)
return (h, *output[1:]) if isinstance(output, tuple) else h
handle = recip.model.layers[12 - 1].register_forward_hook(swap_hook)
try:
with torch.no_grad():
next_token = recip_tok.decode([recip(**inputs).logits[0, -1].argmax().item()])
finally:
handle.remove()
print(next_token) # -> " Paris"
Or run the full self-contained script in examples/germany_paris_demo.py:
python examples/germany_paris_demo.py \
--donor Qwen/Qwen2.5-1.5B \
--recipient Qwen/Qwen2.5-0.5B \
--save-map qwen1.5b_to_qwen0.5b.safetensors
To reuse an already-computed map without re-running calibration:
python examples/germany_paris_demo.py \
--donor Qwen/Qwen2.5-1.5B \
--recipient Qwen/Qwen2.5-0.5B \
--map qwen1.5b_to_qwen0.5b.safetensors
Mathematical formulation
Given paired donor keys $Z_A \in \mathbb{R}^{N \times d_A}$ and recipient keys $Z_B \in \mathbb{R}^{N \times d_B}$:
- Center by means: $$\tilde{Z}_A = Z_A - \mu_A, \qquad \tilde{Z}_B = Z_B - \mu_B$$
- Orthogonal / semi-orthogonal Procrustes rotation via thin SVD of $\tilde{Z}B^\top \tilde{Z}A = U \Sigma V^\top$: $$R = U V^\top \in \mathbb{R}^{d_B \times d_A}$$ ($R^\top R = I{d_A}$ when $d_B \ge d_A$; $R R^\top = I{d_B}$ when $d_B \le d_A$.)
- Global Frobenius scale: $$s = \frac{|\tilde{Z}_B|_F}{|R \tilde{Z}_A^\top|_F}$$
- Inference (zero gradients): $$\hat{z}_B = \mu_B + s , R (z_A - \mu_A)$$
Reference
- Hazy Research — Plato's Key (Vivien Cheng, Jerry Liu, Morris Yau, Chris Ré, Stanford University, November 25, 2026).
License
MIT License — see LICENSE.
Metadata
Release files for plato-maps 0.1.0
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 |
|---|---|---|---|---|
| plato_maps-0.1.0.tar.gz | 29.1 kB | Without provenance | Details for plato_maps-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| plato_maps-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for plato_maps-0.1.0-py3-none-any.whl |
Total release size: 47.7 kB
Release files / plato_maps-0.1.0.tar.gz
| Download URL | plato_maps-0.1.0.tar.gz |
|---|---|
| Size | 29.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92686782d1c15e579f583f14496512ac7e7d354144e067f32c0c7b8fdf78c6d7
|
|
BLAKE2b-256 checksum How to use checksums |
5ae0e35c0771e4a880dbddbb30011c3c3ac2986d7e11ac58afa4b6794fa59e38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.11
|
Release files / plato_maps-0.1.0-py3-none-any.whl
| Download URL | plato_maps-0.1.0-py3-none-any.whl |
|---|---|
| Size | 18.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8b58cc3ee3650cf447c84048d4e341eeb8cf3fd6c6fecb809a6cb5b8ca863f00
|
|
BLAKE2b-256 checksum How to use checksums |
db36d0ac46fadb9a8b3f3250680462c114d6693db4b44e736bab173b6f61dc22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.11
|
Security for plato-maps 0.1.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.