|
| 1 | +Bolts |
| 2 | +===== |
| 3 | +`PyTorch Lightning Bolts <https://pytorch-lightning-bolts.readthedocs.io/en/latest/>`_, is our official collection |
| 4 | +of prebuilt models across many research domains. |
| 5 | + |
| 6 | +.. code-block:: bash |
| 7 | +
|
| 8 | + pip install pytorch-lightning-bolts |
| 9 | +
|
| 10 | +In bolts we have: |
| 11 | + |
| 12 | +- A collection of pretrained state-of-the-art models. |
| 13 | +- A collection of models designed to bootstrap your research. |
| 14 | +- A collection of Callbacks, transforms, full datasets. |
| 15 | +- All models work on CPUs, TPUs, GPUs and 16-bit precision. |
| 16 | + |
| 17 | +----------------- |
| 18 | + |
| 19 | +Quality control |
| 20 | +--------------- |
| 21 | +Bolts are built-by the Lightning community and contributed to bolts. |
| 22 | +The lightning team guarantees that contributions are: |
| 23 | + |
| 24 | +- Rigorously Tested (CPUs, GPUs, TPUs) |
| 25 | +- Rigorously Documented |
| 26 | +- Standardized via PyTorch Lightning |
| 27 | +- Optimized for speed |
| 28 | +- Checked for correctness |
| 29 | + |
| 30 | +--------- |
| 31 | + |
| 32 | +Example 1: Pretrained, prebuilt models |
| 33 | +-------------------------------------- |
| 34 | + |
| 35 | +.. code-block:: python |
| 36 | +
|
| 37 | + from pl_bolts.models import VAE, GPT2, ImageGPT, PixelCNN |
| 38 | + from pl_bolts.models.self_supervised import AMDIM, CPCV2, SimCLR, MocoV2 |
| 39 | + from pl_bolts.models import LinearRegression, LogisticRegression |
| 40 | + from pl_bolts.models.gans import GAN |
| 41 | + from pl_bolts.callbacks import PrintTableMetricsCallback |
| 42 | + from pl_bolts.datamodules import FashionMNISTDataModule, CIFAR10DataModule, ImagenetDataModule |
| 43 | +
|
| 44 | +------------ |
| 45 | + |
| 46 | +Example 2: Extend for faster research |
| 47 | +------------------------------------- |
| 48 | +Bolts are contributed with benchmarks and continuous-integration tests. This means |
| 49 | +you can trust the implementations and use them to bootstrap your resarch much faster. |
| 50 | + |
| 51 | +.. code-block:: python |
| 52 | +
|
| 53 | + from pl_bolts.models import ImageGPT |
| 54 | + from pl_bolts.self_supervised import SimCLR |
| 55 | +
|
| 56 | + class VideoGPT(ImageGPT): |
| 57 | +
|
| 58 | + def training_step(self, batch, batch_idx): |
| 59 | + x, y = batch |
| 60 | + x = _shape_input(x) |
| 61 | +
|
| 62 | + logits = self.gpt(x) |
| 63 | + simclr_features = self.simclr(x) |
| 64 | +
|
| 65 | + # ----------------- |
| 66 | + # do something new with GPT logits + simclr_features |
| 67 | + # ----------------- |
| 68 | +
|
| 69 | + loss = self.criterion(logits.view(-1, logits.size(-1)), x.view(-1).long()) |
| 70 | +
|
| 71 | + logs = {"loss": loss} |
| 72 | + return {"loss": loss, "log": logs} |
| 73 | +
|
| 74 | +---------- |
| 75 | + |
| 76 | +Example 3: Callbacks |
| 77 | +-------------------- |
| 78 | +We also have a collection of callbacks. |
| 79 | + |
| 80 | +.. code-block:: python |
| 81 | +
|
| 82 | + from pl_bolts.callbacks import PrintTableMetricsCallback |
| 83 | + import pytorch_lightning as pl |
| 84 | +
|
| 85 | + trainer = pl.Trainer(callbacks=[PrintTableMetricsCallback()]) |
| 86 | +
|
| 87 | + # loss│train_loss│val_loss│epoch |
| 88 | + # ────────────────────────────── |
| 89 | + # 2.2541470527648926│2.2541470527648926│2.2158432006835938│0 |
0 commit comments