Skip to main content

Large autoregressive language modeling helpers

Project description

transformer-utils

Utilities for the HuggingFace transformer library, focused on loading and using large pretrained autoregressive language models like GPT-2 and GPT-Neo.

This package is unofficial and not associated with HuggingFace.

Example usage

Loading in low-memory environments

Loading a 2.7B model:

from transformer_utils.low_memory import enable_low_memory_load

enable_low_memory_load()

model = transformers.AutoModelForCausalLM.from_pretrained('EleutherAI/gpt-neo-2.7B')

This works fine in an ordinary (non-Pro) Google Colab notebook, with ~12 GB RAM and a T5 GPU.

Inference will work up to the full context window length of 2048 tokens without memory issues.

Logit lens

import torch
import transformers
from transformer_utils.low_memory import enable_low_memory_load

enable_low_memory_load()

tokenizer = transformers.AutoTokenizer.from_pretrained("gpt2")
model = transformers.AutoModelForCausalLM.from_pretrained('gpt2-xl')

def text_to_input_ids(text):
    toks = tokenizer.encode(text)
    return torch.as_tensor(toks).view(1, -1).cuda()

input_ids = text_to_input_ids("This is an example. You can probably think of a more fun text to use than this one.")

plot_logit_lens(model, tokenizer, input_ids, start_ix=0, end_ix=45)  # logits

plot_logit_lens(model, tokenizer, input_ids, start_ix=0, end_ix=45, probs=True)  # probabilities

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

transformer-utils-0.0.8.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

transformer_utils-0.0.8-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file transformer-utils-0.0.8.tar.gz.

File metadata

  • Download URL: transformer-utils-0.0.8.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.6

File hashes

Hashes for transformer-utils-0.0.8.tar.gz
Algorithm Hash digest
SHA256 56516d5afc747807ab573f4acf05ea822e1ef85f2c856517008e05cd33649863
MD5 5f36fdf9231e5b679969ee90259037d6
BLAKE2b-256 1eeaff2c69352d620031c2b8fb4fc2022248262478b75ddf8a1bf165682d9248

See more details on using hashes here.

File details

Details for the file transformer_utils-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: transformer_utils-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.6

File hashes

Hashes for transformer_utils-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 a8bc71ca8ad6a96bc27379c931eb3fded568d34edd1920afac757a7f30b71d4b
MD5 e1ef6b9e5dd58973bdf79c1ccc6cf82f
BLAKE2b-256 b712079cd78b9c4d07f6b2987e412c47b72b4491f70302e8f4eb8b2a95cbf4f3

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