Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Add silent option to quantization script #17094

Merged
merged 3 commits into from
Dec 18, 2019

Conversation

ZhennanQin
Copy link
Contributor

@ZhennanQin ZhennanQin commented Dec 17, 2019

Description

As title.

The log looks like:

$ python imagenet_gen_qsym_mkldnn.py --model=resnet50_v1 --num-calib-batches=5 --calib-mode=naive --quiet
/home/zhennanq/local/mxnet/python/mxnet/module/base_module.py:67: UserWarning: Data provided by label_shapes don't match names specified by label_names ([] vs. ['softmax_label'])
  warnings.warn(msg)
[10:18:14] src/io/iter_image_recordio_2.cc:178: ImageRecordIOParser2: data/val_256_q90.rec, use 56 threads for decoding..

@pengzhao-intel @zhreshold @hetong007

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at https://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

Copy link
Contributor

@pengzhao-intel pengzhao-intel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pengzhao-intel pengzhao-intel added MKLDNN Quantization Issues/Feature Requests related to Quantization labels Dec 17, 2019
Copy link
Member

@zhreshold zhreshold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an api mx.quantization.quantize_net, please make sure it's quite by default.

@@ -275,12 +275,15 @@ Graph QuantizeGraph(Graph &&src) {
std::unordered_map<Node*, NodePtr> mirror_map;
std::unordered_map<NodePtr, NodePtr> reverse_mirror_map;
nnvm::NodeEntryMap<NodeEntry> mirror_entry_map;
static int verbose = dmlc::GetEnv("MXNET_QUANTIZATION_VERBOSE", 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use default = 0, in script you can set to 1 in non-quiet mode

DFSVisit(src.outputs, [&](const NodePtr& node) {
NodePtr new_node = Node::Create();
// If the currently visited node needs quantization, insert a quantize op node before the
// current node and replace the current node with the quantized version in the new graph.
if (quantized_node_map.count(node)) {
std::cout << node->attrs.name << " is quantized." << std::endl;
if (verbose) {
std::cout << node->attrs.name << " is quantized." << std::endl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use LOG(INFO)

@@ -516,15 +520,20 @@ static inline void SetCalibTableForEntry(
out_data_name = out_data_name.substr(prefix.size());
}
const auto calib_table_iter = calib_table.find(out_data_name);
static int verbose = dmlc::GetEnv("MXNET_QUANTIZATION_VERBOSE", 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

<< " : min=" << calib_table_iter->second.first
<< " max=" << calib_table_iter->second.second << std::endl;
if (verbose) {
std::cout << "Set calibration result to " << node->attrs.name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG(INFO) instead of std::cout

@ZhennanQin
Copy link
Contributor Author

@zhreshold Code is refactored to be quiet by default. Only when valid logger is passed, then log will be printed. So just make sure you don't pass a logger to this API.

Copy link
Member

@zhreshold zhreshold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@zhreshold
Copy link
Member

@ZhennanQin Please fix lint error before we can merge this change:

************* Module mxnet.contrib.quantization

python/mxnet/contrib/quantization.py:229:0: C0330: Wrong continued indentation (add 1 space).

                             % (name, min_range, max_range))

                             ^| (bad-continuation)

python/mxnet/contrib/quantization.py:363:0: C0330: Wrong continued indentation (add 1 space).

                        % (name, min_val, max_val, th, divergence))

                        ^| (bad-continuation)

@ZhennanQin
Copy link
Contributor Author

@zhreshold fixed. You can merge now.

@zhreshold zhreshold merged commit a18250d into apache:master Dec 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
MKLDNN Quantization Issues/Feature Requests related to Quantization
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants