Skip to main content

The torch_liberator Module

Project description

GitlabCIPipeline GitlabCICoverage Pypi Downloads

Main Page

https://gitlab.kitware.com/computer-vision/torch_liberator

Github Mirror

https://github.com/Kitware/torch_liberator

Pypi

https://pypi.org/project/torch_liberator

Torch Liberator builds on the “liberator” library to statically extract pytorch code that defines a model’s topology and bundle that with a pretrained weights file. This results in a single-file deployment package and can potentially remove dependencies on the codebase used to train the model.

For more info on the base “liberator” package see: https://gitlab.kitware.com/python/liberator or https://github.com/Kitware/liberator

Torch Liberator can also read these deployment files and create an instance of the model initialized with the correct pretrained weights.

The API is ok, but it does need improvement. However, the current version is in a working state. There aren’t any high level docs, but there are a lot of docstrings and doctests. The example here gives a good overview of the code by extracting the AlexNet model from torchvision.

>>> import torch_liberator
>>> from torch_liberator.deployer import DeployedModel
>>> from torchvision import models

>>> print('--- DEFINE A MODEL ---')
>>> model = models.alexnet(pretrained=False)  # false for test speed
>>> initkw = dict(num_classes=1000)  # not all models nicely supply this
>>> model._initkw = initkw
--- DEFINE A MODEL ---

>>> print('--- DEPLOY THE MODEL ---')
>>> zip_fpath = torch_liberator.deploy(model, 'test-deploy.zip')
--- DEPLOY THE MODEL ---
[DEPLOYER] Deployed zipfpath=/tmp/tmpeqd3y_rx/test-deploy.zip


>>> print('--- LOAD THE DEPLOYED MODEL ---')
>>> loader = DeployedModel(zip_fpath)
>>> model = loader.load_model()
--- LOAD THE DEPLOYED MODEL ---
Loading data onto None from <zopen(<_io.BufferedReader name='/tmp/tmpg1kln3kw/test-deploy/deploy_snapshot.pt'> mode=rb)>
Pretrained weights are a perfect fit

The major weirdness right now, is you either have to explicitly define “initkw” (which are the keyword arguments used to create an instance of our model) at deploy time, or you can set it as the _initkw attribute of your model (or if your keyword arguments all exist as member variables of the class, torch_liberator tries to be smart and infer what initkw should be).

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

torch_liberator-0.0.3.tar.gz (22.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

torch_liberator-0.0.3-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

torch_liberator-0.0.3-py2.py3-none-any.whl (21.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file torch_liberator-0.0.3.tar.gz.

File metadata

  • Download URL: torch_liberator-0.0.3.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for torch_liberator-0.0.3.tar.gz
Algorithm Hash digest
SHA256 cacdb913b202b8fff6faeb0184dda84d0b6eebd01251930322c8753efb5e6d4e
MD5 03dcb02d005d149657a6d0a17e577182
BLAKE2b-256 13fdb105dc12c67dc5f09367038b82bdc7a54e6730748d5dc617d68dfbe46d13

See more details on using hashes here.

File details

Details for the file torch_liberator-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: torch_liberator-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for torch_liberator-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d5ccdf8c210673a853991f254dc0ceafff94bbc6b0025ddddab075ed0f0f6120
MD5 603e8180e749dd70f513c3d49693a744
BLAKE2b-256 a801ee6b83069817634807f56d84f77d18b060056743a3c80fccc9be0eb58455

See more details on using hashes here.

File details

Details for the file torch_liberator-0.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: torch_liberator-0.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

File hashes

Hashes for torch_liberator-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5a634e88aa09fccf7521beb86f15dcc2f9e3895ec424936a414bdaafbfd2d242
MD5 d5354fdb477f8b0136473314830705c0
BLAKE2b-256 990f7eb9169af44b7f02b900fa0cbf647b5fa6b11ec1f98851667645955e873b

See more details on using hashes here.

Supported by

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