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 432 of file QuantizeDequantizeWeightsPass.cpp.

433{
434 LOGGER(l);
435 INFO(l) << "QuantizeDequantizeWeightsPass Start" << std::endl;
436
437 auto info_by_name = layer_info_map(g, _ctx->layers_info);
438
439 auto quantize_dtype = [&](const luci::CircleNode *node) {
440 auto iter = info_by_name.find(node->name());
441
442 // Return designated quantization dtype
443 if (iter != info_by_name.end())
444 return iter->second.dtype;
445
446 // Return default quantization dtype
447 return _ctx->output_model_dtype;
448 };
449
450 auto quantize_granularity = [&](const luci::CircleNode *node) {
451 auto iter = info_by_name.find(node->name());
452
453 // Return designated quantization granularity
454 if (iter != info_by_name.end())
455 return iter->second.granularity;
456
457 // Return default quantization granularity
458 return _ctx->granularity;
459 };
460
461 // Quantize weights
462 for (auto node : loco::active_nodes(loco::output_nodes(g)))
463 {
464 auto circle_node = loco::must_cast<luci::CircleNode *>(node);
465 QuantizeDequantizeWeights qw(_ctx->input_model_dtype, quantize_dtype(circle_node),
466 quantize_granularity(circle_node));
467 circle_node->accept(&qw);
468 }
469
470 INFO(l) << "QuantizeDequantizeWeightsPass End" << std::endl;
471 return false; // one time run
472}
#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().

Referenced by package.infer.session::inference().


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