Skip to content
Snippets Groups Projects
Commit e75df48c authored by auphelia's avatar auphelia
Browse files

[Test] Added test for verification analysis pass

parent 355b4433
No related branches found
No related tags found
No related merge requests found
from onnx import helper
from onnx import TensorProto, helper
from finn.custom_op.verify_custom_op_construct import CustomOp_Construct
from finn.analysis.verify_custom_nodes import verify_nodes
from finn.core.modelwrapper import ModelWrapper
def test_verify_layout_custom_ops():
def check_two_dict_for_equality(dict1, dict2):
for key in dict1:
assert key in dict2, "Key: {} is not in both dictionaries".format(key)
assert (
dict1[key] == dict2[key]
), """Values for key {} are not the same
in both dictionaries""".format(
key
)
return True
def test_verify_custom_nodes():
inp = helper.make_tensor_value_info("inp", TensorProto.FLOAT, [1, 13, 64])
outp = helper.make_tensor_value_info("outp", TensorProto.FLOAT, [1, 1, 64])
# MultiThreshold
m_node = helper.make_node(
"MultiThreshold",
["v", "thresholds"],
["out"],
["xnor_out", "threshs"],
["outp"],
domain="finn",
out_scale=2.0,
out_bias=-1.0,
out_dtype="",
)
inst = CustomOp_Construct[m_node.op_type]
inst.verify_construct(m_node)
# XnorPopcountMatMul
xnor_node = helper.make_node(
"XnorPopcountMatMul", ["x", "W"], ["out"], domain="finn"
"XnorPopcountMatMul",
["fclayer_out0", "fclayer_out1"],
["xnor_out"],
domain="finn",
)
inst = CustomOp_Construct[xnor_node.op_type]
inst.verify_construct(xnor_node)
# StreamingMaxPool_Batch
MaxPool_batch_node = helper.make_node(
"StreamingMaxPool_Batch",
["in"],
["out"],
["inp"],
["max_out"],
domain="finn",
backend="fpgadataflow",
code_gen_dir="",
......@@ -40,14 +54,11 @@ def test_verify_layout_custom_ops():
NumChannels=2,
)
inst = CustomOp_Construct[MaxPool_batch_node.op_type]
inst.verify_construct(MaxPool_batch_node)
# StreamingFCLayer_Batch - no activation
FCLayer_node = helper.make_node(
FCLayer0_node = helper.make_node(
"StreamingFCLayer_Batch",
["in", "weights"],
["out"],
["max_out", "weights"],
["fclayer_out0"],
domain="finn",
backend="fpgadataflow",
code_gen_dir="",
......@@ -65,14 +76,11 @@ def test_verify_layout_custom_ops():
noActivation=1,
)
inst = CustomOp_Construct[FCLayer_node.op_type]
inst.verify_construct(FCLayer_node)
# StreamingFCLayer_Batch - with activation
FCLayer_node = helper.make_node(
FCLayer1_node = helper.make_node(
"StreamingFCLayer_Batch",
["in", "weights", "threshs"],
["out"],
["fclayer_out0", "weights", "threshs"],
["fclayer_out1"],
domain="finn",
backend="fpgadataflow",
code_gen_dir="",
......@@ -89,5 +97,60 @@ def test_verify_layout_custom_ops():
binaryXnorMode=1,
noActivation=0,
)
inst = CustomOp_Construct[FCLayer_node.op_type]
inst.verify_construct(FCLayer_node)
graph = helper.make_graph(
nodes=[MaxPool_batch_node, FCLayer0_node, FCLayer1_node, xnor_node, m_node],
name="custom_op_graph",
inputs=[inp],
outputs=[outp],
value_info=[
helper.make_tensor_value_info("max_out", TensorProto.FLOAT, [1, 13, 64]),
helper.make_tensor_value_info("weights", TensorProto.FLOAT, [64, 32, 416]),
helper.make_tensor_value_info("threshs", TensorProto.FLOAT, [32, 32, 16]),
helper.make_tensor_value_info("xnor_out", TensorProto.FLOAT, [1, 32, 32]),
helper.make_tensor_value_info(
"fclayer_out0", TensorProto.FLOAT, [1, 32, 32]
),
helper.make_tensor_value_info(
"fclayer_out1", TensorProto.FLOAT, [32, 64, 512]
),
],
)
model = helper.make_model(graph, producer_name="custom-op-model")
model = ModelWrapper(model)
produced = model.analysis(verify_nodes)
expected = {
"StreamingMaxPool_Batch": [
"The number of attributes is correct",
"Attribute domain is set correctly",
"Attribute backend is set correctly",
"All necessary attributes exist",
"The number of inputs is correct",
],
"StreamingFCLayer_Batch": [
"The number of attributes is correct",
"Attribute domain is set correctly",
"Attribute backend is set correctly",
"All necessary attributes exist",
"The number of inputs is correct",
],
"XnorPopcountMatMul": [
"The number of attributes is correct",
"Attribute domain is set correctly",
"XnorPopcountMatMul should not have any attributes",
"The number of inputs is correct",
],
"MultiThreshold": [
"The number of attributes is correct",
"Attribute domain is set correctly",
"All necessary attributes exist",
"The number of inputs is correct",
],
}
assert check_two_dict_for_equality(
produced, expected
), """The produced output of
the verification analysis pass is not equal to the expected one"""
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment