Ensures that every tensor used by a network has a dynamic range set. All tensors in a network must have a dynamic range specified if a calibrator is not used. This function is just a utility to globally fill in missing scales and zero-points for the entire network. If a tensor does not have a dyanamic range set, it is assigned inRange or outRange as follows: If the tensor is the input to a laye
| 536 | // The default parameter values choosen arbitrarily. Range values should be choosen such that |
| 537 | // we avoid underflow or overflow. Also range value should be non zero to avoid uniform zero scale tensor. |
| 538 | inline void setAllDynamicRanges(nvinfer1::INetworkDefinition* network, float inRange = 2.0F, float outRange = 4.0F) |
| 539 | { |
| 540 | // Ensure that all layer inputs have a scale. |
| 541 | for (int i = 0; i < network->getNbLayers(); i++) |
| 542 | { |
| 543 | auto layer = network->getLayer(i); |
| 544 | for (int j = 0; j < layer->getNbInputs(); j++) |
| 545 | { |
| 546 | nvinfer1::ITensor* input{layer->getInput(j)}; |
| 547 | // Optional inputs are nullptr here and are from RNN layers. |
| 548 | if (input != nullptr && !input->dynamicRangeIsSet()) |
| 549 | { |
| 550 | ASSERT(input->setDynamicRange(-inRange, inRange)); |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | // Ensure that all layer outputs have a scale. |
| 556 | // Tensors that are also inputs to layers are ingored here |
| 557 | // since the previous loop nest assigned scales to them. |
| 558 | for (int i = 0; i < network->getNbLayers(); i++) |
| 559 | { |
| 560 | auto layer = network->getLayer(i); |
| 561 | for (int j = 0; j < layer->getNbOutputs(); j++) |
| 562 | { |
| 563 | nvinfer1::ITensor* output{layer->getOutput(j)}; |
| 564 | // Optional outputs are nullptr here and are from RNN layers. |
| 565 | if (output != nullptr && !output->dynamicRangeIsSet()) |
| 566 | { |
| 567 | // Pooling must have the same input and output scales. |
| 568 | if (layer->getType() == nvinfer1::LayerType::kPOOLING) |
| 569 | { |
| 570 | ASSERT(output->setDynamicRange(-inRange, inRange)); |
| 571 | } |
| 572 | else |
| 573 | { |
| 574 | ASSERT(output->setDynamicRange(-outRange, outRange)); |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | inline void setDummyInt8DynamicRanges(const nvinfer1::IBuilderConfig* c, nvinfer1::INetworkDefinition* n) |
| 582 | { |
no test coverage detected