Skip to main content

A framework for defining, validating and visualizing neural network architectures.

Project description

https://circleci.com/gh/omni-us/narchi.svg?style=svg https://codecov.io/gh/omni-us/narchi/branch/master/graph/badge.svg https://sonarcloud.io/api/project_badges/measure?project=omni-us_narchi&metric=alert_status https://badge.fury.io/py/narchi.svg https://img.shields.io/badge/contributions-welcome-brightgreen.svg

narchi - A neural network architecture definition package

narchi is as python package that provides functionalities for defining neural network architectures in an implementation independent way. It is intended to make network architectures highly configurable while also making the task easier.

Main features

  • Network architectures are written in jsonnet format, which provides useful features like input parameters and functions to define repeated blocks.

  • The shapes of the tensors internal to the networks are automatically deduced by propagating the shapes of the inputs, thus requiring less effort and being less error prone.

  • Propagation of shapes is done using symbolic arithmetic which makes it simple to understand relationships between inputs and the derived shapes.

  • Architecture files can reference other architecture files, thus making this approach modular.

  • A command line tool is included to validate jsonnet architecture files and to create detailed diagrams of the respective network architectures.

  • Several examples intended to illustrate different features supported.

  • Includes basic implementations that allows to instantiate pytorch modules:

    • Instantiation only requires a jsonnet architecture file.

    • No need to write module classes or forward function for each new architecture.

    • One basic implementation that supports instatiating several of the examples.

    • A second example that supports packed 1d and 2d sequences which illustrates the implementation independent nature of the architecture files.

Teaser example

Here you can see an example that illustrates what narchi provides. The example is for resnet18 as implemented in torchvision, though bare in mind that the potential of narchi is the ease of configurability of network architectures, not the reimplementation of existing architectures.

Instantiating a pytorch module from the architecture file can be easily done as follows.

from narchi.instantiators.pytorch import StandardModule
module = StandardModule('resnet.jsonnet',
                        state_dict='resnet18-5c106cde.pth',
                        cfg={'ext_vars': {"num_blocks": [2, 2, 2, 2]}})

Creating a diagram of the architecture requires a single command like the following.

narchi_cli.py render \
  --ext_vars '{"num_blocks": [2, 2, 2, 2]}' \
  --nested_depth 4 \
  resnet.jsonnet \
  resnet18.pdf

Below you can see a small part of the rendered diagram of the start of the first downsample layer of resnet18.

imgs/resnet_crop.png

The part of the json that generated the previous crop of the architecture diagram can be seen below. Note that information of the shapes is not included, since these are derived automatically.

{
  "_class": "Sequential",
  "_id": "layer2",
  "blocks": [
    {
      "_class": "Group",
      "_name": "ResBlock",
      "blocks": [
        {
          "_class": "Identity",
          "_id": "ident"
        },
        {
          "_class": "Conv2d",
          "_id": "conv1",
          "bias": false,
          "dilation": 1,
          "kernel_size": 3,
          "output_size": 128,
          "padding": 1,
          "stride": 2
        },
        {
          "_class": "BatchNorm2d",
          "_id": "bn1"
        },
        {
          "_class": "Sequential",
          "_id": "downsample",
          "blocks": [
            {
              "_class": "Conv2d",
              "bias": false,
              "kernel_size": 1,
              "output_size": 128,
              "padding": 0,
              "stride": 2
            },
            {
              "_class": "BatchNorm2d"
            }
          ]
        },
        {"...": "..."}
      ],
      "graph": [
        "ident -> conv1 -> bn1 -> relu1 -> conv2 -> bn2 -> add -> relu2",
        "ident -> downsample -> add"
      ],
      "input": "ident",
      "output": "relu2"
    }
  ]
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

narchi-1.6.0-py3-none-any.whl (59.4 kB view details)

Uploaded Python 3

File details

Details for the file narchi-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: narchi-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 59.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for narchi-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d35b5a14d4a2bf0e4a3c20dd1211c0364fc78ce4414247cf46114ca295d9b42f
MD5 53cbe3a524aa4545959ca34848c58065
BLAKE2b-256 71d5f0c925ed1db0acefaea30ae00d272dabceaa41523dae327b6fa5027827e3

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