The torch_liberator Module
Project description
Main Page |
|
Github Mirror |
|
Pypi |
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
Built Distributions
File details
Details for the file torch_liberator-0.0.4.tar.gz
.
File metadata
- Download URL: torch_liberator-0.0.4.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 033be2f25c5d0c3398cb1502ca1777556eaadeda5d7c0c9cea2778347489a55a |
|
MD5 | af5910672787c4ea6f7116938742ad00 |
|
BLAKE2b-256 | 2c44c431c574b1f77c103fa0099df5a7ccfd47471a7e17bfeeb5f18c43322103 |
File details
Details for the file torch_liberator-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: torch_liberator-0.0.4-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e103cd14bcbc1073e9f3cda176654d2e9e6ecf822a66ddcf753e5a2d8406894 |
|
MD5 | e66d09fe8569d1bd45761c28067b7744 |
|
BLAKE2b-256 | 192b767ecaf47b98f7cafb8d56036f2291a9aa076ce3528109c539ec4b43d793 |
File details
Details for the file torch_liberator-0.0.4-py2.py3-none-any.whl
.
File metadata
- Download URL: torch_liberator-0.0.4-py2.py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 410dc40737e16546eb654c72a88c9f7594499abb521f565c70c6dacce14b0f61 |
|
MD5 | 9b8ee7f931739f9fb227ed2eb6c1640f |
|
BLAKE2b-256 | 520baeca6d280bdacd8527ff08df41fa245483322af264f49174930579bdab4b |