Skip to main content

graftr: an interactive shell to view and edit PyTorch checkpoints.

Project description

graftr

PyPI Release License

An interactive shell to view and edit PyTorch checkpoints.

graftr cast

graftr can be used to remove, rename, and move around the layers and parameters of your saved model. It's also a handy tool to peek into the structure of pre-trained PyTorch models that you can find online (e.g. Transformer, DCGAN, etc.).

The screencast above shows an example of taking a pre-trained Densenet and preparing it for integration into a larger model. We remove the final classification layer and move the feature extractor into its own densenet module.

Install

pip install graftr

Documentation

graftr presents a hierarchical directory structure for state_dicts and parameters in your checkpoint. You can list (ls), move/rename (mv), and print (cat) parameters. And, of course, you can navigate (cd) through the hierarchy. It also supports standard shell beahvior like command history, up-arrow, tab-completion, etc.

All changes are kept in-memory until you're ready to write them back to your checkpoint with save.

Supported commands

  • cd - change working directory.
  • pwd - print working directory.
  • ls - list directory contents.
  • cat - print the contents of a value or directory.
  • cp - copy value or directory.
  • mv - move/rename value or directory.
  • rm - remove value or directory.
  • parameters - print the number of model parameters under a directory.
  • shape - print tensor shape.
  • device - get or set the device of a tensor or group of tensors.
  • save - write back changes to disk.
  • where - print the location on disk where changes will be saved.
  • exit - exits the shell.

FAQ

Should this be a mountable user-mode filesystem instead?

Maybe? Some operations (e.g. shape, parameters, device) don't map easily onto standard filesystem operations. On the other hand, it would be interesting to insert/extract tensors by copying NumPy files in and out of the virtual filesystem.

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

graftr-0.1.2.tar.gz (7.4 kB view details)

Uploaded Source

File details

Details for the file graftr-0.1.2.tar.gz.

File metadata

  • Download URL: graftr-0.1.2.tar.gz
  • Upload date:
  • Size: 7.4 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.6.0.post20200814 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.8.5

File hashes

Hashes for graftr-0.1.2.tar.gz
Algorithm Hash digest
SHA256 5d8e58c3dff6332f8c9f8b42ece27fecb8a8d05d1a93d87df5be31e35d465f4a
MD5 d5337a39e83f0ed63c47312e8817b067
BLAKE2b-256 e63a39069e84011aace2aea327cd9d1b12fd8efc062e09dae4faad48423bb881

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