|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
5 | | -from typing import Dict, List, Tuple |
| 5 | +from Deeploy.DeeployTypes import NodeTemplate |
6 | 6 |
|
7 | | -from Deeploy.DeeployTypes import NetworkContext, NodeTemplate, OperatorRepresentation |
8 | | - |
9 | | - |
10 | | -class _ConvTranspose1D_Template(NodeTemplate): |
11 | | - |
12 | | - def __init__(self, templateStr): |
13 | | - super().__init__(templateStr) |
14 | | - |
15 | | - def alignToContext(self, ctxt: NetworkContext, |
16 | | - operatorRepresentation: OperatorRepresentation) -> Tuple[NetworkContext, Dict, List[str]]: |
17 | | - |
18 | | - # input/output tensors |
19 | | - # input/output tensors |
20 | | - data_in = ctxt.lookup(operatorRepresentation["data_in"]) |
21 | | - data_out = ctxt.lookup(operatorRepresentation["data_out"]) |
22 | | - |
23 | | - #quantized tensor offset computation |
24 | | - operatorRepresentation["input_offset"] = 0 |
25 | | - if hasattr(data_in, "_signed") and hasattr(data_in, "nLevels"): |
26 | | - operatorRepresentation["input_offset"] = (data_in._signed == 0) * int(data_in.nLevels // 2) |
27 | | - |
28 | | - operatorRepresentation["output_offset"] = 0 |
29 | | - if hasattr(data_out, "_signed") and hasattr(data_out, "nLevels"): |
30 | | - operatorRepresentation["output_offset"] = -(data_out._signed == 0) * int(data_out.nLevels // 2) |
31 | | - |
32 | | - # Batch size |
33 | | - operatorRepresentation["batch"] = data_in.shape[0] |
34 | | - |
35 | | - # input/output shape (format NCW) |
36 | | - operatorRepresentation["ch_im_in"] = data_in.shape[1] |
37 | | - operatorRepresentation["dim_im_in_y"] = data_in.shape[2] |
38 | | - |
39 | | - operatorRepresentation["ch_im_out"] = data_out.shape[1] |
40 | | - operatorRepresentation["dim_im_out_y"] = data_out.shape[2] |
41 | | - |
42 | | - # weights and kernel |
43 | | - weight = ctxt.lookup(operatorRepresentation["weight"]) |
44 | | - operatorRepresentation["dim_kernel_y"] = weight.shape[2] # Shape: [C_out, C_in, K] |
45 | | - |
46 | | - # Stride |
47 | | - operatorRepresentation["stride_y"] = operatorRepresentation.get("stride_y", 1) |
48 | | - |
49 | | - # Bias (optional) |
50 | | - operatorRepresentation["has_bias"] = "true" if "bias" in operatorRepresentation else "false" |
51 | | - operatorRepresentation["bias"] = operatorRepresentation.get("bias", "NULL") |
52 | | - |
53 | | - operatorRepresentation[ |
54 | | - "batchOffsetIn"] = operatorRepresentation["ch_im_in"] * operatorRepresentation["dim_im_in_y"] |
55 | | - operatorRepresentation[ |
56 | | - "batchOffsetOut"] = operatorRepresentation["ch_im_out"] * operatorRepresentation["dim_im_out_y"] |
57 | | - |
58 | | - return ctxt, operatorRepresentation, [] |
59 | | - |
60 | | - |
61 | | -referenceTemplate = _ConvTranspose1D_Template(""" |
| 7 | +referenceTemplate = NodeTemplate(""" |
62 | 8 | <% |
63 | 9 | batchOffsetIn = ch_im_in * dim_im_in_y |
64 | 10 | batchOffsetOut = ch_im_out * dim_im_out_y |
|
0 commit comments