Lightning Transformers Versions Save

Flexible components pairing 🤗 Transformers with :zap: Pytorch Lightning

0.2.5

1 year ago

[0.2.5] - 2022-11-21

Fixed

  • Fixed loading HF model (#306)
  • Fixed passing config name to CNNDailyMailSummarizationDataModule (#310)
  • Fixed move pipeline to self.device as default (#309)

New Contributors

Full Changelog: https://github.com/Lightning-AI/lightning-transformers/compare/0.2.4...0.2.5

0.2.4

1 year ago

[0.2.4] - 2022-11-04

Changed

  • Added support for Lightning v1.8.0 (#297)

Contributors

@rohitgr7

Full Changelog: https://github.com/Lightning-AI/lightning-transformers/compare/0.2.3...0.2.4

0.2.3

1 year ago

Use Lightning Utilities (#292) by @Borda

Full Changelog: https://github.com/Lightning-AI/lightning-transformers/compare/0.2.2...0.2.3

0.2.2

1 year ago

Update tests for latest PL release (#284) by @rohitgr7

Full Changelog: https://github.com/Lightning-AI/lightning-transformers/compare/0.2.1...0.2.2

0.2.1

1 year ago

⚡ Lightning Transformers 0.2.1

This is an incremental release with some documentation changes, DeepSpeed training support and a refactor to expose transformer model creation.

What's Changed

New Contributors

Full Changelog: https://github.com/Lightning-AI/lightning-transformers/compare/0.2.0...0.2.1

0.2.0

1 year ago

⚡ Lightning Transformers 0.2.0 Release

Below is a summary of the features/fixes we’ve added since the previous release!

ViT Image Classification 🚀

Thanks to @tanmoyio we now have ViT support within Lightning Transformers!

Here is a simple example showing how you can fine-tune a ViT model using Lightning Transformers:

import pytorch_lightning as pl
from transformers import AutoFeatureExtractor

from lightning_transformers.task.vision.image_classification import (
    ImageClassificationDataModule,
    ImageClassificationTransformer,
)

feature_extractor = AutoFeatureExtractor.from_pretrained(pretrained_model_name_or_path="nateraw/vit-base-beans")
dm = ImageClassificationDataModule(
    batch_size=8, 
    dataset_name="beans", 
    num_workers=8,
    feature_extractor=feature_extractor,
)
model = ImageClassificationTransformer(
    pretrained_model_name_or_path="nateraw/vit-base-beans", num_labels=dm.num_classes
)

trainer = pl.Trainer(accelerator="auto", devices="auto", max_epochs=5)
trainer.fit(model, dm)

More information in our documentation.

Save HuggingFace Hub Compatible Checkpoints 💾

Many users have requested the ability to save HF Hub-compatible models. Look no further, we offer manual support + saving an additional HF compatible checkpoint automatically during training.

from lightning_transformers.task.nlp.text_classification import TextClassificationTransformer

model = TextClassificationTransformer(pretrained_model_name_or_path="prajjwal1/bert-tiny")

# saves a HF checkpoint to this path.
model.save_hf_checkpoint("checkpoint")

To save via training, just pass the HFSaveCheckpoint plugin within your training code:

import pytorch_lightning as pl
from lightning_transformers.plugins.checkpoint import HFSaveCheckpoint
...

model = TextClassificationTransformer(pretrained_model_name_or_path="prajjwal1/bert-tiny")
trainer = pl.Trainer(plugins=HFSaveCheckpoint(model=model))
trainer.fit(model, dm)

Big Model Inference 🤖

As transformer models get larger, they require more compute to run. In Lightning Transformers, we've utilized HF Accelerate to allow users to run billion parameter model inference.

This will in turn allow people who do not have the GPU memory or compute to run these models, by leveraging CPU memory & compute and disk space!

import torch
from accelerate import init_empty_weights
from transformers import AutoTokenizer
from lightning_transformers.task.nlp.language_modeling import LanguageModelingTransformer

# initializes empty model for us to the load the checkpoint.
with init_empty_weights():
model = LanguageModelingTransformer(
   pretrained_model_name_or_path="EleutherAI/gpt-j-6B",
   tokenizer=AutoTokenizer.from_pretrained("EleutherAI/gpt-j-6B")
)

# automatically selects the best devices (cpu/gpu) to load model layers based on available memory
# even offloads to disk if necessary.
model.load_checkpoint_and_dispatch("sharded-gpt-j-6B", device_map="auto", no_split_module_classes=["GPTJBlock"])

output = model.generate("Hello, my name is", device=torch.device("cuda"))
print(model.tokenizer.decode(output[0].tolist()))

SparseML Support 🔍

We now have native support for SparseML! SparseML provides GPU-class performance on CPUs through sparsification, pruning, and quantization.

To enable SparseML, all you do is pass the callback to the Lightning Trainer with paths to your recipe!

import pytorch_lightning as pl

from lightning_transformers.callbacks import TransformerSparseMLCallback

pl.Trainer(
    callbacks=TransformerSparseMLCallback(
        output_dir="/content/MODELS",
        recipe_path="/content/recipe.yaml"
    )
)

See our medium blog post for more details.

Align with PyTorch Lightning ⚡

Within this release we've simplified the API, removing complicated internal boilerplate and configuration that should exist outside this library. Keeping this library minimal means easier extensibility and easier contributions for everyone 🔥

Thanks to all the contributors that helped out!

0.2.0rc1

1 year ago

0.1.0

3 years ago

The first release for Lightning Transformers!

Lightning Transformers offers a flexible interface for training and fine-tuning SOTA Transformer models using the PyTorch Lightning Trainer.

  • Train using HuggingFace Transformers models and datasets with Lightning custom Callbacks, Loggers, Accelerators and high performance scaling.
  • Seamless Memory and Speed Optimizations such as DeepSpeed ZeRO or FairScale Sharded Training with no code changes.
  • Powerful config composition backed by Hydra - Easily swap out models, optimizers, schedulers and many more configurations without touching the code.
  • Transformer Task Abstraction for Rapid Research & Experimentation - Built from the ground up to be task agnostic, the library supports creating transformer tasks across all modalities with little friction.

Lightning Transformers tasks allow you to train models using HuggingFace Transformer models and datasets, use Hydra to hotswap models, optimizers or schedulers and leverage all the advances features that Lightning has to offer, including custom Callbacks, Loggers, Accelerators and high performance scaling with minimal changes.

In this release, we introduce these Transformer Tasks to train and predict:

  • Casual Language Modeling
  • Multiple Choice
  • Question Answering
  • Summarization
  • Text Classification
  • Token Classification
  • Translation

Each task supports various datasets, see our documentation for more information!