Spaces:
Running
Running
Redo PyTorch boxes as a separate environment.
Browse files- server/ops.py +5 -0
- server/pytorch_model_ops.py +34 -71
- web/src/NodeWithArea.svelte +0 -4
server/ops.py
CHANGED
|
@@ -181,3 +181,8 @@ def op_registration(env: str):
|
|
| 181 |
|
| 182 |
def passive_op_registration(env: str):
|
| 183 |
return functools.partial(register_passive_op, env)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
def passive_op_registration(env: str):
|
| 183 |
return functools.partial(register_passive_op, env)
|
| 184 |
+
|
| 185 |
+
def register_area(env, name, params=[]):
|
| 186 |
+
'''A node that represents an area. It can contain other nodes, but does not restrict movement in any way.'''
|
| 187 |
+
op = Op(func=no_op, name=name, params={p.name: p for p in params}, inputs={}, outputs={}, type='area')
|
| 188 |
+
CATALOGS[env][name] = op
|
server/pytorch_model_ops.py
CHANGED
|
@@ -1,72 +1,35 @@
|
|
| 1 |
-
'''Boxes for defining
|
| 2 |
-
from enum import Enum
|
| 3 |
-
import inspect
|
| 4 |
from . import ops
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
params
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
return 'LayerNorm'
|
| 39 |
-
|
| 40 |
-
@register_layer('Dropout')
|
| 41 |
-
def dropout(x, *, p=0.5):
|
| 42 |
-
return f'Dropout ({p})'
|
| 43 |
-
|
| 44 |
-
@register_layer('Linear')
|
| 45 |
-
def linear(*, output_dim: int):
|
| 46 |
-
return f'Linear {output_dim}'
|
| 47 |
-
|
| 48 |
-
class GraphConv(Enum):
|
| 49 |
-
GCNConv = 'GCNConv'
|
| 50 |
-
GATConv = 'GATConv'
|
| 51 |
-
GATv2Conv = 'GATv2Conv'
|
| 52 |
-
SAGEConv = 'SAGEConv'
|
| 53 |
-
|
| 54 |
-
@register_layer('Graph Convolution')
|
| 55 |
-
def graph_convolution(x, edges, *, type: GraphConv):
|
| 56 |
-
return 'GraphConv'
|
| 57 |
-
|
| 58 |
-
class Nonlinearity(Enum):
|
| 59 |
-
Mish = 'Mish'
|
| 60 |
-
ReLU = 'ReLU'
|
| 61 |
-
Tanh = 'Tanh'
|
| 62 |
-
|
| 63 |
-
@register_layer('Nonlinearity')
|
| 64 |
-
def nonlinearity(x, *, type: Nonlinearity):
|
| 65 |
-
return 'ReLU'
|
| 66 |
-
|
| 67 |
-
def register_area(name, params=[]):
|
| 68 |
-
'''A node that represents an area. It can contain other nodes, but does not restrict movement in any way.'''
|
| 69 |
-
op = ops.Op(func=ops.no_op, name=name, params={p.name: p for p in params}, inputs={}, outputs={}, type='area')
|
| 70 |
-
LAYERS[name] = op
|
| 71 |
-
|
| 72 |
-
register_area('Repeat', params=[ops.Parameter.basic('times', 1, int)])
|
|
|
|
| 1 |
+
'''Boxes for defining PyTorch models.'''
|
|
|
|
|
|
|
| 2 |
from . import ops
|
| 3 |
+
from .ops import Parameter as P
|
| 4 |
+
|
| 5 |
+
ENV = 'PyTorch model'
|
| 6 |
+
def reg(name, inputs=[], outputs=None, params=[]):
|
| 7 |
+
if outputs is None:
|
| 8 |
+
outputs = inputs
|
| 9 |
+
return ops.register_passive_op(
|
| 10 |
+
ENV, name,
|
| 11 |
+
inputs=[ops.Input(name=name, position='bottom', type='tensor') for name in inputs],
|
| 12 |
+
outputs=[ops.Output(name=name, position='top', type='tensor') for name in outputs],
|
| 13 |
+
params=params)
|
| 14 |
+
reg('Input: features', outputs=['x'])
|
| 15 |
+
reg('Input: graph edges', outputs=['edges'])
|
| 16 |
+
reg('Input: label', outputs=['y'])
|
| 17 |
+
reg('Input: positive sample', outputs=['x_pos'])
|
| 18 |
+
reg('Input: negative sample', outputs=['x_neg'])
|
| 19 |
+
|
| 20 |
+
reg('Attention', inputs=['q', 'k', 'v'], outputs=['x'])
|
| 21 |
+
reg('LayerNorm', inputs=['x'])
|
| 22 |
+
reg('Dropout', inputs=['x'], params=[P.basic('p', 0.5)])
|
| 23 |
+
reg('Linear', inputs=['x'], params=[P.basic('output_dim', 'same')])
|
| 24 |
+
reg('Graph conv', inputs=['x', 'edges'], outputs=['x'],
|
| 25 |
+
params=[P.options('type', ['GCNConv', 'GATConv', 'GATv2Conv', 'SAGEConv'])])
|
| 26 |
+
reg('Activation', inputs=['x'],
|
| 27 |
+
params=[P.options('type', ['ReLU', 'LeakyReLU', 'Tanh', 'Mish'])])
|
| 28 |
+
reg('Supervised loss', inputs=['x', 'y'], outputs=['loss'])
|
| 29 |
+
reg('Triplet loss', inputs=['x', 'x_pos', 'x_neg'], outputs=['loss'])
|
| 30 |
+
reg('Optimizer', inputs=['loss'], outputs=[],
|
| 31 |
+
params=[
|
| 32 |
+
P.options('type', ['AdamW', 'Adafactor', 'Adagrad', 'SGD', 'Lion', 'Paged AdamW', 'Galore AdamW']),
|
| 33 |
+
P.basic('lr', 0.001)])
|
| 34 |
+
|
| 35 |
+
ops.register_area(ENV, 'Repeat', params=[ops.Parameter.basic('times', 1, int)])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/NodeWithArea.svelte
CHANGED
|
@@ -45,10 +45,6 @@
|
|
| 45 |
.area {
|
| 46 |
border-radius: 10px;
|
| 47 |
border: 3px dashed oklch(75% 0.2 55);
|
| 48 |
-
min-width: 400px;
|
| 49 |
-
min-height: 400px;
|
| 50 |
-
max-width: 800px;
|
| 51 |
-
max-height: 800px;
|
| 52 |
z-index: 0 !important;
|
| 53 |
}
|
| 54 |
.title {
|
|
|
|
| 45 |
.area {
|
| 46 |
border-radius: 10px;
|
| 47 |
border: 3px dashed oklch(75% 0.2 55);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
z-index: 0 !important;
|
| 49 |
}
|
| 50 |
.title {
|