Skip to main content

Spline-Based Transformer

Implementation of the proposed Spline-Based Transformer (paper) from Disney Research

This is basically a transformer based autoencoder, but they cleverly use a set of latent tokens, where that set of tokens are the (high dimensional) control points for a spline.

Install

$ pip install spline-based-transformer

Usage

import torch
from spline_based_transformer import SplineBasedTransformer

model = SplineBasedTransformer(
    dim = 512,
    enc_depth = 6,
    dec_depth = 6
)

data = torch.randn(1, 1024, 512)

loss = model(data, return_loss = True)
loss.backward()

# after much training

recon, control_points = model(data, return_latents = True)
assert data.shape == recon.shape

# mess with the control points, which should preserve continuity better

control_points += 1

controlled_recon = model.decode_from_latents(control_points, num_times = 1024)
assert controlled_recon.shape == data.shape

For an example of an image autoencoder

import torch

from spline_based_transformer import (
    SplineBasedTransformer,
    ImageAutoencoderWrapper
)

model = ImageAutoencoderWrapper(
    image_size = 256,
    patch_size = 32,
    spline_transformer = SplineBasedTransformer(
        dim = 512,
        enc_depth = 6,
        dec_depth = 6
    )
)

images = torch.randn(2, 3, 256, 256)

loss = model(images, return_loss = True)
loss.backward()

# after much training

recon_images, control_points = model(images, return_latents = True)
assert images.shape == recon_images.shape

# changing the control points

control_points += 1

controlled_recon_images = model.decode_from_latents(control_points)

assert controlled_recon_images.shape == images.shape

Citations

@misc{Chandran2024,
    author  = {Prashanth Chandran, Agon Serifi, Markus Gross, Moritz Bächer},
    url     = {https://la.disneyresearch.com/publication/spline-based-transformers/}
}

Metadata

Release files for spline-based-transformer 0.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spline-based-transformer 0.0.14
File Size Uploaded
spline_based_transformer-0.0.14.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spline-based-transformer 0.0.14
File Interpreter ABI Platform
spline_based_transformer-0.0.14-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 kB

Release files / spline_based_transformer-0.0.14.tar.gz

Download URL spline_based_transformer-0.0.14.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f023c41004b47c54639ca61288ba7fef979e19f9b076f06e618b22a6aaca86a2
BLAKE2b-256 checksum
How to use checksums
4376487dfa448da9ad2a987abf4e7823ca328cbca7cc2e20154029f6e5f48d9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / spline_based_transformer-0.0.14-py3-none-any.whl

Download URL spline_based_transformer-0.0.14-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
be0f28c8254c07cd1b47d250b973c8b868c8584485eb8fbeebb9095f2182bf69
BLAKE2b-256 checksum
How to use checksums
ba1aedd7f34fa04836c0c27a8594092d26a7a0088f67add25a3e39d09d1aac07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release history Release notifications | RSS feed

This release

0.0.14 This release

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page