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 3~4 times faster than our new PyTorch implementation and 6~85 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.2.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

fast_gem-0.0.2-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fast_gem-0.0.2.tar.gz
  • Upload date:
  • Size: 5.6 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.2.tar.gz
Algorithm Hash digest
SHA256 9a35d0879747dbd1f37f98bfe7e32ce916b027f805005acbf9a097281e01e7a4
MD5 ba721f321dbf23e620d65049058bcc6b
BLAKE2b-256 0c7a626ed27e11d65b951ca5236dab57a35feb90891a58aeee0590491eac842d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fast_gem-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.9 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ac65f3a15cfa50354775ff5c7224cebbf644c1a95e9393721b7906771316ccb4
MD5 fb57879ddfee3795caad9402e518be47
BLAKE2b-256 a5ba905d275ffaa4d48a65a89ec93e8f30b4339754ecbce51900f3ce5db3aa89

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