Thin wrappers around transformers to help speed up training/fine-tuning.
Project description
speedtune
Lightweight helpers to "patch" token embeddings for causal and seq2seq
transformer models. Grouping tokens into fixed-size patches reduces the
effective sequence length and can speed up training or inference for long
inputs. The project provides a thin wrapper around Hugging Face
transformers models that computes patch-level embeddings and forwards them to
the base model while preserving a compatible forward API.
Features
- Compress token embeddings into patches (mean pooling by default).
- Forward patched embeddings to causal LMs and seq2seq LMs (seq2seq implementation pending).
- Optional user-provided patch function for custom aggregation.
Quick install
This package requires PyTorch and Hugging Face Transformers. Because PyTorch is platform-specific (CPU vs GPU/CUDA), install it first following the official instructions for your platform, then install this package.
Example (Windows PowerShell):
# create venv and activate
python -m venv .venv; .\.venv\Scripts\Activate.ps1
# Install PyTorch for your platform first. Example CPU-only wheel:
pip install "torch>=2.0.0" --index-url https://download.pytorch.org/whl/cpu
# Then install transformers and this package
pip install "transformers>=4.30.0"
pip install -U pip build wheel twine
# Build and install the local wheel for development/testing
python -m build
pip install dist\speedtune-0.1.1py3-none-any.whl
Minimal usage example
import torch
from speedtune.speedtune import AutoPatchModelForCausalLM
# Create wrapper around a pretrained model (small model for quick tests)
model = AutoPatchModelForCausalLM.from_pretrained("gpt2", patch_size=2)
model.eval()
input_ids = torch.tensor([[50256, 50257, 50258, 50259]]) # example token ids
outputs = model(input_ids=input_ids)
logits = outputs.logits
Testing
Run the unit tests with pytest after installing test dependencies:
# from the repo root
pip install pytest
pytest -q
License
This project is MIT licensed (see LICENSE).
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 speedtune-0.1.2.tar.gz.
File metadata
- Download URL: speedtune-0.1.2.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fee008fdabb6c041c1f1e9605a1cdf48d02383843c9fedd59f0a5c4c401f2344
|
|
| MD5 |
450238e28c29942b04c4f5f851590d1b
|
|
| BLAKE2b-256 |
b1adff10fd62d8f7d0a2aec73cf5ccfd00bea1a2d526497f625c64148502c831
|
File details
Details for the file speedtune-0.1.2-py3-none-any.whl.
File metadata
- Download URL: speedtune-0.1.2-py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
355ad4924bc2427840fbf6b60f3a00b296d39c2b188fa46bdd4e9f2b3c0219a9
|
|
| MD5 |
2366f967688e41cabb1acffc24e65c15
|
|
| BLAKE2b-256 |
0c8e08072ca3ae92c5ad3cc6cc270f539cd5e1053887a2d12d2db27be980f7e0
|