ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci::QuantizedModelVerifier Struct Reference

Class to verify quantized model. More...

#include <QuantizedModelVerifier.h>

Data Structures

struct  Context
 

Public Member Functions

 QuantizedModelVerifier (std::unique_ptr< Context > &&ctx)
 
void verify (loco::Graph *g)
 

Detailed Description

Class to verify quantized model.

TODO Move this to luci/service

Definition at line 34 of file QuantizedModelVerifier.h.

Constructor & Destructor Documentation

◆ QuantizedModelVerifier()

luci::QuantizedModelVerifier::QuantizedModelVerifier ( std::unique_ptr< Context > &&  ctx)
inline

Definition at line 48 of file QuantizedModelVerifier.h.

48 : _ctx{std::move(ctx)}
49 {
50 // DO NOTHING
51 }

Member Function Documentation

◆ verify()

void luci::QuantizedModelVerifier::verify ( loco::Graph g)

Definition at line 29 of file QuantizedModelVerifier.cpp.

30{
31 if (_ctx->granularity != Granularity::ChannelWise && _ctx->granularity != Granularity::LayerWise)
32 throw std::runtime_error("Unsupported granularity");
33
34 auto info_by_name = layer_info_map(g, _ctx->layers_info);
35
36 auto quantize_dtype = [&](const luci::CircleNode *node) {
37 auto iter = info_by_name.find(node->name());
38
39 // Return designated quantization dtype
40 if (iter != info_by_name.end())
41 return iter->second.dtype;
42
43 // Return default quantization dtype
44 return _ctx->output_model_dtype;
45 };
46
47 auto quantize_granularity = [&](const luci::CircleNode *node) {
48 auto iter = info_by_name.find(node->name());
49
50 // Return designated quantization granularity
51 if (iter != info_by_name.end())
52 return iter->second.granularity;
53
54 // Return default quantization granularity
55 return _ctx->granularity;
56 };
57
58 for (auto node : loco::active_nodes(loco::output_nodes(g)))
59 {
60 auto circle_node = loco::must_cast<luci::CircleNode *>(node);
61
62 auto node_name = [&circle_node]() {
63 if (circle_node->name().length() == 0)
64 return std::string("(noname)");
65
66 return circle_node->name();
67 };
68
69 // Verify Type
70 if (!VerifyQuantizedNodeType::create(quantize_dtype(circle_node))->verify(circle_node))
71 throw std::runtime_error("Wrong data type detected in " + node_name());
72
73 // Verify Granularity
74 if (!circle_node->accept(
75 VerifyQuantizedNodeGranularity::create(quantize_granularity(circle_node)).get()))
76 throw std::runtime_error("Wrong granularity detected in " + node_name());
77
78 // Verify Bias scale
79 if (!VerifyQuantizedBiasScale::create()->verify(circle_node))
80 throw std::runtime_error("Wrong bias scale detected in " + node_name());
81 }
82}
static std::shared_ptr< VerifyQuantizedBiasScale > create()
static std::shared_ptr< VerifyQuantizedNodeGranularity > create(Granularity granularity)
static std::shared_ptr< VerifyQuantizedNodeType > create(loco::DataType dtype)
KnobTrait< K >::ValueType get(void)
std::set< loco::Node * > active_nodes(const std::vector< loco::Node * > &roots)
Enumerate all the nodes required to compute "roots".
std::vector< Node * > output_nodes(Graph *)
Definition Graph.cpp:101
LayerInfoMap layer_info_map(loco::Graph *g, std::vector< LayerInfo > &layers_info)

References loco::active_nodes(), luci::VerifyQuantizedBiasScale::create(), luci::VerifyQuantizedNodeGranularity::create(), luci::VerifyQuantizedNodeType::create(), luci::layer_info_map(), and loco::output_nodes().


The documentation for this struct was generated from the following files: