API Reference
narchi.blocks
Blocks definitions and functions related to registering propagators.
Classes:
|
Enum of blocks that preserve the input shape. |
|
Enum of blocks that concatenate multiple inputs. |
|
Enum of blocks that have fixed outputs. |
|
Enum of convolution-style blocks. |
|
Enum of recurrent-style blocks. |
|
Enum of blocks that transform the shape. |
|
Enum of blocks that group other blocks. |
Functions:
|
Adds a propagator to the dictionary of registered propagators. |
Function that registers all propagators defined in the modules of the package. |
- class narchi.blocks.SameShapeBlocksEnum(value)[source]
Bases:
enum.Enum
Enum of blocks that preserve the input shape.
Attributes:
Sigmoid
(from_blocks, block[, propagators, ...])Block that applies a sigmoid function.
LogSigmoid
(from_blocks, block[, ...])Block that applies a log-sigmoid function.
Softmax
(from_blocks, block[, propagators, ...])Block that applies a softmax function.
LogSoftmax
(from_blocks, block[, ...])Block that applies a log-softmax function.
Tanh
(from_blocks, block[, propagators, ...])Block that applies a hyperbolic tangent function.
ReLU
(from_blocks, block[, propagators, ...])Block that applies a rectified linear unit function.
LeakyReLU
(from_blocks, block[, propagators, ...])Block that applies a leaky rectified linear unit function.
Dropout
(from_blocks, block[, propagators, ...])Block that applies dropout, randomly set elements to zero.
BatchNorm2d
(from_blocks, block[, ...])Block that does 2D batch normalization.
Identity
(from_blocks, block[, propagators, ...])Block that does nothing, useful to connect one tensor to multiple blocks in a graph.
Add
(from_blocks, block[, propagators, ...])Block that adds the values of all input tensors.
CRF
(from_blocks, block[, propagators, ...])A layer that performs CRF decoding.
- Sigmoid(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapePropagator object>
Block that applies a sigmoid function.
- LogSigmoid(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapePropagator object>
Block that applies a log-sigmoid function.
- Softmax(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapePropagator object>
Block that applies a softmax function.
- LogSoftmax(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapePropagator object>
Block that applies a log-softmax function.
- Tanh(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapePropagator object>
Block that applies a hyperbolic tangent function.
- ReLU(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapePropagator object>
Block that applies a rectified linear unit function.
- LeakyReLU(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapePropagator object>
Block that applies a leaky rectified linear unit function.
- Dropout(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapePropagator object>
Block that applies dropout, randomly set elements to zero.
- BatchNorm2d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapePropagator object>
Block that does 2D batch normalization.
- Identity(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapePropagator object>
Block that does nothing, useful to connect one tensor to multiple blocks in a graph.
- Add(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapesPropagator object>
Block that adds the values of all input tensors. Input tensors must have the same shape.
- CRF(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.same.SameShapeConsumeDimPropagator object>
A layer that performs CRF decoding.
- class narchi.blocks.ConcatBlocksEnum(value)[source]
Bases:
enum.Enum
Enum of blocks that concatenate multiple inputs.
Attributes:
Concatenate
(from_blocks, block[, ...])Block that concatenates multiple inputs of the same shape along a given dimension.
- Concatenate(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.concat.ConcatenatePropagator object>
Block that concatenates multiple inputs of the same shape along a given dimension.
- class narchi.blocks.FixedOutputBlocksEnum(value)[source]
Bases:
enum.Enum
Enum of blocks that have fixed outputs.
Attributes:
Linear
(from_blocks, block[, propagators, ...])Linear transformation to the last dimension of input tensor.
Embedding
(from_blocks, block[, propagators, ...])A lookup table that retrieves embeddings of a fixed size.
AdaptiveAvgPool1d
(from_blocks, block[, ...])1D adaptive average pooling over input.
AdaptiveAvgPool2d
(from_blocks, block[, ...])2D adaptive average pooling over input.
- Linear(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.fixed.FixedOutputPropagator object>
Linear transformation to the last dimension of input tensor.
- Embedding(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.fixed.AddFixedPropagator object>
A lookup table that retrieves embeddings of a fixed size.
- AdaptiveAvgPool1d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.fixed.FixedOutputPropagator object>
1D adaptive average pooling over input.
- AdaptiveAvgPool2d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.fixed.FixedOutputPropagator object>
2D adaptive average pooling over input.
- class narchi.blocks.ConvBlocksEnum(value)[source]
Bases:
enum.Enum
Enum of convolution-style blocks.
Attributes:
Conv1d
(from_blocks, block[, propagators, ...])1D convolution.
Conv2d
(from_blocks, block[, propagators, ...])2D convolution.
Conv3d
(from_blocks, block[, propagators, ...])3D convolution.
MaxPool1d
(from_blocks, block[, propagators, ...])1D maximum pooling.
MaxPool2d
(from_blocks, block[, propagators, ...])2D maximum pooling.
MaxPool3d
(from_blocks, block[, propagators, ...])3D maximum pooling.
AvgPool1d
(from_blocks, block[, propagators, ...])1D average pooling.
AvgPool2d
(from_blocks, block[, propagators, ...])2D average pooling.
AvgPool3d
(from_blocks, block[, propagators, ...])3D average pooling.
- Conv1d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.conv.ConvPropagator object>
1D convolution.
- Conv2d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.conv.ConvPropagator object>
2D convolution.
- Conv3d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.conv.ConvPropagator object>
3D convolution.
- MaxPool1d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.conv.PoolPropagator object>
1D maximum pooling.
- MaxPool2d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.conv.PoolPropagator object>
2D maximum pooling.
- MaxPool3d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.conv.PoolPropagator object>
3D maximum pooling.
- AvgPool1d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.conv.PoolPropagator object>
1D average pooling.
- AvgPool2d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.conv.PoolPropagator object>
2D average pooling.
- AvgPool3d(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.conv.PoolPropagator object>
3D average pooling.
- class narchi.blocks.RnnBlocksEnum(value)[source]
Bases:
enum.Enum
Enum of recurrent-style blocks.
Attributes:
RNN
(from_blocks, block[, propagators, ...])A simple recurrent block.
LSTM
(from_blocks, block[, propagators, ...])An LSTM recurrent block.
GRU
(from_blocks, block[, propagators, ...])A GRU recurrent block.
- RNN(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.rnn.RnnPropagator object>
A simple recurrent block.
- LSTM(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.rnn.RnnPropagator object>
An LSTM recurrent block.
- GRU(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.rnn.RnnPropagator object>
A GRU recurrent block.
- class narchi.blocks.ReshapeBlocksEnum(value)[source]
Bases:
enum.Enum
Enum of blocks that transform the shape.
Attributes:
Reshape
(from_blocks, block[, propagators, ...])Transformation of the shape of the input.
- Reshape(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.reshape.ReshapePropagator object>
Transformation of the shape of the input.
- class narchi.blocks.GroupPropagatorsEnum(value)[source]
Bases:
enum.Enum
Enum of blocks that group other blocks.
Attributes:
Sequential
(from_blocks, block[, ...])Sequence of blocks that are connected in the given order.
Group
(from_blocks, block[, propagators, ...])Group of blocks with connected according to a given graph.
Module
(from_blocks, block[, propagators, ...])Definition of a complete module.
- Sequential(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.group.SequentialPropagator object>
Sequence of blocks that are connected in the given order.
- Group(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.propagators.group.GroupPropagator object>
Group of blocks with connected according to a given graph.
- Module(from_blocks: List[argparse.Namespace], block: argparse.Namespace, propagators: Optional[dict] = None, ext_vars: dict = {}, cwd: Optional[str] = None) = <narchi.module.ModulePropagator object>
Definition of a complete module.
narchi.graph
Functions related to the parsing of graphs.
Functions:
|
|
|
Parses a graph of a block. |
- narchi.graph.parse_graph(from_blocks, block)[source]
Parses a graph of a block.
- Parameters
- Return type
- Returns
Dictionary in topological order mapping node IDs to its respective input nodes IDs.
- Raises
ValueError – If there are problems parsing the graph.
ValueError – If the graph is not directed and acyclic.
ValueError – If topological sort does not include all nodes.
narchi.module
Classes related to neural network module architectures.
Classes:
|
Class for instantiating ModuleArchitecture objects. |
|
Propagator for complete modules. |
- class narchi.module.ModuleArchitecture(architecture=None, cfg=None, parser=None)[source]
Bases:
object
Class for instantiating ModuleArchitecture objects.
Attributes:
Methods:
Returns a ModuleArchitecture configuration parser.
__init__
([architecture, cfg, parser])Initializer for ModuleArchitecture class.
apply_config
(cfg)Applies a configuration to the ModuleArchitecture instance.
load_architecture
(architecture)Loads an architecture file.
validate
()Validates the architecture against the narchi or propagated schema.
Propagates the shapes of the neural network module architecture.
write_json
(json_path)Writes the current state of the architecture in json format to the given path.
Writes the current state of the architecture in to the configured output directory.
- path = None
- jsonnet = None
- architecture = None
- propagators = 'default'
- blocks = None
- topological_predecessors = None
- __init__(architecture=None, cfg=None, parser=None)[source]
Initializer for ModuleArchitecture class.
- class narchi.module.ModulePropagator(block_class)[source]
Bases:
narchi.propagators.base.BasePropagator
Propagator for complete modules.
Attributes:
Methods:
propagate
(from_blocks, block[, propagators, ...])Method that propagates shapes through a module.
connect_input
(from_blocks, block, module)Checks fixed dimensions agree and replaces the modules's variable dimensions.
- num_input_blocks = 1
- propagate(from_blocks, block, propagators=None, ext_vars={}, cwd=None)[source]
Method that propagates shapes through a module.
- Parameters
- Raises
ValueError – If no propagator found for some block.
narchi.render
Classes related to rendering of architectures.
Classes:
|
Class for instantiating a ModuleArchitectureRenderer objects useful for creating module architecture diagrams. |
- class narchi.render.ModuleArchitectureRenderer(architecture=None, cfg=None, parser=None)[source]
Bases:
narchi.module.ModuleArchitecture
Class for instantiating a ModuleArchitectureRenderer objects useful for creating module architecture diagrams.
Methods:
Returns a ModuleArchitectureRenderer configuration parser.
apply_config
(cfg)Applies a configuration to the ModuleArchitectureRenderer instance.
Creates a pygraphviz graph of the architecture using the current configuration.
render
([architecture, out_render, cfg])Renders the architecture diagram optionally writing to the given file path.
- create_graph()[source]
Creates a pygraphviz graph of the architecture using the current configuration.
narchi.schemas
Definition of the narchi json schemas.
Classes:
|
Enum of the schemas defined in narchi. |
Functions:
|
Formats a schema as a pretty printed json string. |
- class narchi.schemas.SchemasEnum(value)[source]
Bases:
enum.Enum
Enum of the schemas defined in narchi.
Attributes:
Main schema which defines the general format for architecture files.
Schema for architectures in which the dimensions have been propagated.
Schema that defines the format to specify reshaping of tensors.
Schema for a single architecture block.
Schema for mappings between architectures and block implementations.
- narchi = {'$id': 'https://schema.omnius.com/json/narchi/1.0/schema.json', '$ref': '#/definitions/architecture', '$schema': 'http://json-schema.org/draft-07/schema#', 'definitions': {'architecture': {'additionalProperties': False, 'properties': {'_description': {'$ref': '#/definitions/description'}, '_id': {'$ref': '#/definitions/id'}, 'blocks': {'$ref': '#/definitions/blocks'}, 'graph': {'$ref': '#/definitions/graph'}, 'inputs': {'$ref': '#/definitions/inputs_outputs'}, 'outputs': {'$ref': '#/definitions/inputs_outputs'}}, 'required': ['_id', 'blocks', 'graph', 'inputs', 'outputs'], 'type': 'object'}, 'block': {'allOf': [{'if': {'properties': {'_class': {'enum': ['Sequential', 'Group']}}}, 'then': {'required': ['blocks']}, 'else': {'not': {'required': ['blocks']}}}, {'if': {'properties': {'_class': {'const': 'Group'}}}, 'then': {'required': ['graph', 'input', 'output']}, 'else': {'not': {'required': ['graph', 'input', 'output']}}}, {'if': {'properties': {'_class': {'const': 'Module'}}}, 'then': {'required': ['_path']}, 'else': {'not': {'required': ['_path', '_ext_vars', 'architecture']}}}, {'if': {'properties': {'_class': {'const': 'Sequential'}}}, 'else': {'properties': {'blocks': {'items': {'required': ['_id']}}}}}, {'if': {'properties': {'_class': {'const': 'Concatenate'}}}, 'then': {'required': ['dim']}}, {'if': {'properties': {'_class': {'const': 'Reshape'}}}, 'then': {'required': ['reshape_spec']}, 'else': {'not': {'required': ['reshape_spec']}}}], 'properties': {'_class': {'$ref': '#/definitions/id'}, '_description': {'$ref': '#/definitions/description'}, '_ext_vars': {'type': 'object'}, '_id': {'$ref': '#/definitions/id'}, '_id_share': {'$ref': '#/definitions/id'}, '_name': {'$ref': '#/definitions/id'}, '_path': {'$ref': '#/definitions/path'}, '_shape': {'$ref': '#/definitions/shape'}, 'architecture': {'$ref': '#/definitions/architecture'}, 'blocks': {'$ref': '#/definitions/blocks'}, 'dim': {'type': 'integer'}, 'graph': {'$ref': '#/definitions/graph'}, 'input': {'$ref': '#/definitions/id'}, 'output': {'$ref': '#/definitions/id'}, 'reshape_spec': {'$ref': '#/definitions/reshape'}}, 'required': ['_class'], 'type': 'object'}, 'blocks': {'items': {'$ref': '#/definitions/block'}, 'minItems': 1, 'type': 'array'}, 'description': {'minLength': 8, 'pattern': '^[^<>]+$', 'type': 'string'}, 'dims': {'items': {'oneOf': [{'type': 'integer', 'minimum': 1}, {'type': 'string', 'pattern': '^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$'}]}, 'minItems': 1, 'type': 'array'}, 'dims_in': {'items': {'oneOf': [{'type': 'integer', 'minimum': 1}, {'type': 'string', 'pattern': '^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$'}, {'type': 'null'}]}, 'minItems': 1, 'type': 'array'}, 'graph': {'items': {'pattern': '^[A-Za-z_][0-9A-Za-z_]*( +-> +[A-Za-z_][0-9A-Za-z_]*)+$', 'type': 'string'}, 'minItems': 1, 'type': 'array'}, 'id': {'pattern': '^[A-Za-z_][0-9A-Za-z_]*$', 'type': 'string'}, 'inputs_outputs': {'items': {'additionalProperties': False, 'properties': {'_description': {'$ref': '#/definitions/description'}, '_id': {'$ref': '#/definitions/id'}, '_shape': {'$ref': '#/definitions/dims'}}, 'required': ['_id', '_shape'], 'type': 'object'}, 'minItems': 1, 'type': 'array'}, 'path': {'pattern': '.+\\.jsonnet', 'type': 'string'}, 'reshape': {'oneOf': [{'const': 'flatten'}, {'type': 'array', 'minItems': 1, 'items': {'oneOf': [{'$ref': '#/definitions/reshape_index'}, {'$ref': '#/definitions/reshape_flatten'}, {'$ref': '#/definitions/reshape_unflatten'}]}}]}, 'reshape_dims': {'items': {'oneOf': [{'type': 'integer', 'minimum': 1}, {'type': 'string', 'pattern': '^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$'}]}, 'minItems': 2, 'type': 'array'}, 'reshape_flatten': {'items': {'$ref': '#/definitions/reshape_index'}, 'minItems': 2, 'type': 'array'}, 'reshape_index': {'minimum': 0, 'type': 'integer'}, 'reshape_unflatten': {'additionalProperties': False, 'maxProperties': 1, 'minProperties': 1, 'patternProperties': {'^[0-9]+$': {'$ref': '#/definitions/reshape_dims'}}, 'type': 'object'}, 'shape': {'additionalProperties': False, 'properties': {'in': {'$ref': '#/definitions/dims_in'}, 'out': {'$ref': '#/definitions/dims'}}, 'required': ['in', 'out'], 'type': 'object'}}, 'title': 'Neural Network Module Architecture Schema'}
Main schema which defines the general format for architecture files.
- propagated = {'$ref': '#/definitions/architecture', '$schema': 'http://json-schema.org/draft-07/schema#', 'definitions': {'architecture': {'additionalProperties': False, 'properties': {'_description': {'$ref': '#/definitions/description'}, '_id': {'$ref': '#/definitions/id'}, '_shape': {'$ref': '#/definitions/shape'}, 'blocks': {'$ref': '#/definitions/blocks'}, 'graph': {'$ref': '#/definitions/graph'}, 'inputs': {'$ref': '#/definitions/inputs_outputs'}, 'outputs': {'$ref': '#/definitions/inputs_outputs'}}, 'required': ['_id', 'blocks', 'graph', 'inputs', 'outputs'], 'type': 'object'}, 'block': {'allOf': [{'if': {'properties': {'_class': {'enum': ['Sequential', 'Group']}}}, 'then': {'required': ['blocks']}, 'else': {'not': {'required': ['blocks']}}}, {'if': {'properties': {'_class': {'const': 'Group'}}}, 'then': {'required': ['graph', 'input', 'output']}, 'else': {'not': {'required': ['graph', 'input', 'output']}}}, {'if': {'properties': {'_class': {'const': 'Module'}}}, 'then': {'required': ['_path']}, 'else': {'not': {'required': ['_path', '_ext_vars', 'architecture']}}}, {'if': {'properties': {'_class': {'const': 'Sequential'}}}, 'else': {'properties': {'blocks': {'items': {'required': ['_id']}}}}}, {'if': {'properties': {'_class': {'const': 'Concatenate'}}}, 'then': {'required': ['dim']}}, {'if': {'properties': {'_class': {'const': 'Reshape'}}}, 'then': {'required': ['reshape_spec']}, 'else': {'not': {'required': ['reshape_spec']}}}], 'properties': {'_class': {'$ref': '#/definitions/id'}, '_description': {'$ref': '#/definitions/description'}, '_ext_vars': {'type': 'object'}, '_id': {'$ref': '#/definitions/id'}, '_id_share': {'$ref': '#/definitions/id'}, '_name': {'$ref': '#/definitions/id'}, '_path': {'$ref': '#/definitions/path'}, '_shape': {'$ref': '#/definitions/shape'}, 'architecture': {'$ref': '#/definitions/architecture'}, 'blocks': {'$ref': '#/definitions/blocks'}, 'dim': {'type': 'integer'}, 'graph': {'$ref': '#/definitions/graph'}, 'input': {'$ref': '#/definitions/id'}, 'output': {'$ref': '#/definitions/id'}, 'reshape_spec': {'$ref': '#/definitions/reshape'}}, 'required': ['_class', '_shape'], 'type': 'object'}, 'blocks': {'items': {'$ref': '#/definitions/block'}, 'minItems': 1, 'type': 'array'}, 'description': {'minLength': 8, 'pattern': '^[^<>]+$', 'type': 'string'}, 'dims': {'items': {'oneOf': [{'type': 'integer', 'minimum': 1}, {'type': 'string', 'pattern': '^<<variable:([-+/*0-9A-Za-z_]+)>>$'}]}, 'minItems': 1, 'type': 'array'}, 'dims_in': {'items': {'oneOf': [{'type': 'integer', 'minimum': 1}, {'type': 'string', 'pattern': '^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$'}, {'type': 'null'}]}, 'minItems': 1, 'type': 'array'}, 'graph': {'items': {'pattern': '^[A-Za-z_][0-9A-Za-z_·]*( +-> +[A-Za-z_][0-9A-Za-z_·]*)+$', 'type': 'string'}, 'minItems': 1, 'type': 'array'}, 'id': {'pattern': '^[A-Za-z_][0-9A-Za-z_·]*$', 'type': 'string'}, 'inputs_outputs': {'items': {'additionalProperties': False, 'properties': {'_description': {'$ref': '#/definitions/description'}, '_id': {'$ref': '#/definitions/id'}, '_shape': {'$ref': '#/definitions/dims'}}, 'required': ['_id', '_shape'], 'type': 'object'}, 'minItems': 1, 'type': 'array'}, 'path': {'pattern': '.+\\.jsonnet', 'type': 'string'}, 'reshape': {'oneOf': [{'const': 'flatten'}, {'type': 'array', 'minItems': 1, 'items': {'oneOf': [{'$ref': '#/definitions/reshape_index'}, {'$ref': '#/definitions/reshape_flatten'}, {'$ref': '#/definitions/reshape_unflatten'}]}}]}, 'reshape_dims': {'items': {'oneOf': [{'type': 'integer', 'minimum': 1}, {'type': 'string', 'pattern': '^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$'}]}, 'minItems': 2, 'type': 'array'}, 'reshape_flatten': {'items': {'$ref': '#/definitions/reshape_index'}, 'minItems': 2, 'type': 'array'}, 'reshape_index': {'minimum': 0, 'type': 'integer'}, 'reshape_unflatten': {'additionalProperties': False, 'maxProperties': 1, 'minProperties': 1, 'patternProperties': {'^[0-9]+$': {'$ref': '#/definitions/reshape_dims'}}, 'type': 'object'}, 'shape': {'additionalProperties': False, 'properties': {'in': {'$ref': '#/definitions/dims_in'}, 'out': {'$ref': '#/definitions/dims'}}, 'required': ['in', 'out'], 'type': 'object'}}, 'title': 'Neural Network Module Propagated Architecture Schema'}
Schema for architectures in which the dimensions have been propagated.
- reshape = {'$ref': '#/definitions/reshape', 'definitions': {'reshape': {'oneOf': [{'const': 'flatten'}, {'type': 'array', 'minItems': 1, 'items': {'oneOf': [{'$ref': '#/definitions/reshape_index'}, {'$ref': '#/definitions/reshape_flatten'}, {'$ref': '#/definitions/reshape_unflatten'}]}}]}, 'reshape_dims': {'items': {'oneOf': [{'type': 'integer', 'minimum': 1}, {'type': 'string', 'pattern': '^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$'}]}, 'minItems': 2, 'type': 'array'}, 'reshape_flatten': {'items': {'$ref': '#/definitions/reshape_index'}, 'minItems': 2, 'type': 'array'}, 'reshape_index': {'minimum': 0, 'type': 'integer'}, 'reshape_unflatten': {'additionalProperties': False, 'maxProperties': 1, 'minProperties': 1, 'patternProperties': {'^[0-9]+$': {'$ref': '#/definitions/reshape_dims'}}, 'type': 'object'}}}
Schema that defines the format to specify reshaping of tensors.
- block = {'$ref': '#/definitions/block', 'definitions': {'architecture': {'additionalProperties': False, 'properties': {'_description': {'$ref': '#/definitions/description'}, '_id': {'$ref': '#/definitions/id'}, 'blocks': {'$ref': '#/definitions/blocks'}, 'graph': {'$ref': '#/definitions/graph'}, 'inputs': {'$ref': '#/definitions/inputs_outputs'}, 'outputs': {'$ref': '#/definitions/inputs_outputs'}}, 'required': ['_id', 'blocks', 'graph', 'inputs', 'outputs'], 'type': 'object'}, 'block': {'allOf': [{'if': {'properties': {'_class': {'enum': ['Sequential', 'Group']}}}, 'then': {'required': ['blocks']}, 'else': {'not': {'required': ['blocks']}}}, {'if': {'properties': {'_class': {'const': 'Group'}}}, 'then': {'required': ['graph', 'input', 'output']}, 'else': {'not': {'required': ['graph', 'input', 'output']}}}, {'if': {'properties': {'_class': {'const': 'Module'}}}, 'then': {'required': ['_path']}, 'else': {'not': {'required': ['_path', '_ext_vars', 'architecture']}}}, {'if': {'properties': {'_class': {'const': 'Sequential'}}}, 'else': {'properties': {'blocks': {'items': {'required': ['_id']}}}}}, {'if': {'properties': {'_class': {'const': 'Concatenate'}}}, 'then': {'required': ['dim']}}, {'if': {'properties': {'_class': {'const': 'Reshape'}}}, 'then': {'required': ['reshape_spec']}, 'else': {'not': {'required': ['reshape_spec']}}}], 'properties': {'_class': {'$ref': '#/definitions/id'}, '_description': {'$ref': '#/definitions/description'}, '_ext_vars': {'type': 'object'}, '_id': {'$ref': '#/definitions/id'}, '_id_share': {'$ref': '#/definitions/id'}, '_name': {'$ref': '#/definitions/id'}, '_path': {'$ref': '#/definitions/path'}, '_shape': {'$ref': '#/definitions/shape'}, 'architecture': {'$ref': '#/definitions/architecture'}, 'blocks': {'$ref': '#/definitions/blocks'}, 'dim': {'type': 'integer'}, 'graph': {'$ref': '#/definitions/graph'}, 'input': {'$ref': '#/definitions/id'}, 'output': {'$ref': '#/definitions/id'}, 'reshape_spec': {'$ref': '#/definitions/reshape'}}, 'required': ['_class'], 'type': 'object'}, 'blocks': {'items': {'$ref': '#/definitions/block'}, 'minItems': 1, 'type': 'array'}, 'description': {'minLength': 8, 'pattern': '^[^<>]+$', 'type': 'string'}, 'dims': {'items': {'oneOf': [{'type': 'integer', 'minimum': 1}, {'type': 'string', 'pattern': '^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$'}]}, 'minItems': 1, 'type': 'array'}, 'dims_in': {'items': {'oneOf': [{'type': 'integer', 'minimum': 1}, {'type': 'string', 'pattern': '^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$'}, {'type': 'null'}]}, 'minItems': 1, 'type': 'array'}, 'graph': {'items': {'pattern': '^[A-Za-z_][0-9A-Za-z_·]*( +-> +[A-Za-z_][0-9A-Za-z_·]*)+$', 'type': 'string'}, 'minItems': 1, 'type': 'array'}, 'id': {'pattern': '^[A-Za-z_][0-9A-Za-z_·]*$', 'type': 'string'}, 'inputs_outputs': {'items': {'additionalProperties': False, 'properties': {'_description': {'$ref': '#/definitions/description'}, '_id': {'$ref': '#/definitions/id'}, '_shape': {'$ref': '#/definitions/dims'}}, 'required': ['_id', '_shape'], 'type': 'object'}, 'minItems': 1, 'type': 'array'}, 'path': {'pattern': '.+\\.jsonnet', 'type': 'string'}, 'reshape': {'oneOf': [{'const': 'flatten'}, {'type': 'array', 'minItems': 1, 'items': {'oneOf': [{'$ref': '#/definitions/reshape_index'}, {'$ref': '#/definitions/reshape_flatten'}, {'$ref': '#/definitions/reshape_unflatten'}]}}]}, 'reshape_dims': {'items': {'oneOf': [{'type': 'integer', 'minimum': 1}, {'type': 'string', 'pattern': '^(<<variable:([-+/*0-9A-Za-z_]+)>>|<<auto>>)$'}]}, 'minItems': 2, 'type': 'array'}, 'reshape_flatten': {'items': {'$ref': '#/definitions/reshape_index'}, 'minItems': 2, 'type': 'array'}, 'reshape_index': {'minimum': 0, 'type': 'integer'}, 'reshape_unflatten': {'additionalProperties': False, 'maxProperties': 1, 'minProperties': 1, 'patternProperties': {'^[0-9]+$': {'$ref': '#/definitions/reshape_dims'}}, 'type': 'object'}, 'shape': {'additionalProperties': False, 'properties': {'in': {'$ref': '#/definitions/dims_in'}, 'out': {'$ref': '#/definitions/dims'}}, 'required': ['in', 'out'], 'type': 'object'}}}
Schema for a single architecture block.
- mappings = {'additionalProperties': False, 'minProperties': 1, 'patternProperties': {'^[A-Za-z_][0-9A-Za-z_]*$': {'properties': {'additionalProperties': False, 'class': {'pattern': '^[A-Za-z_][0-9A-Za-z_.]*$', 'type': 'string'}, 'kwargs': {'additionalProperties': False, 'patternProperties': {'^:skip:$': {'pattern': '^[A-Za-z_][0-9A-Za-z_]*$', 'type': 'string'}, '^[A-Za-z_][0-9A-Za-z_]*$': {'oneOf': [{'pattern': '^[A-Za-z_][0-9A-Za-z_]*$'}, {'pattern': '^shape:in:(|-)[0-9]+$'}, {'pattern': '^const:str:[^:]+$'}, {'pattern': '^const:int:[0-9]+$'}, {'pattern': '^const:bool:(True|False)$'}], 'type': 'string'}}, 'type': 'object'}, 'required': ['class']}, 'type': 'object'}}, 'type': 'object'}
Schema for mappings between architectures and block implementations.
narchi.sympy
Functions for symbolic operations.
Functions:
|
Checks whether value is an int > 0 or str that follows variable_regex.pattern. |
|
Returns the sympyfied object for the given value. |
|
Returns either an int or a string variable. |
|
Performs a symbolic operation on a given value. |
|
Performs a symbolic aggregation operation over all input values. |
|
Performs a symbolic sum of all input values. |
|
Performs a symbolic product of all input values. |
|
Performs a symbolic division. |
|
Performs a symbolic calculation of the output length of a convolution. |
- narchi.sympy.is_valid_dim(value)[source]
Checks whether value is an int > 0 or str that follows variable_regex.pattern.
- narchi.sympy.variable_operate(value, operation)[source]
Performs a symbolic operation on a given value.
- Parameters
- Return type
- Returns
The result of the operation.
- Raises
If operation is not int nor a valid expression. * If value is not an int or a string that follows variable_regex.pattern. * If value is not a valid expression or contains “__input__” as a free symbol.
- narchi.sympy.variables_aggregate(values, operation)[source]
Performs a symbolic aggregation operation over all input values.
- narchi.sympy.conv_out_length(length, kernel, stride, padding, dilation)[source]
Performs a symbolic calculation of the output length of a convolution.
- Parameters
length (
Union
[str
,int
]) – Length of the input, either an int or a variable.kernel (
int
) – Size of the kernel in the direction of length.stride (
int
) – Stride size in the direction of the length.padding (
int
) – Padding added at both sides in the direction of the length.dilation (
int
) – Dilation size in the direction of the length.
- Return type
- Returns
The result of the operation.
narchi.propagators.base
Base propagator class and related functions.
Functions:
|
Gets the shape list for a given key among {'in','out'}. |
|
Creates a shape namespace with 'in' and 'out' attributes and copied shape arrays. |
|
Sets a value for a given dimension, shape and key ('in' or 'out'). |
|
Checks whether the output shape from a block agrees with input shape of another block. |
|
Checks whether a shape has any <<auto>> values. |
|
Checks the output_feats attribute of a block. |
Classes:
|
Base class for block shapes propagation. |
- narchi.propagators.base.get_shape(key, shape)[source]
Gets the shape list for a given key among {‘in’,’out’}.
- narchi.propagators.base.create_shape(shape_in, shape_out=None)[source]
Creates a shape namespace with ‘in’ and ‘out’ attributes and copied shape arrays.
- narchi.propagators.base.set_shape_dim(key, shape, dim, val)[source]
Sets a value for a given dimension, shape and key (‘in’ or ‘out’).
- narchi.propagators.base.shapes_agree(shape_from, shape_to)[source]
Checks whether the output shape from a block agrees with input shape of another block.
- narchi.propagators.base.shape_has_auto(shape)[source]
Checks whether a shape has any <<auto>> values.
- narchi.propagators.base.check_output_feats_dims(output_feats_dims, block_class, block)[source]
Checks the output_feats attribute of a block.
- class narchi.propagators.base.BasePropagator(block_class)[source]
Bases:
object
Base class for block shapes propagation.
Attributes:
Methods:
__init__
(block_class)Initializer for BasePropagator instance.
initial_checks
(from_blocks, block)Method that does some initial checks before propagation.
propagate
(from_blocks, block)Method that propagates shapes to a block.
final_checks
(from_blocks, block)Method that checks for problems after shapes have been propagated.
__call__
(from_blocks, block[, propagators, ...])Propagates shapes to the given block.
- num_input_blocks = None
- output_feats_dims = False
- __init__(block_class)[source]
Initializer for BasePropagator instance.
- Parameters
block_class (str) – The name of the block class being propagated.
- block_class = None
- initial_checks(from_blocks, block)[source]
Method that does some initial checks before propagation.
Extensions of this method in derived classes should always call this base method. This base method implements the following checks:
That the block class is the same as the one expected by the propagator.
That the input shapes don’t contain any <<auto>> values.
If num_input_blocks is set and is an int, that there are exactly this number of input blocks.
- Parameters
- Raises
ValueError – If block fails to validate against schema.
ValueError – If block already has a _shape attribute.
ValueError – If block._class != block_class.
ValueError – If input shape not present, invalid or contains <<auto>>.
ValueError – If output_feats required by class and not present or invalid.
ValueError – If len(from_blocks) != num_input_blocks.
- propagate(from_blocks, block)[source]
Method that propagates shapes to a block.
This base method should be implemented by all derived classes.
- Parameters
- Raises
NotImplementedError – Always.
- final_checks(from_blocks, block)[source]
Method that checks for problems after shapes have been propagated.
This base method implements checking the output shape don’t contain <<auto>> values and if there is only a single from_block, that the connecting shapes agree. Extensions of this method in derived classes should always call this base one.
- __call__(from_blocks, block, propagators=None, ext_vars={}, cwd=None)[source]
Propagates shapes to the given block.
narchi.propagators.concat
Propagator classes for concatenating.
Classes:
|
Propagator for concatenating along a given dimension. |
- class narchi.propagators.concat.ConcatenatePropagator(block_class)[source]
Bases:
narchi.propagators.base.BasePropagator
Propagator for concatenating along a given dimension.
Attributes:
Methods:
initial_checks
(from_blocks, block)Method that does some initial checks before propagation.
propagate
(from_blocks, block)Method that propagates shapes to a block.
- num_input_blocks = '>1'
- initial_checks(from_blocks, block)[source]
Method that does some initial checks before propagation.
Calls the base class checks and makes sure that the dim attribute is valid and agrees with the input dimensions.
- Parameters
- Raises
ValueError – When block does not have a valid dim attribute that agrees with input dimensions.
narchi.propagators.conv
Propagator classes for convolution blocks.
Classes:
|
Propagator for convolution style blocks. |
|
Propagator for pooling style blocks. |
- class narchi.propagators.conv.ConvPropagator(block_class, conv_dims)[source]
Bases:
narchi.propagators.base.BasePropagator
Propagator for convolution style blocks.
Attributes:
Methods:
__init__
(block_class, conv_dims)Initializer for ConvPropagator instance.
initial_checks
(from_blocks, block)Method that does some initial checks before propagation.
propagate
(from_blocks, block)Method that propagates shapes to a block.
- num_input_blocks = 1
- num_features_source = 'output_feats'
- __init__(block_class, conv_dims)[source]
Initializer for ConvPropagator instance.
- Parameters
- Raises
ValueError – If conv_dims not int > 0.
- conv_dims = None
- initial_checks(from_blocks, block)[source]
Method that does some initial checks before propagation.
Calls the base class checks and makes sure that the input shape agrees with the convolution dimensions.
- Parameters
- Raises
ValueError – When conv_dims does not agree with from_block[0]._shape.
- propagate(from_blocks, block)[source]
Method that propagates shapes to a block.
- Parameters
- Raises
ValueError – When block.output_feats not valid.
NotImplementedError – If num_features_source is not one of {“from_shape”, “output_feats”}.
- class narchi.propagators.conv.PoolPropagator(block_class, conv_dims)[source]
Bases:
narchi.propagators.conv.ConvPropagator
Propagator for pooling style blocks.
Attributes:
- num_features_source = 'from_shape'
narchi.propagators.fixed
Propagator classes for fixed output blocks.
Classes:
|
Propagator for blocks that adds fixed dimensions. |
|
Propagator for fixed output size blocks. |
- class narchi.propagators.fixed.AddFixedPropagator(block_class, fixed_dims=1)[source]
Bases:
narchi.propagators.base.BasePropagator
Propagator for blocks that adds fixed dimensions.
Methods:
__init__
(block_class[, fixed_dims])Initializer for AddFixedPropagator instance.
propagate
(from_blocks, block)Method that propagates shapes to a block.
Attributes:
- __init__(block_class, fixed_dims=1)[source]
Initializer for AddFixedPropagator instance.
- Parameters
- Raises
ValueError – If fixed_dims not int > 0.
- fixed_dims = 1
- class narchi.propagators.fixed.FixedOutputPropagator(block_class, unfixed_dims='any', fixed_dims=1)[source]
Bases:
narchi.propagators.base.BasePropagator
Propagator for fixed output size blocks.
Attributes:
Methods:
__init__
(block_class[, unfixed_dims, fixed_dims])Initializer for FixedOutputPropagator instance.
initial_checks
(from_blocks, block)Method that does some initial checks before propagation.
propagate
(from_blocks, block)Method that propagates shapes to a block.
- num_input_blocks = 1
- __init__(block_class, unfixed_dims='any', fixed_dims=1)[source]
Initializer for FixedOutputPropagator instance.
- Parameters
- Raises
ValueError – If fixed_dims not int > 0.
ValueError – If unfixed_dims not “any” or int > 0.
- unfixed_dims = 'any'
- output_feats_dims = 1
- initial_checks(from_blocks, block)[source]
Method that does some initial checks before propagation.
Calls the base class checks and makes sure that the input shape has at least (fixed_dims+1) dimensions if unfixed_dims==”any” or exactly (fixed_dims+fixed_dims) dimensions if unfixed_dims is int.
- Parameters
- Raises
ValueError – When fixed_dims and unfixed_dims do not agree with from_block[0]._shape.
narchi.propagators.group
Propagator classes for groups of blocks.
Functions:
|
Function that creates a dictionary of blocks using _id as keys. |
|
Adds to block id a prefix consisting of parent id and separator as defined in propagated schema. |
|
Function that propagates shapes in blocks based on a connections mapping. |
Classes:
|
Propagator for a sequence of blocks. |
|
Propagator for a sequence of blocks. |
- narchi.propagators.group.get_blocks_dict(blocks)[source]
Function that creates a dictionary of blocks using _id as keys.
- narchi.propagators.group.add_ids_prefix(block, io_blocks, skip_io=True)[source]
Adds to block id a prefix consisting of parent id and separator as defined in propagated schema.
- narchi.propagators.group.propagate_shapes(blocks_dict, topological_predecessors, propagators, ext_vars, cwd, skip_ids=None)[source]
Function that propagates shapes in blocks based on a connections mapping.
- Parameters
topological_predecessors (
Dict
[str
,List
[str
]]) – Mapping of block IDs to its input blocks IDs.propagators (
dict
) – Dictionary of propagators.ext_vars (
dict
) – Dictionary of external variables required to load jsonnet.cwd (
str
) – Working directory to resolve relative paths.skip_ids (
Optional
[set
]) – Blocks that should be skipped in propagation.
- Raises
ValueError – If there graph references an undefined block.
ValueError – If no propagator found for some block.
- class narchi.propagators.group.SequentialPropagator(block_class)[source]
Bases:
narchi.propagators.base.BasePropagator
Propagator for a sequence of blocks.
Attributes:
Methods:
propagate
(from_blocks, block, propagators, ...)Method that propagates shapes in the given block.
- num_input_blocks = 1
- propagate(from_blocks, block, propagators, ext_vars, cwd=None)[source]
Method that propagates shapes in the given block.
- Parameters
- Raises
ValueError – If there are multiple blocks with the same id.
ValueError – If no propagator found for some block.
- class narchi.propagators.group.GroupPropagator(block_class)[source]
Bases:
narchi.propagators.group.SequentialPropagator
Propagator for a sequence of blocks.
Methods:
propagate
(from_blocks, block, propagators, ...)Method that propagates shapes in the given block.
- propagate(from_blocks, block, propagators, ext_vars, cwd=None)[source]
Method that propagates shapes in the given block.
- Parameters
- Raises
ValueError – If there are multiple blocks with the same id.
ValueError – If there graph references an undefined block.
ValueError – If no propagator found for some block.
narchi.propagators.reshape
Propagator classes for reshaping.
Functions:
|
Checks that reshape_spec is valid according to schema, indexes range is valid and there is at most one <<auto>> in each unflatten. |
|
Converts elements of a reshape_spec from Namespace to dict. |
Classes:
|
Propagator for reshapping which could involve any of: permute, flatten and unflatten. |
- narchi.propagators.reshape.check_reshape_spec(reshape_spec)[source]
Checks that reshape_spec is valid according to schema, indexes range is valid and there is at most one <<auto>> in each unflatten.
- narchi.propagators.reshape.norm_reshape_spec(reshape_spec)[source]
Converts elements of a reshape_spec from Namespace to dict.
- class narchi.propagators.reshape.ReshapePropagator(block_class)[source]
Bases:
narchi.propagators.base.BasePropagator
Propagator for reshapping which could involve any of: permute, flatten and unflatten.
Attributes:
Methods:
initial_checks
(from_blocks, block)Method that does some initial checks before propagation.
propagate
(from_blocks, block)Method that propagates shapes to a block.
- num_input_blocks = 1
- initial_checks(from_blocks, block)[source]
Method that does some initial checks before propagation.
Calls the base class checks and makes sure that the reshape_spec attribute is valid and agrees with the input dimensions.
- Parameters
- Raises
ValueError – When block does not have a valid reshape_spec attribute that agrees with input dimensions.
narchi.propagators.rnn
Propagator classes for recurrent blocks.
Classes:
|
Propagator for recurrent style blocks. |
- class narchi.propagators.rnn.RnnPropagator(block_class)[source]
Bases:
narchi.propagators.base.BasePropagator
Propagator for recurrent style blocks.
Attributes:
Methods:
initial_checks
(from_blocks, block)Method that does some initial checks before propagation.
propagate
(from_blocks, block)Method that propagates shapes to a block.
- num_input_blocks = 1
- output_feats_dims = 1
- initial_checks(from_blocks, block)[source]
Method that does some initial checks before propagation.
Calls the base class checks and makes sure that the input shape has two dimensions and that block includes a valid output_feats attribute.
- Parameters
- Raises
ValueError – When block.output_feats not valid.
ValueError – When len(from_block[0]._shape) != 2.
narchi.propagators.same
Propagator classes that preserve the same shape.
Classes:
|
Propagator for blocks in which the input and output shapes are the same. |
|
Propagator for blocks that receive multiple inputs of the same shape and preserves this shape. |
|
Propagator for blocks in which the output shape is the same as input except the last which is consumed. |
- class narchi.propagators.same.SameShapePropagator(block_class)[source]
Bases:
narchi.propagators.base.BasePropagator
Propagator for blocks in which the input and output shapes are the same.
Methods:
initial_checks
(from_blocks, block)Method that does some initial checks before propagation.
propagate
(from_blocks, block)Method that propagates shapes to a block.
- initial_checks(from_blocks, block)[source]
Method that does some initial checks before propagation.
Calls the base class checks and if multi-input makes sure that all inputs have the same shape and if not multi-input makes sure that there is only a single input block.
- Parameters
- Raises
ValueError – When multi_input==False and len(from_blocks) != 1.
- class narchi.propagators.same.SameShapesPropagator(block_class)[source]
Bases:
narchi.propagators.same.SameShapePropagator
Propagator for blocks that receive multiple inputs of the same shape and preserves this shape.
Attributes:
- num_input_blocks = '>1'
- class narchi.propagators.same.SameShapeConsumeDimPropagator(block_class)[source]
Bases:
narchi.propagators.same.SameShapePropagator
Propagator for blocks in which the output shape is the same as input except the last which is consumed.
Methods:
initial_checks
(from_blocks, block)Method that does some initial checks before propagation.
propagate
(from_blocks, block)Method that propagates shapes to a block.
- initial_checks(from_blocks, block)[source]
Method that does some initial checks before propagation.
Calls the base class checks and makes sure that the input has more than one dimension.
- Parameters
- Raises
ValueError – When len(input_shape) < 2.
narchi.instantiators.common
Generic code for module architecture instantiators.
Functions:
|
Removes the parent prefix from an id value. |
|
Function that returns a class in a module given its dot import statement. |
|
Function that instantiates a block given its narchi config and a mappings object. |
- narchi.instantiators.common.id_strip_parent_prefix(value)[source]
Removes the parent prefix from an id value.