| 133 | } |
| 134 | |
| 135 | DimsExprs EmbLayerNormPluginDynamic::getOutputDimensions( |
| 136 | int32_t outputIndex, DimsExprs const* inputs, int32_t nbInputs, IExprBuilder& exprBuilder) noexcept |
| 137 | { |
| 138 | try |
| 139 | { |
| 140 | // Input should be input ids and token ids and the input mask |
| 141 | // Output should be the embeddings tensor and mask indices |
| 142 | PLUGIN_ASSERT(nbInputs == 3); |
| 143 | |
| 144 | PLUGIN_ASSERT(inputs[0].nbDims == 2); // BxS |
| 145 | PLUGIN_ASSERT(inputs[0].nbDims == inputs[1].nbDims); |
| 146 | PLUGIN_ASSERT(inputs[0].nbDims == inputs[2].nbDims); |
| 147 | |
| 148 | PLUGIN_ASSERT(outputIndex == 0 || outputIndex == 1); |
| 149 | |
| 150 | if (outputIndex == 0) |
| 151 | { |
| 152 | DimsExprs ret; |
| 153 | ret.nbDims = 5; |
| 154 | ret.d[0] = inputs[0].d[0]; |
| 155 | ret.d[1] = inputs[0].d[1]; |
| 156 | ret.d[2] = exprBuilder.constant(mLd); |
| 157 | ret.d[3] = exprBuilder.constant(1); |
| 158 | ret.d[4] = exprBuilder.constant(1); |
| 159 | return ret; |
| 160 | } |
| 161 | |
| 162 | DimsExprs ret; |
| 163 | ret.nbDims = 2; |
| 164 | ret.d[0] = inputs[0].d[BDIM]; |
| 165 | auto cms0 = exprBuilder.constant(unfusedMaskSize); |
| 166 | |
| 167 | // this code must match getMHAMaskPackedSize in bertCommon.h |
| 168 | bool const isSmOK |
| 169 | = (mSM == kSM_75 || mSM == kSM_80 || mSM == kSM_86 || mSM == kSM_87 || mSM == kSM_89 || mSM == kSM_90); |
| 170 | bool const isPrecisionOK = (mMhaType == nvinfer1::DataType::kHALF || mMhaType == nvinfer1::DataType::kINT8); |
| 171 | if (mUseFullMask || (isSmOK && isPrecisionOK)) |
| 172 | { |
| 173 | // support 128, 384 in both int8 and fp16 |
| 174 | auto cms128 = exprBuilder.constant(packedMaskSize128); |
| 175 | auto cms384 = exprBuilder.constant(packedMaskSize384); |
| 176 | auto c128 = exprBuilder.constant(128); |
| 177 | auto c384 = exprBuilder.constant(384); |
| 178 | auto is128 = exprBuilder.operation(DimensionOperation::kEQUAL, *inputs[0].d[SDIM], *c128); |
| 179 | auto is384 = exprBuilder.operation(DimensionOperation::kEQUAL, *inputs[0].d[SDIM], *c384); |
| 180 | auto sel128 = exprBuilder.operation(DimensionOperation::kPROD, *is128, *cms128); |
| 181 | auto sel384 = exprBuilder.operation(DimensionOperation::kPROD, *is384, *cms384); |
| 182 | auto maskSize = exprBuilder.operation(DimensionOperation::kSUM, *sel384, *sel128); |
| 183 | |
| 184 | // support 64, 96 in both int8 and fp16 |
| 185 | auto cms64 = exprBuilder.constant(packedMaskSize64); |
| 186 | auto cms96 = exprBuilder.constant(packedMaskSize96); |
| 187 | auto c64 = exprBuilder.constant(64); |
| 188 | auto c96 = exprBuilder.constant(96); |
| 189 | |
| 190 | auto is64 = exprBuilder.operation(DimensionOperation::kEQUAL, *inputs[0].d[SDIM], *c64); |
| 191 | auto is96 = exprBuilder.operation(DimensionOperation::kEQUAL, *inputs[0].d[SDIM], *c96); |
| 192 | auto sel64 = exprBuilder.operation(DimensionOperation::kPROD, *is64, *cms64); |
nothing calls this directly
no test coverage detected