Skip to main content

No project description provided

Project description

fast-GeM

Efficient and general implementation of Generalized Mean Pooling (GeM).

benchmark_result

The original implementation is quite slower due to the F.avg_pool functions.

We provide a new PyTorch implementation that is 4~20 times faster than the original. This implementation is suitable for environments without OpenAI Triton or when the input is a CPU tensor.

Additionally, we offer a Triton-based implementation that is 34 times faster than our new PyTorch implementation and 685 times faster than the original.

Our implementation is easy to use, maintaining a similar interface to the original while supporting flexible input data shapes.

Installation

pip install fast-gem

Usage

For 2D image tensor (batch, channel, width, height):

import torch
from fast_gem import GeM

# for 4D tensor (batch, channel, height, width) case
gem = GeM().cuda()
x = torch.rand(2, 3, 224, 224, device="cuda")
y = gem(x)
y.shape  # shape: (2, 3, 1, 1)

# for 3D tensor (batch, channel, length) case
gem = GeM(dim=-1).cuda()
x = torch.rand(2, 32, 1024, device="cuda")
y = gem(x)
y.shape  # shape: (2, 32, 1)

# for 4D tensor (batch, channel, depth, height, width) case
gem = GeM(dim=-1).cuda()
x = torch.rand(2, 32, 64, 64, 64, device="cuda")
y = gem(x)
y.shape  # shape: (2, 32, 1, 1, 1)

# or you can make not keep 1s and different initial `p` value instead of 3.0
gem = GeM(p=2.0, dim=-1, keepdim=False).cuda()
x = torch.rand(2, 32, 64, 64, 64, device="cuda")
y = gem(x)
y.shape  # shape: (2, 32)

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

fast_gem-0.0.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

fast_gem-0.0.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file fast_gem-0.0.1.tar.gz.

File metadata

  • Download URL: fast_gem-0.0.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for fast_gem-0.0.1.tar.gz
Algorithm Hash digest
SHA256 30229b12b74bfc2fe485e40cbc2ac30f7acb59b8f26b38663e6819393d0cdb6c
MD5 42a62ff3954671ba1f37c7d9b769cb07
BLAKE2b-256 4f5970c5e24210e89c74e07e175695b5328fe62e641703c0b430c193cc2fb495

See more details on using hashes here.

File details

Details for the file fast_gem-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: fast_gem-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for fast_gem-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 89cac4a4f9bc674221d0e144fbd794dcf5c59bdc31f60243d24bfa9bd21cac5d
MD5 7f771dc047c56b21615f05c72ed84378
BLAKE2b-256 99c51dacf9b7fb5fed57eb33e2d927a35724625e5793b337fc43ea57787bb3d2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page