A tool for loading and computing on parts of LLM models.
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
LLM Layer Collector
A practical Python package for working with Huggingface models at the layer level. Designed to help developers and researchers load specific model components when working with large, sharded checkpoints.
What It Does
- Easily load layers, embedding, head, and norm and run partial computation of language models.
- Uses Huggingface file format to find the appropriate parts of the model.
- Uses the transformers and pytorch libraries to load data and run computations.
- Useful for research, development, and memory-constrained environments
Getting Started
Installation
pip install llm-layer-collector
Essential Components
The LlmLayerCollector class serves as your central interface to the package's functionality.
Required Parameters:
model_dir: Path to your model directory containing shards and configurationcache_file: Location for storing shard metadata
Optional Parameters:
shard_pattern: Custom regex for matching shard fileslayer_prefix: Prefix for identifying decoder layers (default: "model.layers.")input_embedding_layer_name: Name for the embedding layer (default: 'model.embed_tokens.weight')norm_layer_name: Name for the norm weight (default: 'momdel.norm.weight')lm_head_name: Name for the head weight (default: 'lm_head.weight')device: Target device for tensor operations ("cpu" or "cuda") (default: "cpu")dtype: Desired numerical precision (default: torch.float16)
Example
This example uses all of the parts of the package to generate a token prediction
from llm_layer_collector import LlmLayerCollector
from llm_layer_collector.compute import compute_embedding, compute_layer, compute_head
from transformers import AutoTokenizer
import torch
# Initialize core components
collector = LlmLayerCollector(
model_dir="/path/to/model",
cache_file="cache.json",
device="cuda",
dtype=torch.float16
)
# Set up tokenization
tokenizer = AutoTokenizer.from_pretrained("/path/to/model")
input_text = "The quick brown fox"
input_ids = tokenizer(input_text, return_tensors='pt')['input_ids']
# Load model components
embedding = collector.load_input_embedding()
norm = collector.load_norm()
head = collector.load_head()
layers = collector.load_layer_set(0, collector.num_layers - 1)
# Execute forward pass
state = compute_embedding(embedding, input_ids, collector.config)
for layer in layers:
state.state = compute_layer(layer, state)
# Generate predictions
predictions = compute_head(head, norm(state.state), topk=1)
Computation Pipeline
Our helper functions provide a streamlined approach to model operations:
compute_embedding: Handles input embedding and causal mask setupcompute_layer: Manages state transitions through decoder layerscompute_head: Processes final linear projections and token prediction
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 llm_layer_collector-0.1.0.tar.gz.
File metadata
- Download URL: llm_layer_collector-0.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d690025cb123f38d1f8d31a121d93c5db436e0b7469f2409a5e76de6b0268b45
|
|
| MD5 |
fb73eac990049a8224cc362690f1ef65
|
|
| BLAKE2b-256 |
60feb7e755841c40b1cde70e7d0a1d5d25930855043ac87294c93d14c43dddc6
|
Provenance
The following attestation bundles were made for llm_layer_collector-0.1.0.tar.gz:
Publisher:
publish.yml on erinclemmer/llm-layer-collector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_layer_collector-0.1.0.tar.gz -
Subject digest:
d690025cb123f38d1f8d31a121d93c5db436e0b7469f2409a5e76de6b0268b45 - Sigstore transparency entry: 514617376
- Sigstore integration time:
-
Permalink:
erinclemmer/llm-layer-collector@3fa7184e544ea869e7ad35cc0c9d1f6bbf075597 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/erinclemmer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3fa7184e544ea869e7ad35cc0c9d1f6bbf075597 -
Trigger Event:
release
-
Statement type:
File details
Details for the file llm_layer_collector-0.1.0-py3-none-any.whl.
File metadata
- Download URL: llm_layer_collector-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3732f740fb2ce095c56de6604e53d2b1049cc7e18768202eaf60d57e6281f98d
|
|
| MD5 |
f0bbf3f26a4d1cc0a3f911dad40ed9d6
|
|
| BLAKE2b-256 |
8118bdb805c96c9f1508a995be9f48bdebf2d695fb82401dd273caa6c8d286ce
|
Provenance
The following attestation bundles were made for llm_layer_collector-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on erinclemmer/llm-layer-collector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
llm_layer_collector-0.1.0-py3-none-any.whl -
Subject digest:
3732f740fb2ce095c56de6604e53d2b1049cc7e18768202eaf60d57e6281f98d - Sigstore transparency entry: 514617380
- Sigstore integration time:
-
Permalink:
erinclemmer/llm-layer-collector@3fa7184e544ea869e7ad35cc0c9d1f6bbf075597 -
Branch / Tag:
refs/tags/0.1.0 - Owner: https://github.com/erinclemmer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3fa7184e544ea869e7ad35cc0c9d1f6bbf075597 -
Trigger Event:
release
-
Statement type: