Skip to main content

llm_sepweight

The llm_sepweight microlib is designed to manage the weights of large language models (LLMs) by organizing them into a directory format called sepweight.

sepweight essentially mirrors the state dict of the LLM into the filesystems, meaning that you will (roughly) have one file per key in the state dict of the LLM.

This format enables the distributed execution of LLMs by separating the model weights into distinct segments that can be individually managed and accessed as needed.

The only dependencies are numpy and torch.

Installation

pip install llm_sepweight

Quick Example

To convert an existing state dict into sepweight, you need to provide:

  • decider is a function which will be called for each key in the state dict, and has to decide whether that key should be part of the start, mid, or end section. Example
  • state_dict - is just your usual PyTorch state dict
  • out_path is the directory, in which you want the result to be stored.
from llm_sepweight import dump_to_directory

dump_to_directory(
    decider=decider,
    state_dict=state_dict,
    out_path=out_path
)

You could have multiple state dicts (for example coming from multiple files), it's ok to call dump_to_directory with each of them. The result will be combined state dict of all the state dicts provided for a given out_path.

Goal format

llm_sepweight allows you to convert different formats to its own directory format, which is very simple. Let's have a look at an example:

└── weights_root
    ├── end
    │   └── lm_head.pth
    ├── mid
    │   ├── 0
    │   │   ├── keys.pth
    │   │   ├── queries.pth
    │   │   └── values.pth
    │   ├── 1
    │   │   ├── keys.pth
    │   │   ├── queries.pth
    │   │   └── values.pth
    │   ├── 2
    │   │   ├── keys.pth
    │   │   ├── queries.pth
    │   │   └── values.pth
    │   └── 3
    │       ├── keys.pth
    │       ├── queries.pth
    │       └── values.pth
    └── start
        └── embeddings.pth

8 directories, 14 files

All the weights are stored in a directory in usual .pth files.

The root directory contains exactly three child directories: start, mid and end.

  • The subdirectory start contains all the weights needed to compute the initial embeddings, prior to the transformer layers.
  • The subdirectory mid contains numbered subdirectories corresponding to the weights of each layer.
  • The subdirectory end contains the weights needed to compute the final prediction of the LM head.

This format is very simple and allows great flexibility. For example, a node running layers 0 to 3 will only need the start, mid/0, mid/1, mid/2 subdirectories.

Why do we need it?

There are all sorts of different formats for storing the weights of an LLM - .pth files, safetensors, H5, arrow, GGUF, etc.

Moreover, there is a lot of difference in the naming of the transformer layers, of the start embedding, and of the final head. llm_sepweight aims to provide functions, through which you can convert different formats into a separated weights format.

Metadata

Release files for llm-sepweight 0.6.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 llm-sepweight 0.6.0
File Size Uploaded Provenance Actions
llm_sepweight-0.6.0.tar.gz 5.3 kB Without provenance Details for llm_sepweight-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llm-sepweight 0.6.0
File Interpreter ABI Platform Actions
llm_sepweight-0.6.0-py3-none-any.whl Python 3 none any Details for llm_sepweight-0.6.0-py3-none-any.whl

Total release size: 11.5 kB

Release files / llm_sepweight-0.6.0.tar.gz

Download URL llm_sepweight-0.6.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
bd47956768318b6e0f9adce4315b6be5440ec6ae078e9557f0c9f36b95cc3312
BLAKE2b-256 checksum
How to use checksums
79f7d3ff69d7164180c32fd6bd98f354da1d96ca9b0d451dd8e9af62fe52fef0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / llm_sepweight-0.6.0-py3-none-any.whl

Download URL llm_sepweight-0.6.0-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
add8aa74296c8d7135b1a1fe3ab7c5818cd0e862238ebdd07b5af77d2b59a8d5
BLAKE2b-256 checksum
How to use checksums
f8c9f76007ac13ef975ae967a512bdce58a946834f02d8337a12df0db26f6e09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for llm-sepweight 0.6.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.

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