Neurocache
A library for augmenting language models with external caching mechanisms
Requirements
- Python 3.6+
- PyTorch 1.13.0+
- Transformers 4.25.0+
Installation
pip install neurocache
Getting started
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from neurocache import (
NeurocacheModelForCausalLM,
OnDeviceCacheConfig,
)
model_name = "facebook/opt-350m"
model = AutoModelForCausalLM.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
cache_layer_idx = model.config.num_hidden_layers - 5
config = OnDeviceCacheConfig(
cache_layers=[cache_layer_idx, cache_layer_idx + 3],
attention_layers=list(range(cache_layer_idx, model.config.num_hidden_layers)),
compression_factor=8,
topk=8,
)
model = NeurocacheModelForCausalLM(model, config)
input_text = ["Hello, my dog is cute", "Hello, my cat is cute"]
tokenized_input = tokenizer(input_text, return_tensors="pt")
tokenized_input["start_of_sequence"] = torch.tensor([0, 1]).bool()
outputs = model(**tokenized_input)
Supported model types
from neurocache.utils import NEUROCACHE_SUPPORTED_MODELS
print(NEUROCACHE_SUPPORTED_MODELS)
[
"opt",
"llama",
"mistral",
"gptj",
]
Release files for neurocache 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| neurocache-0.0.1.tar.gz | 26.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| neurocache-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 55.6 kB
Release files / neurocache-0.0.1.tar.gz
| Download URL | neurocache-0.0.1.tar.gz |
|---|---|
| Size | 26.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7520ad223a1f03a48132adcd189e9a3a8f0ad28363f75395ae52adfb23f55ec
|
|
BLAKE2b-256 checksum How to use checksums |
75f6d47f2a3950bc39359cb943fd6f871c3e47f2d8049b39c62ddca9ad17d9f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|
Release files / neurocache-0.0.1-py3-none-any.whl
| Download URL | neurocache-0.0.1-py3-none-any.whl |
|---|---|
| Size | 29.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
30eaed454d061804ef63f005fe99d0427c407475eac502b03adf8ecc75e94b40
|
|
BLAKE2b-256 checksum How to use checksums |
af8c685e65a2f7afca86992b738b0065077aa892a616ce71a749d8be8a8cc9c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.10
|