Skip to main content

🪄 Statecraft - Load, store and remix states for SSMs, Mamba and Stateful models

TL;DR

With statecraft you can easily load states from a file or from the community repository and use them in your SSMs or stateful models. The interface is just like Huggingface's Transformers library:

from statecraft import StatefulModel

model = StatefulModel.from_pretrained(
        model_name="state-spaces/mamba-130m-hf",
        initial_state_name="koayon/state-a",
    )

Now with every forward pass you get the knowledge from the state you loaded. And because StatefulModel inherits from Huggingface's PreTrainedModel, you can use it just like any other Huggingface model.

🧑‍💻 Installation

pip install statecraft

✨ Other Features

  • Use model.build_state() to generate a new state from your context.
  • Use model.save_state() or model.save_current_state to save your state to a file so that you can use it again in the future.
  • With model.load_state() you can load a state either from a file or from the community repository.
    • To see the states that are available in the community repository, visit the Statecraft Hub or use statecraft.list_states().

🔍 Coming Soon

  • Right now we only support Mamba models (in all sizes), as more SSMs and Stateful models begin to come onto Huggingface, we will support them too.
  • We're also looking at RAG-like generation approaches where you automatically retrieve the state instead of context, watch this space 👀

🧙 Conceptually

Currently, we often use RAG to give a transformer contextual information.

With Mamba-like models, you could instead imagine having a library of states created by running the model over specialised data. States could be shared kinda like LoRAs for image models.

For example, I could do inference on 20 physics textbooks and, say, 100 physics questions and answers. Then I have a state which I can give to you. Now you don’t need to add any few-shot examples; you just simply ask your question. The in-context learning is in the state.

In other words, you can drag and drop downloaded states into your model, like literal plug-in cartridges. And note that “training” a state doesn’t require any backprop. It’s more like a highly specialised one-pass fixed-size compression algorithm. This is unlimited in-context learning applied at inference time for zero-compute or latency.

The structure of an effective Transformer LLM call is:

  • System Prompt
  • Preamble
  • Few shot-examples
  • Question

With statecraft and your SSM, we instead simply have:

  • Inputted state (with problem context, initial instructions, textbooks, and few-shot examples all baked in)
  • Short question

For more details see here

💃 Contributions

We welcome contributions to the statecraft library! And of course, please contribute your SSM states with statecraft.upload_state(...) 🪄


Proudly powering the SSM revolution.

Metadata

Release files for statecraft 0.3.0

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

Source distribution (sdist)

Source distribution for statecraft 0.3.0
File Size Uploaded
statecraft-0.3.0.tar.gz 15.3 kB Details

Built distribution (wheel)

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

Total release size: 32.0 kB

Release files / statecraft-0.3.0.tar.gz

Download URL statecraft-0.3.0.tar.gz
Size 15.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7c423f8927fe6169914ba9219e34d9fd017fa65f4802d19bd5a8daca626eeccd
BLAKE2b-256 checksum
How to use checksums
c992da4e87a123534418b9ff34004aa49fd63f28d623d27372b40d3b2dfc6d5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.10.14 Linux/6.5.0-1017-azure

Release files / statecraft-0.3.0-py3-none-any.whl

Download URL statecraft-0.3.0-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed5e5d6f7097848a319a4fe5d12c2727485bc21e24b2e6ee9093dfda05ecda96
BLAKE2b-256 checksum
How to use checksums
c12a6226dcf9b349188cdfedcedbe4573fe17e966489a66fcca451227a383aff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.2 CPython/3.10.14 Linux/6.5.0-1017-azure

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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