Skip to content

Instantly share code, notes, and snippets.

type Storage {
}
def @main(%data: Tensor[(1, 3, 224, 224), float32]) -> Tensor[(1, 1000), float32] {
%0 = add(602112 /* ty=int64 */, 64 /* ty=int64 */) /* ty=int64 */;
%1 = subtract(%0, 1 /* ty=int64 */) /* ty=int64 */;
%2 = divide(%1, 64 /* ty=int64 */) /* ty=int64 */;
%3 = multiply(%2, 64 /* ty=int64 */) /* ty=int64 */;
%4 = add(0 /* ty=int64 */, %3) /* ty=int64 */;
@zhiics
zhiics / shapefunc_fail.py
Created December 9, 2019 19:32
An example that ShapeFunc fails
import tvm
from tvm import relay
import numpy as np
x = relay.var("x", shape=(1, 1), dtype="int32")
x1 = relay.var("x1", shape=(1, 1), dtype="int32")
p0 = relay.var("p0", shape=(1, 1), dtype="int32")
p1 = relay.var("p1", shape=(1, 1), dtype="int32")
import tensorflow as tf
import numpy as np
from tvm import relay
from tvm.relay.frontend.tensorflow import from_tensorflow
def check_equal(graph, tf_out):
mod, params = from_tensorflow(graph.as_graph_def(add_shapes=True))
print("---------------")
print(mod["main"])
Before optimization
-------------------
v0.0.3
fn (%data: Tensor[(1, 3, 224, 224), float32], %mobilenet0_conv0_weight: Tensor[(32, 3, 3, 3), float32], %mobilenet0_batchnorm0_gamma: Tensor[(32,), float32], %mobilenet0_batchnorm0_beta: Tensor[(32,), float32], %mobilenet0_batchnorm0_running_mean: Tensor[(32,), float32], %mobilenet0_batchnorm0_running_var: Tensor[(32,), float32], %mobilenet0_conv1_weight: Tensor[(32, 1, 3, 3), float32], %mobilenet0_batchnorm1_gamma: Tensor[(32,), float32], %mobilenet0_batchnorm1_beta: Tensor[(32,), float32], %mobilenet0_batchnorm1_running_mean: Tensor[(32,), float32], %mobilenet0_batchnorm1_running_var: Tensor[(32,), float32], %mobilenet0_conv2_weight: Tensor[(64, 32, 1, 1), float32], %mobilenet0_batchnorm2_gamma: Tensor[(64,), float32], %mobilenet0_batchnorm2_beta: Tensor[(64,), float32], %mobilenet0_batchnorm2_running_mean: Tensor[(64,), float32], %mobilenet0_batchnorm2_running_var: Tensor[(64,), float32], %mobilenet0_conv3_weight: Tensor[(64, 1, 3, 3), float32], %mobilenet0_ba
@zhiics
zhiics / dis.md
Last active March 25, 2019 05:48
Jared and Zhi discussion

We think having a dicussion/RFC for registered based VM is necessary if it brings great value.

We first talked about how register allocation can be done in VM

  1. we can collect the liveness first using ANF where scoping information could used as basic block so that traditional kill-gen analysis could be used.

  2. Linear scan RA should be helpful here. Graph coloring needs more consideration about spilling. Also an object may in a register for a long while. Linear scan should satfisy our case as the liveness of each variable/object should be genearlly short. Linear scan is much easier to implement as well

Graph(%input_tensor,
%resnet_model/conv2d/kernel,
%resnet_model/batch_normalization/gamma,
%resnet_model/batch_normalization/beta,
%resnet_model/batch_normalization/moving_mean,
%resnet_model/batch_normalization/moving_variance,
%resnet_model/conv2d_2/kernel,
%resnet_model/batch_normalization_2/gamma,
%resnet_model/batch_normalization_2/beta,
%resnet_model/batch_normalization_2/moving_mean,