GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - nmicic/int-llm-coordinate-permutation: Reversible coordinate permutations for Llama checkpoints with exact Q16.48 validation and direct SafeTensors support.

BranchesTags
Open more actions menu

Latest commit

 

History

7 Commits
7 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
experiments
experiments
 
 
source
source
 
 
validation
validation
 
 
.gitignore
.gitignore
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
FORMAT.md
FORMAT.md
 
 
LICENSE
LICENSE
 
 
Makefile
Makefile
 
 
README.md
README.md
 
 
RESULTS.md
RESULTS.md
 
 
SECURITY.md
SECURITY.md
 
 
SOURCE_PROVENANCE.md
SOURCE_PROVENANCE.md
 
 
compare_runs.py
compare_runs.py
 
 
explicit_token_map.py
explicit_token_map.py
 
 
safetensors_permutation.py
safetensors_permutation.py
 
 
test_attention_head_permutation.py
test_attention_head_permutation.py
 
 
test_combined_coordinate_permutation.py
test_combined_coordinate_permutation.py
 
 
test_explicit_token_map.py
test_explicit_token_map.py
 
 
test_hidden_channel_permutation.py
test_hidden_channel_permutation.py
 
 
test_mlp_neuron_permutation.py
test_mlp_neuron_permutation.py
 
 
test_safetensors_coordinate_permutation.py
test_safetensors_coordinate_permutation.py
 
 
test_systematic_mlp_layout.py
test_systematic_mlp_layout.py
 
 
test_token_map.c
test_token_map.c
 
 
test_token_permutation.py
test_token_permutation.py
 
 
token_map.h
token_map.h
 
 
token_permutation.py
token_permutation.py
 
 

Repository files navigation

int-llm coordinate permutation

A reversible model-layout toolkit for controlled experiments on vocabulary, neuron, attention-head, and hidden-coordinate ordering.

The project originated in the deterministic Q16.48 int-llm runtime, but also includes direct BF16/F16/F32 SafeTensors implementations that move stored floating-point values without integer conversion. The integer path provides stronger exact-validation gates; the floating-point path makes the same transformations directly applicable to standard Hugging Face checkpoints.

Two scopes are implemented and deliberately kept distinct:

Scope What moves Implementation
Vocabulary only all rows of the input embedding and any separately stored output head safetensors_permutation.py and token_permutation.py
All axes vocabulary rows, SwiGLU neurons, GQA-aware whole heads, and the global residual hidden basis experiments/safetensors_coordinate_permutation/ and the MGW component tools under experiments/

On TinyLlama-1.1B-Chat-v1.0, the all-axis composition transformed all 201 learned tensors. The Q16.48 model passed a direct prescribed-axis verifier and the same 80/80-token greedy gate as the original. The direct BF16 version restored the original checkpoint byte-for-byte; its FP inference control kept 48/48 tested top-1 decisions while showing the expected small logit drift from changed floating-point reduction order. See RESULTS.md for the exact scope, hashes, and limitations.

Important

These are known exact-arithmetic parameter symmetries and reversible token namespaces—not encryption, private weights, or a new cryptographic primitive. A public base checkpoint makes the transformations especially easy to analyze or recover. See SECURITY.md.

Is coordinate permutation the same as quantization?

No. They change different parts of the checkpoint representation.

Operation Logical coordinate order Stored scalar values Relation to the original model
Coordinate permutation reordered copied bit-for-bit without modification same mathematical function; FP execution may show reduction-order drift
Quantization normally unchanged replaced by lower-precision approximations generally an approximate function relative to the original

Coordinate permutation changes where a stored value lives; quantization changes the value stored at a coordinate.

The two operations can be combined, but they are separate transformations and should be validated separately. Some production quantizers also pack or reorder weights for execution; that is an additional layout operation, not quantization itself.

Start with standard SafeTensors weights

Requirements are Python 3.10+ on a POSIX host. NumPy is optional for small fixtures and strongly recommended for full checkpoints.

Create a token map from a private random key:

(umask 077; set -C; head -c 32 /dev/urandom > token.key)
python3 token_permutation.py create-map \
  --vocab 32000 --key-file token.key --output token.tpmap

The TPMAP contains the complete token permutation and inverse. It is sufficient to translate token IDs at runtime; it is not a hash or an encryption key file.

For a specific vocabulary-row arrangement, use an explicit order instead of a key. Position j in new_to_old names the original logical token row that will be stored at physical row j:

{
  "format": "int-llm-token-order-v1",
  "new_to_old": [2, 0, 3, 1]
}

For this four-token example:

python3 explicit_token_map.py \
  --vocab 4 \
  --permutation-file token-order.json \
  --output token.tpmap

The explicit order must contain every ID exactly once. The tool validates the bijection, computes the inverse, and writes the same TPMAP1 format used by all existing converters and runtimes.

Option A: vocabulary-only permutation

This is the small, general operation: move every stored row of model.embed_tokens.weight and, when present as a separate tensor, lm_head.weight, without decoding any FP value.

python3 safetensors_permutation.py inspect model.safetensors

python3 safetensors_permutation.py convert \
  --input model.safetensors \
  --output model.token-permuted.safetensors \
  --map token.tpmap

python3 safetensors_permutation.py verify \
  --input model.safetensors \
  --output model.token-permuted.safetensors \
  --map token.tpmap

Restore the original row order and prove the file round trip:

python3 safetensors_permutation.py convert --inverse \
  --input model.token-permuted.safetensors \
  --output model.restored.safetensors \
  --map token.tpmap

cmp model.safetensors model.restored.safetensors

Option B: all-axis permutation

The all-axis tool additionally derives independent per-layer MLP-neuron and GQA-head maps plus one global residual-basis map. It classifies every learned tensor and fails closed if the checkpoint does not match its supported Llama layout.

(umask 077; set -C; head -c 32 /dev/urandom > mlp.key)
(umask 077; set -C; head -c 32 /dev/urandom > attention.key)
(umask 077; set -C; head -c 32 /dev/urandom > hidden.key)

python3 experiments/safetensors_coordinate_permutation/all_axis_safetensors.py \
  inspect model.safetensors --config config.json

python3 experiments/safetensors_coordinate_permutation/all_axis_safetensors.py \
  convert \
  --input model.safetensors \
  --output model.all-axis.safetensors \
  --config config.json \
  --map token.tpmap \
  --mlp-key-file mlp.key \
  --attention-key-file attention.key \
  --hidden-key-file hidden.key

python3 experiments/safetensors_coordinate_permutation/all_axis_safetensors.py \
  verify \
  --input model.safetensors \
  --output model.all-axis.safetensors \
  --config config.json \
  --map token.tpmap \
  --mlp-key-file mlp.key \
  --attention-key-file attention.key \
  --hidden-key-file hidden.key

For an inverse, add --inverse, use the all-axis artifact as --input, choose a new restored-file path as --output, and supply the same four map inputs.

Both FP tools currently accept one unsharded SafeTensors file. The all-axis tool is intentionally strict: it supports Llama architecture, standard Hugging Face tensor names, an external config.json, and BF16/F16/F32 learned tensors.

The required token boundary mapping

Let P be a bijection from original/logical IDs to permuted/physical IDs:

physical_id = P(logical_id)
logical_id  = P^-1(physical_id)

The vocabulary rows move as follows:

new_embedding[P(i)] = old_embedding[i]
new_lm_head[P(i)]   = old_lm_head[i]

Inputs must be mapped through P; output logits or sampled IDs must be mapped back to logical order. Reordering weights without this boundary translation is not an equivalent end-to-end model interface. The copied INT runtime implements that boundary with --token-map; the FP comparison harness demonstrates it for Hugging Face inference.

The three internal maps need no runtime sidecar. Their compensating row and column moves are fully baked into the model weights.

What the all-axis transformation does

Each map acts on a different model coordinate system:

Tensor family Row axis Column axis
token embedding / output head vocabulary residual hidden
Q projection Q head residual hidden
K/V projections KV head residual hidden
attention O projection residual hidden Q head
MLP gate/up projections intermediate neuron residual hidden
MLP down projection residual hidden intermediate neuron
learned RMSNorm vectors residual hidden entries —

The attention map moves whole heads and preserves TinyLlama's GQA grouping. Coordinates inside Q/K heads remain unchanged, so RoPE pairs and frequencies remain canonical. The residual permutation is global because residual additions require every branch to use the same basis.

TinyLlama's tested checkpoint contains:

Property Value
Learned scalar parameters 1,100,048,384
Learned tensors 201
Vocabulary 32,000
Hidden size 2,048
Intermediate size 5,632
Q / KV heads 32 / 4
Transformer layers 22
BF16 SafeTensors file 2,200,119,864 bytes
Q16.48 MGW file 8,800,406,496 bytes

“All learned tensors are transformed” does not mean every scalar byte must differ. A random permutation can have fixed coordinates, and distinct coordinates can contain equal values. The verifiers compare every destination coordinate with its prescribed source coordinate and separately require format metadata to remain byte-identical. Structural verification therefore covers the complete checkpoint, including bytes that are not transformation targets.

Explicit and possible layout uses

A permutation can make a chosen equivalent coordinate order part of the stored checkpoint. Explicit order files currently cover vocabulary rows, MGW MLP-neuron axes, and the global MGW residual hidden basis. The SafeTensors all-axis path and the attention component tool still derive their internal maps from keys.

The smallest global hidden-basis example swaps coordinates 0 and 31. This is not a swap of two isolated scalar weights: it moves the same two coordinate lanes through every learned matrix that consumes or produces the residual stream. On the committed MicroGPT checkpoint, all 9 learned matrices change, the direct verifier accepts every prescribed row and column, the inverse is byte-exact, and all 5,832 checked Q16.48 logits remain identical. See hidden_channel_permutation for the explicit-order format and commands.

The same generator can compose a requested number of deterministic random coordinate transpositions into one source-bound order. The converter applies that final permutation in a single checkpoint pass; intermediate rewrites are unnecessary.

The small-model systematic_mlp_layout spike uses the explicit MGW MLP path to generate original, smooth, spread, and seeded-random orders. It measures exact adjacent-neuron weight-profile distance and verifies the complete Q16.48 function. It is a local-layout experiment, not a sparsity or performance claim.

Possible follow-up experiments include:

  • arranging vocabulary rows by measured token frequency for paging or storage locality experiments;
  • grouping frequently and infrequently activated MLP neurons within each layer for a sparse or offloaded runtime; and
  • grouping channels or GQA-compatible whole heads for a downstream layout or quantization experiment.

These transformations are inputs to such experiments, not optimizations by themselves. Dense GEMM shapes and operation counts are unchanged. Any benefit requires a runtime, storage scheme, or quantizer that uses the resulting contiguous groups, followed by controlled measurement.

The allowed orders also have different scopes: MLP-neuron maps are independent per layer; attention maps are per layer but constrained by GQA grouping; the vocabulary map and residual hidden-basis map are each global.

Why keep the integer path?

The symmetry is dtype-independent, but Q16.48 is a stronger exact oracle for internal column permutations:

  • the MGW converter moves stored int64_t values without dequantization, rounding, or requantization;
  • all prescribed rows, columns, and vectors can be checked byte-for-byte;
  • supported integer dot products remain exact when a column permutation changes accumulation order; and
  • deterministic generation can be compared by complete token lists and a canonical output hash.

Floating-point checkpoints can also be transformed without changing stored scalar values and restored byte-for-byte. During FP inference, however, compensated column permutations may reorder additions, so mathematically equivalent models need not produce bit-identical logits. The repository reports that drift instead of hiding it behind an exact-output claim.

Native Q16.48 MGW path

For vocabulary-only conversion:

python3 token_permutation.py convert-mgw \
  --input tinyllama.mgw \
  --output tinyllama.token-permuted.mgw \
  --map token.tpmap

python3 token_permutation.py verify-mgw \
  --input tinyllama.mgw \
  --output tinyllama.token-permuted.mgw \
  --map token.tpmap

Build and use the copied runtime integration:

make runtime

./source/llama_int tinyllama.token-permuted.mgw \
  --native \
  --token-map token.tpmap \
  --ref-dir /path/to/TinyLlama-reference-files \
  --benchmark --profile

The MGW all-axis implementation is currently a sequence of the MLP, attention, vocabulary, and hidden-basis converters under experiments/, followed by a direct verifier that reconstructs both prescribed axes from the original checkpoint. See the combined coordinate README for the exact commands and evidence.

Converters refuse to overwrite an output. If interrupted, they retain a .partial file for explicit inspection or removal.

Verification summary

The retained TinyLlama records establish four different results:

Path Scope Main result
Q16.48 MGW vocabulary only 64,000 prescribed rows, byte-exact inverse, 80/80 tokens
BF16 SafeTensors vocabulary only 64,000 prescribed rows, byte-exact inverse, exact agreement with MGW-first conversion
Q16.48 MGW all axes 201/201 learned tensors directly verified, 80/80 tokens
BF16 SafeTensors all axes 201/201 learned tensors, byte-exact inverse, 48/48 top-1 FP control

An additional Q16.48 TinyLlama gate composed 10,000 deterministic random hidden-coordinate transpositions into one explicit order. It directly verified all 201 learned tensors, passed a complete-file inverse cmp, and matched 80/80 reference tokens. See the 2026-08-02 record.

The final composed MGW artifact was verified directly against the original but was not retained through a second full 8.8 GB composed inverse artifact. Each component converter has its own exact inverse gate. This distinction is recorded explicitly in RESULTS.md.

Run all committed fixture, inverse, tamper, fallback, and C-loader tests with:

make test

Repository map

  • safetensors_permutation.py — direct vocabulary-only SafeTensors tool.
  • explicit_token_map.py — create a TPMAP1 sidecar from a specified new_to_old vocabulary-row order.
  • token_permutation.py — TPMAP generation, ID translation, and vocabulary-only MGW conversion/verification.
  • experiments/safetensors_coordinate_permutation/ — one-pass all-axis SafeTensors converter, verifier, and FP inference comparator.
  • experiments/mlp_neuron_permutation/ — SwiGLU-neuron MGW converter.
  • experiments/attention_head_permutation/ — GQA-aware whole-head MGW converter.
  • experiments/hidden_channel_permutation/ — global residual-basis MGW converter and explicit fixed or deterministic-random order generator.
  • experiments/combined_coordinate_permutation/ — direct composed-axis MGW verifiers.
  • token_map.h and source/ — TPMAP C loader and pinned int-llm runtime integration.
  • RESULTS.md and validation/ — exact complete-model claims and records.
  • FORMAT.md, SECURITY.md, and SOURCE_PROVENANCE.md — format, threat boundary, and copied-source audit.

The main public project remains nmicic/int-llm. This repository uses a pinned copy of commit 1b80e024c5fadea955e3892578a36dbc80a8a0b5; no experimental change here has been applied to the main repository.

Prior art and claim boundary

Vocabulary relabeling and coordinated neuron/head permutations are established model symmetries. Relevant examples include Git Re-Basin, transformer re-basin work in TransFusion, and broader rotation symmetry.

ObfusLM (ACL 2025) also begins with vocabulary and embedding/head permutation, then adds clustering, synthetic embeddings, noise, and attack evaluation for a privacy claim. None of those additional mechanisms are implemented here. This repository contributes auditable conversion tools and exact/drift-reporting validation records, not a claim to have discovered these symmetries or reproduced ObfusLM's privacy system. See experiments/PRIOR_ART.md.

Limits and non-claims

  • Full-model evidence is for TinyLlama-1.1B-Chat-v1.0; fixture tests cover additional small Llama/GQA layouts.
  • The all-axis SafeTensors path is single-file and Llama-specific; it is not a general sharded-checkpoint framework.
  • The 80-token INT gate and 48-position FP control are regression evidence, not general model-quality guarantees.
  • FP top-1 equality is not guaranteed for arbitrary prompts or decoding paths.
  • No training or fine-tuning pipeline is implemented.
  • Explicit user-provided orders currently cover vocabulary rows, MGW MLP-neuron axes, and the global MGW residual hidden basis. The attention component and SafeTensors all-axis paths remain key-derived.
  • Model weights and tokenizers are not distributed here and retain their upstream licenses.
  • MGW, SafeTensors, TPMAP, and config inputs are trusted research inputs; the parsers have not been audited as hostile-file parsers.
  • No speedup, compression, cryptographic security, or novelty of the underlying symmetries is claimed.

Related projects and articles

  • Original int-llm repository
  • Original small model artifact
  • Original int-llm article
  • int-llm-precision-ladder repository
  • int-llm-precision-ladder article

License

Repository-owned code is Apache-2.0 © 2026 Nenad Mićić. The pinned source/ snapshot retains its upstream notices and provenance. See LICENSE, source/LICENSE, and SOURCE_PROVENANCE.md.

About

Reversible coordinate permutations for Llama checkpoints with exact Q16.48 validation and direct SafeTensors support.

Topics

ccoordinate-permutationdeterministic-computingfixed-pointinteger-arithmeticinteger-inferencellamallmmodel-layoutmodel-transformationmodel-verificationneural-network-symmetrypythonquantizationreproducibilityreproducible-researchsafetensorstinyllamaweight-permutation

Resources

Readme
Apache-2.0 license

Contributing

Contributing

Security policy

Security policy
Activity

Stars

1 star

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.