[POT] Added typecast while nodes updating & creation (#8621)
* Update type casting while update * Fix Pylint * Update precision setting for FQ values * Update FQ values precision setting * Fix scales dump * Update reference * Another reference update
This commit is contained in:
1 parent
6156626706
commit
516d510045
4 files changed
+24
-13
No files matched your search
@@ -84,7 +84,10 @@ def set_node_value(node: Node, value: np.ndarray):
|
||||
"""
|
||||
if node.type != 'Const':
|
||||
raise Exception('Can\'t set value for non-constant node {}'.format(node.name))
|
||||
node.out_port(0).data.set_value(value)
|
||||
data_type = np.float32
|
||||
if node.out_port(0).is_data_type_defined():
|
||||
data_type = node.out_port(0).get_data_type()
|
||||
node.out_port(0).data.set_value(np.array(value).astype(data_type))
|
||||
|
||||
|
||||
def get_node_value(node: Node):
|
||||
|
||||
@@ -27,7 +27,7 @@ from . import node_utils as nu
|
||||
from .pattern_utils import get_fq_result_pattern
|
||||
from .special_operations import OPERATIONS_WITH_WEIGHTS, DETECTION_OUTPUT_FINAL_TYPES, SPLIT_OPERATIONS
|
||||
from .utils import find_operation_matches, is_ignored, get_hw_aware_ignored_patterns
|
||||
from ..graph.node_utils import get_all_node_outputs, get_node_inputs, get_node_input
|
||||
from ..graph.node_utils import get_all_node_outputs, get_node_inputs, get_node_input, get_weights_for_node
|
||||
from ..graph.special_patterns import get_ignored_patterns
|
||||
from ..utils.logger import get_logger
|
||||
|
||||
@@ -683,8 +683,12 @@ def create_bias_node(graph: Graph, src_node):
|
||||
bias_shape = src_node.out_port(0).data.get_shape()
|
||||
add_bias_shape = [1] * len(bias_shape)
|
||||
add_bias_shape[1] = bias_shape[1]
|
||||
weights = get_weights_for_node(src_node)
|
||||
bias_dtype = np.float32
|
||||
if weights and weights.out_port(0).is_data_type_defined():
|
||||
bias_dtype = weights.out_port(0).get_data_type()
|
||||
add_bias = Const(graph,
|
||||
{'value': np.zeros(add_bias_shape, dtype=np.float32),
|
||||
{'value': np.zeros(add_bias_shape, dtype=bias_dtype),
|
||||
'shape': add_bias_shape,
|
||||
'need_shape_inference': True
|
||||
}).create_node()
|
||||
@@ -706,10 +710,10 @@ def create_fake_quantize_node(graph: Graph, name):
|
||||
fq = FakeQuantize(graph, {'name': name, 'levels': 0,
|
||||
'stop_value_propagation': True}).create_node()
|
||||
|
||||
input_low = Const(graph, {'value': 0.0}).create_node()
|
||||
input_height = Const(graph, {'value': 0.0}).create_node()
|
||||
output_low = Const(graph, {'value': 0.0}).create_node()
|
||||
output_height = Const(graph, {'value': 0.0}).create_node()
|
||||
input_low = Const(graph, {'value': np.array(0.0).astype(np.float32)}).create_node()
|
||||
input_height = Const(graph, {'value': np.array(0.0).astype(np.float32)}).create_node()
|
||||
output_low = Const(graph, {'value': np.array(0.0).astype(np.float32)}).create_node()
|
||||
output_height = Const(graph, {'value': np.array(0.0).astype(np.float32)}).create_node()
|
||||
|
||||
input_low.out_port(0).connect(fq.in_port(1))
|
||||
input_height.out_port(0).connect(fq.in_port(2))
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"Conv_74/WithoutBiases/fq_weights_1": {"low_level": [-0.3552180528640747, -0.30241239070892334, -0.35705194888370373, -0.39215172373730206, -0.2776391501997558, -0.3361489474773407, -0.3868256211280823, -0.5436204671859741, -0.318410187959671, -0.31505051680973595, -0.23880594968795776, -0.38046693801879883, -0.27451284840810214, -0.2766186594963074, -0.3627367317676544, -0.29476964473724365, -0.38299572358437634, -0.2062835544347763, -0.39400672912597656, -0.3251293095258566, -0.2832641585877067, -0.2863684296607971, -0.3876238763332367, -0.5277606248855591, -0.4006192684173584, -0.24683696554078685, -0.37802205123300625, -0.29070305824279785, -0.422828733921051, -0.39472426451853854, -0.47633805871009827, -0.32811633551993025, -0.2596876141501636, -0.2581086582862414, -0.323214590549469, -0.21324138343334198, -0.4875659302833977, -0.3296740651130676, -0.2913229465484619, -0.2127135992050171, -0.36269703061561887, -0.30451700091362, -0.28875365364017774, -0.3643628218042569, -0.43030617634455365, -0.2890738844871521, -0.3457960693249062, -0.5414946675300598, -0.3943061828613281, -0.25064602494239807, -0.3793347117512725, -0.49791520833969116, -0.36387041211128235, -0.35704181684275804, -0.33560687214580937, -0.29169208318629164, -0.4725576639175415, -0.2941891344866358, -0.35876838374333303, -0.577532947063446, -0.45339235663414, -0.2987205386161804, -0.2940130574362618, -0.2849476235126382], "high_level": [0.3580150454063115, 0.28179336406967853, 0.2796490788459778, 0.3221246302127838, 0.3488916754722595, 0.30834715482883884, 0.38380354596301913, 0.4058536364607615, 0.3876297940378604, 0.3077237606048584, 0.309802313108702, 0.30276594363467796, 0.32894212007522583, 0.38883188929197926, 0.3832138053351833, 0.2703902004356671, 0.2859351634979248, 0.25112780539885815, 0.40338784172421405, 0.22393012046813965, 0.2290220856666565, 0.3715049898302233, 0.2847848887346229, 0.4617905467748642, 0.40377375084584155, 0.3763652741909027, 0.3750687539577484, 0.21703173526345867, 0.49091132667105075, 0.43713265657424927, 0.34996265537884774, 0.3057447671890259, 0.241981640458107, 0.26843300461769104, 0.5535909476432395, 0.26796704820827044, 0.3640047013759613, 0.38275717729229036, 0.2714600183747031, 0.23930279910564423, 0.3598634600639343, 0.28375447812405497, 0.3197767734527588, 0.36151623725891113, 0.3648248016834259, 0.2868154947645962, 0.382947713136673, 0.3669338865499748, 0.25860340564281914, 0.31000955716559764, 0.3883664906024933, 0.6998996796473017, 0.5733715584783843, 0.30752506852149963, 0.37166380882263184, 0.3607770502567291, 0.341646419183628, 0.32071438431739807, 0.3290958106517792, 0.33719314921716725, 0.3843978675811187, 0.42674362659454346, 0.2572614252567291, 0.31556183099746704]}, "Conv_125/WithoutBiases/fq_weights_1": {"low_level": [-0.04426548257470131, -0.11135134100914001, -0.07765828843774467, -0.07175323907160919, -0.060261402279138565, -0.05421733856201172, -0.05354925990104675, -0.07521119915453114, -0.07791574175159137, -0.08745469897985458, -0.07189199309318493, -0.05181106639669296, -0.06931255519390106, -0.05981183624710919, -0.08264470100402832, -0.08058278521230398, -0.038206877652555704, -0.05236886441707611, -0.0714881494641304, -0.06468688696622849, -0.04678557409594457, -0.070274789418493, -0.09696732368320225, -0.06825089454650879, -0.061186570674180984, -0.030360217294877482, -0.07276034579340335, -0.07600618096498343, -0.062455371022224426, -0.06675869226455688, -0.07666285336017609, -0.051215965329235745, -0.06137414276599884, -0.10632237046957016, -0.1040971577167511, -0.047672911236683525, -0.07880405336618423, -0.07304930686950684, -0.09130963052694614, -0.07190621644258499, -0.03428914397954941, -0.05814117565751076, -0.07498869299888611, -0.1129443421959877, -0.08268275588320997, -0.07034473866224289, -0.04944238439202309, -0.071214881810275, -0.07518197164357265, -0.0678708627820015, -0.0700924121774733, -0.0834651067852974, -0.06273815035820007, -0.042415303337137875, -0.058624863624572754, -0.06033270061016083, -0.08330123871564865, -0.060676246881484985, -0.07170525131912171, -0.05046023800969124, -0.06607347805249064, -0.053976915776729584, -0.06806410849094391, -0.06096310541033745, -0.044993895034377396, -0.071513831615448, -0.07277793507941448, -0.09321408573601206, -0.06699004769325256, -0.0547582246363163, -0.056250058114528656, -0.07162976667393732, -0.0588226000944229, -0.051999552496548355, -0.06379608171326773, -0.07324327128689465, -0.07357516711534455, -0.1037807974011399, -0.024106331169605255, -0.06610234826803207, -0.06883271038532257, -0.06272075813392114, -0.07152508782303851, -0.08124346286058426, -0.07964716106653214, -0.08752370625734329, -0.0716009132628297, -0.07995743304491043, -0.060948817831713985, -0.058082368252868936, -0.048840384058495785, -0.11046174381460462, -0.11872662603855133, -0.13504953682422638, -0.06786764413118362, -0.06365028023719788, -0.0386648263471822, -0.04963810741901398, -0.05910563245415687, -0.06122723308792949, -0.10Line truncated
|
||||
{"Conv_18/WithoutBiases/fq_weights_1": {"low_level": [-0.33628177642822266, -0.10192569345235825, -0.1414744108915329, -0.09867030382156372, -0.07035823166370392, -0.1819474995136261, -0.08642897009849548, -0.12750278413295746, -0.08892028033733368, -0.07362021505832672, -0.13083158433437347, -0.09058710187673569, -0.14712078869342804, -0.13010239601135254, -0.10890895128250122, -0.11914203315973282, -0.143864706158638, -0.12614178657531738, -0.07033423334360123, -0.12635652720928192, -0.10231312364339828, -0.12024693191051483, -0.17142678797245026, -0.21563704311847687, -0.10218450427055359, -0.07466267794370651, -0.12306007742881775, -0.10650700330734253, -0.16889378428459167, -0.07867223024368286, -0.08988849073648453, -0.11420479416847229, -0.1532488614320755, -0.14257735013961792, -0.2665537893772125, -0.15829968452453613, -0.17013679444789886, -0.23825490474700928, -0.14009536802768707, -0.25717175006866455, -0.10843111574649811, -0.09732627123594284, -0.06015172600746155, -0.1892346441745758, -0.06553273648023605, -0.1586458534002304, -0.05464121699333191, -0.16764642298221588, -0.15902085602283478, -0.3325059413909912, -0.19377107918262482, -0.0621342808008194, -0.13215802609920502, -0.09284872561693192, -0.12850990891456604, -0.1337643563747406, -0.15039770305156708, -0.11543955653905869, -0.1862628012895584, -0.10914220660924911, -0.13897448778152466, -0.10441877692937851, -0.15710937976837158, -0.09338368475437164, -0.14904873073101044, -0.07726844400167465, -0.21625365316867828, -0.07940186560153961, -0.08817722648382187, -0.21272388100624084, -0.10510165244340897, -0.18255415558815002, -0.08768252283334732, -0.06838440150022507, -0.12043219059705734, -0.18189221620559692, -0.1301165521144867, -0.06279709190130234, -0.1985868215560913, -0.07323706150054932, -0.09679094702005386, -0.10019820183515549, -0.08810677379369736, -0.10867008566856384, -0.1044086366891861, -0.12809160351753235, -0.1690153032541275, -0.06109140068292618, -0.09338681399822235, -0.15684764087200165, -0.11098662763834, -0.07135874032974243, -0.28873565793037415, -0.16784358024597168, -0.1438044160604477, -0.0838066041469574, -0.10687481611967087, -0.0681106299161911, -0.14130288362503052, -0.21789906919002533, -0.13594473898410797, -0.1439555585384369, -0.18710333108901978, -0.10536909848451614, -0.16626577079296112, -0.1607036292552948, -0.07378210127353668, -0.06600908935070038, -0.14793577790260315, -0.2902717888355255, -0.029647817835211754, -0.19911329448223114, -0.08698544651269913, -0.18359756469726562, -0.0572865754365921, -0.04393824189901352, -0.04685574397444725, -0.2336089164018631, -0.09793591499328613, -0.06984587013721466, -0.038684211671352386, -0.1398335099220276, -0.11378352344036102, -0.27221792936325073, -0.1882454752922058, -0.16268213093280792, -0.11301448941230774, -0.10845408588647842, -0.08396726101636887, -0.3030869662761688, -0.16590018570423126, -0.08112139999866486, -0.16750361025333405, -0.20384161174297333, -0.09432516992092133, -0.15527039766311646, -0.1318613737821579, -0.16084294021129608, -0.04684806242585182, -0.13775935769081116, -0.14145684242248535, -0.12744326889514923, -0.09580560773611069, -0.1237976923584938], "high_level": [0.22418785095214844, 0.12213509529829025, 0.16425418853759766, 0.18089555203914642, 0.09127554297447205, 0.16954198479652405, 0.1961272805929184, 0.20426467061042786, 0.2055559754371643, 0.16104422509670258, 0.08302773535251617, 0.16325587034225464, 0.0788780152797699, 0.10857465863227844, 0.18342560529708862, 0.2341279536485672, 0.18368439376354218, 0.2054680734872818, 0.12461391091346741, 0.14670206606388092, 0.09385113418102264, 0.1440889984369278, 0.17828385531902313, 0.21733497083187103, 0.16924308240413666, 0.16633710265159607, 0.13844259083271027, 0.16508585214614868, 0.16239787638187408, 0.056877896189689636, 0.060911279171705246, 0.1225612461566925, 0.1544555425643921, 0.14828044176101685, 0.11530697345733643, 0.13634571433067322, 0.13755740225315094, 0.24392764270305634, 0.1626531034708023, 0.20792609453201294, 0.16264668107032776, 0.076227568089962, 0.09022758901119232, 0.14586837589740753, 0.050514817237854004, 0.09578617662191391, 0.0605117604136467, 0.19773679971694946, 0.13696686923503876, 0.15478724241256714, 0.11699385941028595, 0.15792463719844818, 0.21888673305511475, 0.10611283034086227, 0.108954057097435, 0.13911493122577667, 0.18309286236763, 0.10756868124008179, 0.10159789025783539, 0.13935120403766632, 0.19535093009471893, 0.16728314757347107, 0.20059500634670258, 0.08701661229133606, 0.04788094013929367, 0.17533992230892181, 0.12840060889720917, 0.07878153771162033, 0.21567672491073608, 0.0990266352891922, 0.1551014631986618, 0.18690069019794464, 0.10342041403055191, 0.1495908796787262, 0.11580018699169159, 0.20462875068187714, 0.1635092943906784, 0.1627417504787445, 0.16055956482887268, 0.09058268368244171, 0.10551799833774567, 0.0890650674700737, 0.21550440788269043, 0.11846821010112762, 0.1312037706375122, 0.23483461141586304, 0.1871Line truncated
|
||||
@@ -4,6 +4,7 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from copy import deepcopy
|
||||
import numpy as np
|
||||
import pytest
|
||||
from addict import Dict
|
||||
@@ -124,8 +125,7 @@ def test_activation_scales(tmp_path, models, preset, bits, stats_path, clipping_
|
||||
nodes = normalize(get_fq_nodes_stats_algo(model, preset, bits, False,
|
||||
clipping_value=clipping_value))
|
||||
local_path = os.path.join(tmp_path, '{}.json'.format(stats_path.split("_")[-2]))
|
||||
local_file = open(local_path, 'w')
|
||||
json.dump(nodes, local_file)
|
||||
dump_intermediate_scales(local_path, nodes)
|
||||
|
||||
assert len(ref_nodes) == len(nodes)
|
||||
processed_nodes = []
|
||||
@@ -152,9 +152,7 @@ def test_weights_scales(tmp_path, models):
|
||||
ref_weights = get_ref_stats(path_to_weights)
|
||||
weights = get_fq_nodes_stats_algo(model, False, 8, True)
|
||||
local_path = os.path.join(tmp_path, '{}.json'.format('mv2_weights'))
|
||||
dumped = json.dumps(weights, cls=NumpyEncoder)
|
||||
local_file = open(local_path, 'w')
|
||||
json.dump(dumped, local_file)
|
||||
dump_intermediate_scales(local_path, weights)
|
||||
|
||||
for fq_name in weights:
|
||||
item_min, item_max = weights[fq_name]['low_level'], weights[fq_name]['high_level']
|
||||
@@ -359,3 +357,9 @@ def _get_tf_accuracy_checker_config(path_to_dataset):
|
||||
}]
|
||||
}
|
||||
]}]})
|
||||
|
||||
|
||||
def dump_intermediate_scales(local_path, data):
|
||||
data = json.dumps(deepcopy(data), cls=NumpyEncoder)
|
||||
local_file = open(local_path, 'w')
|
||||
json.dump(data, local_file)
|
||||
Reference in new issue
Block a user