Meaning-Informed Next-token Transformation
Project description
MINT
Meaning-Informed Next-token Transformation
Project Goals
MINT adds a transformation layer that redistributes next-token probabilities according to semantic token similarity based on the model's embedding space. The aim is to produce more varied, human-like text without sacrificing coherence.
Installation
Create a virtual environment and install the package in editable mode:
pip install -e .
This installs the mint package and provides the mint command-line interface.
To use the published release from PyPI (when available), run:
pip install mint-llm
CLI Usage
Run the CLI with:
mint --help
The mint command exposes several subcommands. The typical workflow is shown
below.
Using MINT
The recommended workflow progresses through several commands:
-
Pick a checkpoint from the Hugging Face Hub (optional).
mint pick <model_id> checkpoint/
-
Crush merge sharded checkpoints referenced by an index file.
mint crush model.safetensors.index.json model.safetensors
-
Extract token embeddings from a checkpoint.
-
Blend the embeddings into a sparse similarity matrix. The command tries to use GPU 0 via CUDA, then Vulkan, before falling back to the CPU. Use
--cputo disable GPU usage or--gpu <index>to choose a device. The--sdkoption selects the acceleration backend and values below--tau(default:1e-4) are pruned before saving the matrix as a PyTorch sparse tensor:mint blend embeddings.safetensors similarity.pt --cpu --tau 0.00001
-
Brew new text from the wrapped model.
mint brew --model <model_id_or_path> --similarity similarity.pt --prompt "Hello"
Omit --prompt or pass --interactive to read prompts line by line from
stdin.
-
Infuse the tested similarity matrix into a local model and save the result to a directory.
mint infuse path/to/model similarity.pt infused-model --alpha 0.1
-
Chop split a full checkpoint back into shards (optional).
mint chop model.safetensors --size 2GB
Example workflow
Run the commands sequentially to build and use the redistribution layer:
mint pick my-model checkpoint/
mint crush checkpoint/model.safetensors.index.json checkpoint/model.safetensors
mint extract checkpoint/model.safetensors embeddings.safetensors
mint blend embeddings.safetensors similarity.pt --tau 1e-4
mint brew --model my-model --similarity similarity.pt --prompt "Hello" --seed 42
mint infuse ./my-model similarity.pt my-model-infused --alpha 0.1
mint chop my-model-infused --size 2GB # optional
See the notebooks and examples/quickstart.py
for a more detailed walk-through and an automated script. You can also
explore the generator interactively using the CLI.
Quickstart Script
Run examples/quickstart.py for an end-to-end
demonstration. The script mirrors the mint CLI commands:
extract, blend and brew.
Required argument:
--prompt– input text to generate from.
Optional arguments default to values defined in
tests/utils/model_config.json:
--checkpoint– checkpoint path. If this points to a*.safetensors.index.jsonfile the required shards are downloaded and merged automatically. If omittedmodel_urlis used.--model– model identifier or path. When a model ID is provided the checkpoint shards are fetched and merged automatically. Defaults tomodel_idor one derived frommodel_url.--embeddings– output file for embeddings (defaultembeddings.safetensors).--similarity– output file for the similarity matrix (defaultsimilarity.pt).--tau– sparsity threshold (default1e-4).
python examples/quickstart.py --prompt "Hello"
The script extracts embeddings, builds the similarity matrix and generates text using the wrapped model.
Examples
Practical examples are provided in the notebooks directory. They demonstrate embedding extraction, building a similarity matrix and brewing text from a short prompt.
Splitting Large Checkpoints
Use the chop command to divide a .safetensors checkpoint into shards:
mint chop model.safetensors shards/ --shards 2
The command writes shard files and a matching model.safetensors.index.json
inside the output directory. You can instead target a specific shard size:
mint chop model.safetensors shards/ --size-mb 500
Development
Install development dependencies with:
pip install -e '.[dev]'
Use the provided Makefile to run common tasks:
make format # check black formatting
make lint # run ruff and mypy (if configured)
make test # run the pytest suite
make all # runs all checks
make commands format, lint, and all can also be suffixed with -fix (e.g. make format-fix)
to attempt to automatically fix issues. make fix will also run all fixes.
Contributing
Development tasks are tracked in todos.json. See
project_proposal-MINT.md for the full technical
plan. Release notes are available in
CHANGELOG.md. Feel free to open issues or pull requests to
contribute.
Citation
If you use MINT in your research, please cite the project using the metadata in CITATION.cff.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mint_llm-0.0.2.tar.gz.
File metadata
- Download URL: mint_llm-0.0.2.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
915a64ef79bfd7ffe2b322cf9f3e8788953f0ed4752403f724e1bdacb6d8db24
|
|
| MD5 |
608be53d6ed4a007d0fd2ca3afbe3fb3
|
|
| BLAKE2b-256 |
1bc4b3997668990149d3d5a112d628bc540b423b06d9f9d314774c58623f7e56
|
Provenance
The following attestation bundles were made for mint_llm-0.0.2.tar.gz:
Publisher:
publish.yml on Reithan/MINT
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mint_llm-0.0.2.tar.gz -
Subject digest:
915a64ef79bfd7ffe2b322cf9f3e8788953f0ed4752403f724e1bdacb6d8db24 - Sigstore transparency entry: 245835703
- Sigstore integration time:
-
Permalink:
Reithan/MINT@05aa78bd7a9f6f8c705579512e5f8b23a52d2240 -
Branch / Tag:
refs/tags/v0.0.2-pre-release - Owner: https://github.com/Reithan
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@05aa78bd7a9f6f8c705579512e5f8b23a52d2240 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mint_llm-0.0.2-py3-none-any.whl.
File metadata
- Download URL: mint_llm-0.0.2-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
88df4f5d46ac6fe06940bba73d28ebbc582450c454795d4eceb64280b7c5fe64
|
|
| MD5 |
f3666fbe54f8932df345eece27ff1dc5
|
|
| BLAKE2b-256 |
d06cc688c2d0414200f827b645fc10d252926210c9a1bc8be4ef536e72a59e97
|
Provenance
The following attestation bundles were made for mint_llm-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on Reithan/MINT
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mint_llm-0.0.2-py3-none-any.whl -
Subject digest:
88df4f5d46ac6fe06940bba73d28ebbc582450c454795d4eceb64280b7c5fe64 - Sigstore transparency entry: 245835705
- Sigstore integration time:
-
Permalink:
Reithan/MINT@05aa78bd7a9f6f8c705579512e5f8b23a52d2240 -
Branch / Tag:
refs/tags/v0.0.2-pre-release - Owner: https://github.com/Reithan
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@05aa78bd7a9f6f8c705579512e5f8b23a52d2240 -
Trigger Event:
push
-
Statement type: