Skip to main content

Pool Resources

Project description

Pool Resources

Description

Library to generalize multiprocessing.Pool(n: int) to handle generic resources.

First class support for torch devices as a generic resource.

Example for n torch GPUs and k torch Modules

from pool_resources import PoolResources
from pool_resources.resources import TorchResource

class Model(nn.Module):
    def __init__(self, input_shape, output_shape):
        super().__init__()
        self.fc = nn.Linear(input_shape, output_shape)

    def forward(self, x):
        return self.fc(x)

def forward_fn(item):
    model, data = item
    return model.forward(data)

modules = [Model(input_shape=20, output_shape=30) for _ in range(k)]
data = tr.randn(k, B, 20)
seq = zip(modules, data)

resources = [TorchResource(f"cuda:{i}") for i in range(n)]

res_sequential = list(map(forward_fn, seq))
res_parallel = PoolResources(resources).map(forward_fn, seq)


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

pool-resources-0.3.0.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file pool-resources-0.3.0.tar.gz.

File metadata

  • Download URL: pool-resources-0.3.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.18

File hashes

Hashes for pool-resources-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8512e2424536797a84bd7b9fd9802cc50fc9aa952d38f0437332d9cd7152b6cb
MD5 d77cc5e4e77da1533095c5b80f23ce4b
BLAKE2b-256 afc0674fbc0a3ca7df7ac5cba7ca8262e4332b172f10dcbfbf5faa9a1a5809da

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