A dynamic inference sampler for LLMs using thermodynamic thermal shock.
Project description
Phase-Slip-Sampler: Entropy-Guided Thermal Shock for LLMs
The Concept
Standard LLM generation forces a choice between rigidity (Greedy Decoding) and randomness (Standard Sampling).
Phase-Slip is a dynamic inference sampler that utilizes the Thermodynamics of Attention.
- Monitor: It calculates the Shannon Entropy (uncertainty) of the model at every step.
- Trigger: When confusion spikes above a threshold, it triggers a "Phase Slip."
- Shock: It injects Gaussian noise ("Heat") directly into the Key-Value memory tensors and temporarily spikes the sampling temperature.
This simulated annealing forces the model to "shake loose" from local minima (repetitive loops) only when necessary, preserving structure when the model is confident.
Installation
You can install the package directly from PyPI:
pip install phase-slip-sampler
Alternatively, for local development from the source repository:
pip install -r requirements.txt
Important: While the package name is
phase-slip-sampler, the Python module is namedphase_slip.
Usage
Python Import
To use the sampler in your own code, remember to use the underscore naming convention:
import phase_slip
sampler = phase_slip.Sampler(...)
Quick Demo
To see the sampler in action and watch it trigger "Thermal Shocks" in real-time:
python demo.py
Benchmarking
To statistically compare Phase-Slip against Greedy Decoding and Standard Sampling:
python benchmark.py
Evidence
Benchmarks performed on gpt2 (Small) demonstrate that Phase-Slip effectively breaks repetition loops without requiring constant high-temperature sampling.
1. Vocabulary Diversity (n=5 rounds)
Score based on unique word count ratio. Higher is better.
| Method | Score | Behavior |
|---|---|---|
| Greedy Decoding | 0.26 |
Highly repetitive. Stuck in loops. |
| Standard Sampling | 0.59 |
High variance. Good for creative writing. |
| Phase-Slip | 0.60 |
Matches standard sampling diversity but uses an adaptive trigger. |
2. The "Loop Breaker" Test
Prompt: "The scientist opened the door to the secret lab and discovered"
Standard GPT-2 (Greedy):
"...that the lab was a laboratory for the research of the human brain. 'I was very surprised to find out that the lab was a laboratory..." (FAILURE: Stuck in a logic loop)
Phase-Slip GPT-2:
"...that how the human body works was influenced by the environment. West's research was published in the journal Heart. 'The microwave is a very important part..." (SUCCESS: Detected entropy spike, injected heat, and forced a semantic divergence)
Project Structure
phase_slip/: The source code for the sampler.demo.py: A visual comparison script to see the thermal shocks.benchmark.py: A statistical tool to measure vocabulary diversity.
License
MIT
Project details
Release history Release notifications | RSS feed
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 phase_slip_sampler-0.1.1.tar.gz.
File metadata
- Download URL: phase_slip_sampler-0.1.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bb5b7c77483419f37354004a739a9ea7a6b712cade3a7fd19d89006bb558843
|
|
| MD5 |
9e813887423e5fa735a817776498c23a
|
|
| BLAKE2b-256 |
a1295841b4473bfce9b9ee0d128148137dec8317dcfffb6c2e57b2e66522ddcf
|
File details
Details for the file phase_slip_sampler-0.1.1-py3-none-any.whl.
File metadata
- Download URL: phase_slip_sampler-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19e66761604acbd92b33033b924c8f1dfcffbcf5258fa90c7e8cb3bd272c3b00
|
|
| MD5 |
175dfdbd8b53c81bdcb51eebd3b4a30e
|
|
| BLAKE2b-256 |
727d0f5adf46b1ab1329a49c17820e004134fd18be4e82820b6a06ef0169d213
|