MCPcopy Create free account
hub / github.com/NVIDIA/TensorRT / convertRNNBias

Method convertRNNBias

samples/sampleCharRNN/sampleCharRNN.cpp:481–493  ·  view source on GitHub ↗

\brief Converts RNN Biases from TensorFlow's format to TensorRT's format. \param input Biases that are stored in TensorFlow's format. \return Converted bias in TensorRT's format. \note TensorFlow bias parameters for BasicLSTMCell are formatted as: CellN: Bi, Bc, Bf, Bo TensorRT expects the format to be: CellN: Wi, Wc, Wf, Wo, Ri, Rc, Rf, Ro Since tensorflow already combines U and W, we double

Source from the content-addressed store, hash-verified

479//! Since tensorflow already combines U and W,
480//! we double the size and set all of U to zero.
481nvinfer1::Weights SampleCharRNNBase::convertRNNBias(nvinfer1::Weights input)
482{
483 auto mem = new samplesCommon::FloatMemory(input.count * 2);
484 weightsMemory.emplace_back(mem);
485 auto ptr = mem->raw();
486 const float* iptr = static_cast<const float*>(input.values);
487 int64_t count = 4 * mParams.hiddenSize;
488 ASSERT(input.count == count);
489 std::copy(iptr, iptr + count, ptr);
490 float* shiftedPtr = ptr + count;
491 std::fill(shiftedPtr, shiftedPtr + count, 0.0);
492 return nvinfer1::Weights{input.type, ptr, input.count * 2};
493}
494
495nvinfer1::ILayer* SampleCharRNNLoop::addLSTMCell(SampleUniquePtr<nvinfer1::INetworkDefinition>& network,
496 const LstmIO& inputTensors, nvinfer1::ITensor* sequenceSize, const LstmParams& params, LstmIO& outputTensors)

Callers

nothing calls this directly

Calls 1

rawMethod · 0.45

Tested by

no test coverage detected