Skip to main content

VGSLify: Variable-size Graph Specification for TensorFlow & PyTorch

PyPI Downloads License

VGSLify simplifies defining, training, and interpreting deep learning models using the Variable-size Graph Specification Language (VGSL). Inspired by Tesseract's VGSL specs, VGSLify enhances and streamlines the process for both TensorFlow and PyTorch.

Table of Contents

Installation

Basic Installation

To install VGSLify without any deep learning backend, run:

pip install vgslify

This installs only the core functionalities of VGSLify without torch or tensorflow.

Installing with a Specific Backend

VGSLify supports both TensorFlow and PyTorch. You can install it with the required backend:

# For TensorFlow (latest compatible version)
pip install vgslify[tensorflow]

# For PyTorch (latest compatible version)
pip install vgslify[torch]

By default, this will install:

  • tensorflow (latest stable version)
  • torch (latest stable version)

Controlling Backend Versions

If you need a specific version of torch or tensorflow, install VGSLify first and then manually install the backend:

pip install vgslify
pip install torch==2.1.0      # Example for PyTorch
pip install tensorflow==2.14  # Example for TensorFlow

Alternatively, you can specify the version during installation:

pip install vgslify[torch] torch==2.1.0
pip install vgslify[tensorflow] tensorflow==2.14

⚠ Note: If a different version of torch or tensorflow is already installed, pip may not downgrade it automatically. Use --force-reinstall or --upgrade if necessary:

pip install --upgrade --force-reinstall torch==2.1.0

Verify installation

To check that VGSLify is installed correctly, run:

python -c "import vgslify; print(vgslify.__version__)"

How VGSL Works

VGSL uses concise strings to define model architectures. For example:

None,None,64,1 Cr3,3,32 Mp2,2 Cr3,3,64 Mp2,2 Rc3 Fr64 D20 Lrs128 D20 Lrs64 D20 Fs92

Each part represents a layer: input, convolution, pooling, reshaping, fully connected, LSTM, and output. VGSL allows specifying activation functions for customization.

Quick Start

Generating a Model with VGSLify

from vgslify import VGSLModelGenerator

# Define the VGSL specification
vgsl_spec = "None,None,64,1 Cr3,3,32 Mp2,2 Fs92"

# Choose backend: "tensorflow", "torch", or "auto" (defaults to whichever is available)
vgsl_gn = VGSLModelGenerator(backend="tensorflow") 
model = vgsl_gn.generate_model(vgsl_spec, model_name="MyModel")
model.summary()


vgsl_gn = VGSLModelGenerator(backend="torch") # Switch to PyTorch
model = vgsl_gn.generate_model(vgsl_spec, model_name="MyTorchModel")
print(model)

Creating Individual Layers with VGSLify

from vgslify import VGSLModelGenerator

vgsl_gn = VGSLModelGenerator(backend="tensorflow")
conv2d_layer = vgsl_gn.construct_layer("Cr3,3,64")

# Integrate into an existing model:
# model = tf.keras.Sequential()
# model.add(conv2d_layer) # ...

# Example with generate_history:
history = vgsl_gn.generate_history("None,None,64,1 Cr3,3,32 Mp2,2 Fs92")
for layer in history:
    print(layer)

Converting Models to VGSL

from vgslify import model_to_spec
import tensorflow as tf
# Or import torch.nn as nn

# TensorFlow example:
model = tf.keras.models.load_model("path_to_your_model.keras") # If loading from file

# PyTorch example:
# model = MyPyTorchModel() # Assuming MyPyTorchModel is defined elsewhere


vgsl_spec_string = model_to_spec(model)
print(vgsl_spec_string)

Note: Flatten/Reshape layers might require manual input shape adjustment in the generated VGSL.

Additional Documentation

See the VGSL Documentation for more details on supported layers and their specifications.

Contributing

Contributions are welcome! Fork the repository, set up your environment, make changes, and submit a pull request. Create issues for bugs or suggestions.

License

MIT License. See LICENSE file.

Acknowledgements

Thanks to the creators and contributors of the original VGSL specification.

Metadata

Release files for vgslify 0.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vgslify 0.14.0
File Size Uploaded
vgslify-0.14.0.tar.gz 2.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for vgslify 0.14.0
File Interpreter ABI Platform
vgslify-0.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 5.7 MB

Release files / vgslify-0.14.0.tar.gz

Download URL vgslify-0.14.0.tar.gz
Size 2.8 MB
Tags Source
SHA-256 checksum
How to use checksums
197ea8a85f7d77f7cdd0369ea698ece458d2d7c08d89adb6e1a2a1d782d7e7b7
BLAKE2b-256 checksum
How to use checksums
a44fbef90a96b011290605e50ac0ede063b98a3a2aeede23371764becbd292f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.9

Release files / vgslify-0.14.0-py3-none-any.whl

Download URL vgslify-0.14.0-py3-none-any.whl
Size 2.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b54c2ed2835f42a8a03e412b7c5ad2e51d038e33897ee915528a67c4d767be9f
BLAKE2b-256 checksum
How to use checksums
4c19999cf1e88a9011511b42e745120032624d64d9a5090a0e3e546099317ee9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.11.9

Release history Release notifications | RSS feed

This release

0.14.0 This release

2 release files

0.13.3

2 release files

0.13.2

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.1

2 release files

0.9.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page