Skip to content

v0.14.0

Latest

Choose a tag to compare

@TimKoornstra TimKoornstra released this 02 Feb 12:05

VGSLify v0.14.0 Release Notes

Summary

This release adds the ability to register and parse custom layers for both TensorFlow and PyTorch backends in VGSLify. It also introduces a few breaking changes related to file organization and simplifies import paths to make the library easier to use.

New Features

  1. Custom Layer Registration (TensorFlow and PyTorch)

    • You can now register custom layer builder functions directly with the TensorFlowLayerFactory (and similarly with the Torch layer factory).

      from vgslify.tensorflow import TensorFlowLayerFactory
      
      @classmethod
      def register(cls, prefix: str, builder_fn):
          ...
    • Alternatively, use the new decorator approach:

      from vgslify.tensorflow import register_custom_layer
      
      @register_custom_layer("Xsw")
      def build_custom_layer(factory, spec):
          # Custom layer logic
          return tf.keras.layers.Dense(10)
    • This allows users to incorporate any custom TensorFlow or PyTorch layers into a VGSL specification simply by providing a prefix and builder function.

  2. Custom Parser Registration for Model -> Spec

    • To convert a custom layer back into a VGSL specification, you can now register parser functions:

      from vgslify.model_parsers.tensorflow import register_custom_parser
      import tensorflow as tf
      
      class MyCustomLayer(tf.keras.layers.Layer):
          def __init__(self, units: int):
              super().__init__()
              self.units = units
      
      @register_custom_parser(MyCustomLayer)
      def parse_my_custom_layer(layer: MyCustomLayer):
          return f"MyCustomSpec({{layer.units}})"
    • These functions are then picked up automatically by the parser (TensorFlowModelParser or TorchModelParser) to handle custom layers.

Breaking Changes

  1. Module Renaming and Reorganization

    • vgslify.parsers is now vgslify.model_parsers.
    • tf_parser.py, torch_parser.py, and base_parser.py have been reorganized into tensorflow/, torch/, and base/ directories respectively.
    • vgslify.core.parser is now called vgslify.core.spec_parser.
  2. Simplified Imports

    • You can now import the main classes and utilities more directly:

      from vgslify import VGSLModelGenerator, model_to_spec
    • Parser imports have been simplified:

      from vgslify.tensorflow import TensorFlowModelParser
      from vgslify.torch import TorchModelParser
    • Layer factory imports have also been unified:

      from vgslify.tensorflow import TensorFlowLayerFactory, register_custom_layer

Example Usage

from vgslify import VGSLModelGenerator, model_to_spec
from vgslify.tensorflow import register_custom_layer
from vgslify.model_parsers.tensorflow import register_custom_parser

# Register a custom layer builder
@register_custom_layer("Xsw")
def my_custom_builder(factory, spec):
    # Implement custom layer creation here
    return tf.keras.layers.Dense(10)

# Register a custom parser for that layer
@register_custom_parser(MyCustomLayer)
def my_custom_parser(layer):
    # Return the spec string for this custom layer
    return f"Xsw({{layer.units}})"

# Example model creation and spec conversion
model = ...
vgsl_spec = model_to_spec(model)

Additional Changes

  • Updated the documentation with advanced examples.
  • Allow installation of the latest version of the desired backend with vgslify[torch] or vgslify[tensorflow].
  • Fixed a bug where the TensorFlow model parser could not handle pooling layers.