Skip to main content

Placeholder description for the speedtune package.

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 (planned) seq2seq LMs.
  • 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.0-py3-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.0.tar.gz (12.7 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.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: speedtune-0.1.0.tar.gz
  • Upload date:
  • Size: 12.7 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.0.tar.gz
Algorithm Hash digest
SHA256 9af39430c465b6367cc16ad6ab76294f440ce30613c42549563f12bae5673cb8
MD5 6e5a6b73ff47fb58fcd75bee06f31e3c
BLAKE2b-256 2ecd2dff7a5e323777497cf9f84d6afdb9693ba465be689cb4875485f852b79d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: speedtune-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 155c0e6b89e6429abdb1f75868cc4bb768a00b947491b739d1c2fe54d1d5483e
MD5 111584cdca4005ea476a1b2612bf2064
BLAKE2b-256 a84851d259ddb8a6498d326ee1fdc30105dfbe89a6f6504ab9f90bccbdffa328

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