ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci::QuantizeDequantizeWeightsPass Class Reference

Pass to quantize weights. More...

#include <QuantizeDequantizeWeightsPass.h>

Collaboration diagram for luci::QuantizeDequantizeWeightsPass:

Data Structures

struct  Context
 

Public Member Functions

 QuantizeDequantizeWeightsPass (std::unique_ptr< Context > &&ctx)
 
 QuantizeDequantizeWeightsPass (loco::DataType input_model_dtype, loco::DataType output_model_dtype, QuantizationGranularity granularity)
 
virtual const char * name (void) const
 
bool run (loco::Graph *graph)
 Run the pass.
 
- Public Member Functions inherited from logo::Pass
virtual ~Pass ()=default
 

Detailed Description

Pass to quantize weights.

Definition at line 32 of file QuantizeDequantizeWeightsPass.h.

Constructor & Destructor Documentation

◆ QuantizeDequantizeWeightsPass() [1/2]

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

Definition at line 44 of file QuantizeDequantizeWeightsPass.h.

44 : _ctx{std::move(ctx)}
45 {
46 // DO NOTHING
47 }

◆ QuantizeDequantizeWeightsPass() [2/2]

luci::QuantizeDequantizeWeightsPass::QuantizeDequantizeWeightsPass ( loco::DataType  input_model_dtype,
loco::DataType  output_model_dtype,
QuantizationGranularity  granularity 
)
inline

Definition at line 50 of file QuantizeDequantizeWeightsPass.h.

52 {
53 _ctx = std::make_unique<Context>();
54 {
55 _ctx->input_model_dtype = input_model_dtype;
56 _ctx->output_model_dtype = output_model_dtype;
57 _ctx->granularity = granularity;
58 }
59 }

Member Function Documentation

◆ name()

virtual const char * luci::QuantizeDequantizeWeightsPass::name ( void  ) const
inlinevirtual

Reimplemented from logo::Pass.

Definition at line 60 of file QuantizeDequantizeWeightsPass.h.

60{ return "luci::QuantizeDequantizeWeightsPass"; }

◆ run()

bool luci::QuantizeDequantizeWeightsPass::run ( loco::Graph graph)
virtual

Run the pass.

Returns
false if there was nothing changed

Implements logo::Pass.

Definition at line 361 of file QuantizeDequantizeWeightsPass.cpp.

362{
363 LOGGER(l);
364 INFO(l) << "QuantizeDequantizeWeightsPass Start" << std::endl;
365
366 auto info_by_name = layer_info_map(g, _ctx->layers_info);
367
368 auto quantize_dtype = [&](const luci::CircleNode *node) {
369 auto iter = info_by_name.find(node->name());
370
371 // Return designated quantization dtype
372 if (iter != info_by_name.end())
373 return iter->second.dtype;
374
375 // Return default quantization dtype
376 return _ctx->output_model_dtype;
377 };
378
379 auto quantize_granularity = [&](const luci::CircleNode *node) {
380 auto iter = info_by_name.find(node->name());
381
382 // Return designated quantization granularity
383 if (iter != info_by_name.end())
384 return iter->second.granularity;
385
386 // Return default quantization granularity
387 return _ctx->granularity;
388 };
389
390 // Quantize weights
391 for (auto node : loco::active_nodes(loco::output_nodes(g)))
392 {
393 auto circle_node = loco::must_cast<luci::CircleNode *>(node);
394 QuantizeDequantizeWeights qw(_ctx->input_model_dtype, quantize_dtype(circle_node),
395 quantize_granularity(circle_node));
396 circle_node->accept(&qw);
397 }
398
399 INFO(l) << "QuantizeDequantizeWeightsPass End" << std::endl;
400 return false; // one time run
401}
#define LOGGER(name)
Definition Log.h:65
#define INFO(name)
Definition Log.h:68
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(), INFO, luci::layer_info_map(), LOGGER, luci::CircleNode::name(), and loco::output_nodes().


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