Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

speedtune-0.1.1.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

speedtune-0.1.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file speedtune-0.1.1.tar.gz.

File metadata

  • Download URL: speedtune-0.1.1.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for speedtune-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6fda9adaa92e28808b9145cf677573d06e9788d6c84e97300ce888c103277fa3
MD5 8bbc317a12e89860dfa51c361fa49091
BLAKE2b-256 1cc6083491f53784ddab72599e8bfa99328c7204f1c59bc6cc807bf3d674d59a

See more details on using hashes here.

File details

Details for the file speedtune-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: speedtune-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for speedtune-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d268066c735df35256a1c5e9cf3d08ec0427a53327d48d1571cbd5f7c74725ec
MD5 8f5542991b2a12789a120f61171f7762
BLAKE2b-256 12caaf07488c9783a7d6e95e5acfa2506b48ac7375468b66ddeb3c3119d298d8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page