ptmod: Modify PyTorch model
A Command line utility to modify serialized PyTorch model states.
The definition of pytorch model file
In the context of this text, a model file should be a serialized state_dict object. See for mote detail: https://pytorch.org/docs/stable/notes/serialization.html
# e.g.
import torch
class Block(torch.nn.Module):
def __init__(self):
super().__init__()
self.layer1 = torch.nn.Linear(10, 10)
self.layer2 = torch.nn.Linear(10, 10)
class Model(torch.nn.Module):
def __init__(self):
super().__init__()
self.block1 = Block()
self.block2 = Block()
model = Model()
torch.save(model.state_dict(), "model.pth")
Show the contents in a model file
Usage
ptmod-ls model.pth
# OR
ptmod "ls model.pth"
Example
% ptmod "ls model.pth"
block1.layer1.weight
block1.layer1.bias
block1.layer2.weight
block1.layer2.bias
block2.layer1.weight
block2.layer1.bias
block2.layer2.weight
block2.layer2.bias
% ptmod "ls -l model.pth"
block1.layer1.weight (10, 10)
block1.layer1.bias (10,)
block1.layer2.weight (10, 10)
block1.layer2.bias (10,)
block2.layer1.weight (10, 10)
block2.layer1.bias (10,)
block2.layer2.weight (10, 10)
block2.layer2.bias (10,)
Copy parameters
Usage
ptmod-cp model.pth:key out.pth:key2
# OR
ptmod "cp model.pth:key out.pth:key2"
Example
% ptmod "cp model.pth:block1 out.pth" "ls out.pth"
layer1.weight
layer1.bias
layer2.weight
layer2.bias
% ptmod "cp model.pth:block1 out.pth:foo" "ls out.pth"
foo.layer1.weight
foo.layer1.bias
foo.layer2.weight
foo.layer2.bias
Remove parameters
Usage
ptmod-rm model.pth:key
# OR
ptmod "rm model.pth:key"
Example
% ptmod "cp model.pth out.pth" "rm out.pth:block1" "ls out.pth"
block2.layer1.weight
block2.layer1.bias
block2.layer2.weight
block2.layer2.bias
% ptmod "cp model.pth out.pth" "rm out.pth:block2.layer2" "ls out.pth"
block2.layer1.weight
block2.layer1.bias
block1.layer1.weight
block1.layer1.bias
block1.layer2.weight
block1.layer2.bias
Sum/Average parameters
Usage
ptmod-average out.pth model1.pth model2.pth ...
# OR
ptmod "average out.pth model1.pth model2.pth ...
Example
% ptmod "average out.pth model1.pth model2.pth"
% ptmod "sum out.pth model1.pth model2.pth"
Metadata
Release files for ptmod 0.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ptmod-0.0.0.tar.gz | 3.4 kB | Without provenance | Details for ptmod-0.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ptmod-0.0.0-py3-none-any.whl | Python 3 | none | any | Details for ptmod-0.0.0-py3-none-any.whl |
Total release size: 7.8 kB
Release files / ptmod-0.0.0.tar.gz
| Download URL | ptmod-0.0.0.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e2ceace3f70fb8469ccd21b4594ea53626f49500359df44ee8448f0d3303e38a
|
|
BLAKE2b-256 checksum How to use checksums |
514a54de15788171681d0c81a05c63b9b377179cfe2699ea9246132c52a25814
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0.post20200127 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.4
|
Release files / ptmod-0.0.0-py3-none-any.whl
| Download URL | ptmod-0.0.0-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e27f71515db3e210e76c894a0196c2bfc91735bc7a51bfc1ef68b71184c5ffb0
|
|
BLAKE2b-256 checksum How to use checksums |
8acbf53057e1b4e5c6d7dcd07bc777f9b9dc2616027f02e646084fa5582f3026
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0.post20200127 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.4
|
Security for ptmod 0.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.