Functions | |
def | chpt_to_dict_arrays_simple (file_name) |
def | chpt_to_dict_arrays () |
def | concatenate_layers (params) |
def | convert_rnn_kernel (weights, dimensions, is_decoder_rnn=False) |
def | convert_rnn_bias (weights, dimensions, forget_bias=1.0) |
def | convert_weigts (dimensions, data, forget_bias=1.0) |
def | save_layer_weights (data, list_keys, dims, footer_string, file_name) |
def | main (_) |
def chptToBin.chpt_to_dict_arrays_simple | ( | file_name | ) |
Convert a checkpoint into into a dictionary of numpy arrays for later use in TensorRT NMT sample.
def chptToBin.chpt_to_dict_arrays | ( | ) |
Convert a checkpoint into a dictionary of numpy arrays for later use in TensorRT NMT sample. git clone https://github.com/tensorflow/nmt.git
def chptToBin.concatenate_layers | ( | params | ) |
Concatenate weights from multiple layers
def chptToBin.convert_rnn_kernel | ( | weights, | |
dimensions, | |||
is_decoder_rnn = False |
|||
) |
In place. weights conversion TensorFlow weight parameters for BasicLSTMCell are formatted as: Each [WR][icfo] is hiddenSize sequential elements. CellN Row 0: WiT, WcT, WfT, WoT CellN Row 1: WiT, WcT, WfT, WoT ... CellN RowM-1: WiT, WcT, WfT, WoT CellN RowM+0: RiT, RcT, RfT, RoT CellN RowM+1: RiT, RcT, RfT, RoT ... CellNRow(M+P)-1: RiT, RcT, RfT, RoT M - data size P - projection size TensorRT expects the format to laid out in memory: CellN: Wf, Wi, Wc, Wo, Rf, Ri, Rc, Ro For the purpose of implementing LSTMP all W and R weights become weights from W CellN: Wf, Rf, Wi, Ri, Wc, Rc, Wo, Ro, Empty states Update: alternative notation Tensorflow documents gates' order in e.g. https:github.com/tensorflow/tensorflow/blob/r1.4/tensorflow/python/ops/rnn_cell_impl.py:439 TF: i = input_gate, j = new_input (cell gate), f = forget_gate, o = output_gate - ijfo Need to convert 'ijfo' to 'fijo'
def chptToBin.convert_rnn_bias | ( | weights, | |
dimensions, | |||
forget_bias = 1.0 |
|||
) |
TensorFlow bias parameters for BasicLSTMCell are formatted as: CellN: Bi, Bc, Bf, Bo TensorRT expects the format to be: CellN: Wf, Wi, Wc, Wo, Rf, Ri, Rc, Ro Since Tensorflow already combines U and W, we double the size and set all of U to zero.
def chptToBin.convert_weigts | ( | dimensions, | |
data, | |||
forget_bias = 1.0 |
|||
) |
Convert weights from Tensorflow to TensorRT format
def chptToBin.save_layer_weights | ( | data, | |
list_keys, | |||
dims, | |||
footer_string, | |||
file_name | |||
) |
data - dictionary with string names as keys and numpy weights as values list_keys - list of dictionary keys to save dims - list of int values relevant to the layer e.g. tensor dimensions sufficient to extract all the tensors footer_string - marker placed at the end of file file format: data -> meta_data -> footer
def chptToBin.main | ( | _ | ) |